belajar 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -4
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile +1 -1
- data/README.md +76 -1
- data/Rakefile +1 -1
- data/belajar.gemspec +23 -26
- data/belajar.png +0 -0
- data/bin/belajar +6 -2
- data/lib/belajar.rb +0 -1
- data/lib/belajar/chapter.rb +3 -4
- data/lib/belajar/coloring.rb +32 -0
- data/lib/belajar/configuration.rb +25 -28
- data/lib/belajar/congratulator.rb +17 -5
- data/lib/belajar/course.rb +9 -8
- data/lib/belajar/exceptions.rb +0 -2
- data/lib/belajar/generator.rb +13 -15
- data/lib/belajar/github_client.rb +5 -5
- data/lib/belajar/loadable.rb +23 -14
- data/lib/belajar/loading/chapters.rb +0 -2
- data/lib/belajar/loading/courses.rb +0 -2
- data/lib/belajar/loading/units.rb +0 -2
- data/lib/belajar/markdown.rb +2 -0
- data/lib/belajar/markdown/printer.rb +89 -0
- data/lib/belajar/markdown/ruby_doc.rb +104 -0
- data/lib/belajar/solution.rb +23 -15
- data/lib/belajar/storeable.rb +11 -12
- data/lib/belajar/task.rb +1 -1
- data/lib/belajar/terminal.rb +3 -4
- data/lib/belajar/terminal/cli.rb +8 -8
- data/lib/belajar/terminal/courses.rb +24 -21
- data/lib/belajar/terminal/output.rb +46 -53
- data/lib/belajar/terminal/setup.rb +13 -18
- data/lib/belajar/terminal/solutions.rb +27 -32
- data/lib/belajar/terminal/texts/hint_course_download.txt +2 -2
- data/lib/belajar/terminal/welcome.rb +9 -11
- data/lib/belajar/test.rb +7 -10
- data/lib/belajar/test_result.rb +54 -21
- data/lib/belajar/unit.rb +2 -4
- data/lib/belajar/version.rb +1 -1
- data/lib/belajar/views.rb +29 -33
- data/lib/belajar/views/chapters_menu.rb +16 -20
- data/lib/belajar/views/courses_menu.rb +12 -15
- data/lib/belajar/views/main_menu.rb +23 -23
- data/lib/belajar/views/menu.rb +14 -18
- data/lib/belajar/views/splash.rb +11 -13
- data/lib/belajar/views/subscriber.rb +38 -0
- data/lib/belajar/views/task_view.rb +97 -80
- data/lib/belajar/views/top_bar.rb +4 -10
- data/lib/belajar/views/units_menu.rb +16 -21
- data/lib/belajar/window.rb +20 -140
- data/spec/belajar/chapter_spec.rb +23 -18
- data/spec/belajar/coloring_spec.rb +35 -0
- data/spec/belajar/configuration_spec.rb +55 -51
- data/spec/belajar/congratulator_spec.rb +11 -8
- data/spec/belajar/course_spec.rb +75 -52
- data/spec/belajar/generator_spec.rb +24 -25
- data/spec/belajar/github_client_spec.rb +17 -18
- data/spec/belajar/loading/chapters_spec.rb +2 -3
- data/spec/belajar/loading/courses_spec.rb +2 -3
- data/spec/belajar/loading/units_spec.rb +4 -5
- data/spec/belajar/markdown/ruby_doc_spec.rb +116 -0
- data/spec/belajar/reference_solution_spec.rb +8 -10
- data/spec/belajar/solution_spec.rb +21 -22
- data/spec/belajar/storeable_spec.rb +12 -10
- data/spec/belajar/task_spec.rb +3 -4
- data/spec/belajar/terminal/cli_spec.rb +29 -21
- data/spec/belajar/terminal/courses_spec.rb +104 -99
- data/spec/belajar/terminal/output_spec.rb +44 -39
- data/spec/belajar/terminal/setup_spec.rb +1 -3
- data/spec/belajar/terminal/solutions_spec.rb +0 -2
- data/spec/belajar/terminal/welcome_spec.rb +0 -2
- data/spec/belajar/terminal_spec.rb +5 -7
- data/spec/belajar/test_example_spec.rb +16 -14
- data/spec/belajar/test_result_spec.rb +21 -25
- data/spec/belajar/test_spec.rb +11 -12
- data/spec/belajar/unit_spec.rb +24 -27
- data/spec/belajar/views/chapters_menu_spec.rb +0 -1
- data/spec/belajar/views/courses_menu_spec.rb +0 -1
- data/spec/belajar/views/menu_spec.rb +1 -2
- data/spec/belajar/views/task_view_spec.rb +0 -2
- data/spec/belajar/views/units_menu_spec.rb +0 -1
- data/spec/belajar/views_spec.rb +0 -1
- data/spec/belajar_spec.rb +9 -12
- data/spec/path_helpers_spec.rb +11 -12
- data/spec/resource_helpers_spec.rb +11 -12
- data/spec/spec_helper.rb +3 -4
- data/spec/support/macros/content_helpers.rb +16 -17
- data/spec/support/macros/mock_helpers.rb +6 -6
- data/spec/support/macros/path_helpers.rb +15 -15
- data/spec/support/macros/resource_helpers.rb +34 -35
- metadata +56 -75
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Belajar::Configuration do
|
4
|
-
|
5
4
|
subject { Belajar::Configuration.send(:new) }
|
6
5
|
|
7
6
|
it { is_expected.to respond_to :solutions_path }
|
@@ -10,85 +9,90 @@ describe Belajar::Configuration do
|
|
10
9
|
it { is_expected.to respond_to :courses_path= }
|
11
10
|
it { is_expected.to respond_to :storage_file }
|
12
11
|
it { is_expected.to respond_to :save }
|
13
|
-
it { is_expected.to respond_to :import
|
12
|
+
it { is_expected.to respond_to :import }
|
14
13
|
it { is_expected.to respond_to :summary }
|
15
14
|
|
16
15
|
before do
|
17
16
|
subject.instance_variable_set(:@storage_file, local_storage_file)
|
17
|
+
File.open(local_storage_file, 'w')
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
21
|
-
it
|
20
|
+
describe '#courses_path' do
|
21
|
+
it 'returns the appropriate initial local courses path' do
|
22
22
|
courses_path = File.expand_path('~/.belajar/courses', __FILE__)
|
23
23
|
expect(subject.courses_path).to eq courses_path
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'returns the appropriate set courses path' do
|
27
27
|
subject.courses_path = local_courses_path
|
28
28
|
expect(subject.courses_path).to eq local_courses_path
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
33
|
-
|
34
|
-
|
35
|
-
.
|
32
|
+
describe '#solutions_path=' do
|
33
|
+
context 'if the given path is no existent dir' do
|
34
|
+
it 'raises a configuration error' do
|
35
|
+
expect { subject.solutions_path = 'no/existent/dir' }
|
36
|
+
.to raise_error(Belajar::ConfigurationError)
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
describe
|
40
|
-
|
41
|
-
|
42
|
-
.
|
41
|
+
describe '#solutions_path' do
|
42
|
+
context 'if not set' do
|
43
|
+
it 'raises an error' do
|
44
|
+
expect { subject.solutions_path }
|
45
|
+
.to raise_error(Belajar::ConfigurationError)
|
46
|
+
end
|
43
47
|
end
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
context 'if set' do
|
50
|
+
it 'returns the solutions path' do
|
51
|
+
subject.solutions_path = test_basepath
|
52
|
+
expect(subject.solutions_path).to eq test_basepath
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
51
|
-
describe
|
52
|
-
it
|
57
|
+
describe '#storage_path' do
|
58
|
+
it 'returns the appropriate path to the storage file' do
|
53
59
|
expect(subject.storage_file).to eq local_storage_file
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
57
|
-
describe
|
58
|
-
it
|
63
|
+
describe '#save' do
|
64
|
+
it 'saves the configured courses path to the belajar store' do
|
59
65
|
subject.courses_path = local_courses_path
|
60
66
|
subject.save
|
61
67
|
|
62
68
|
expect(QuickStore.store.courses_path).to eq local_courses_path
|
63
69
|
end
|
64
70
|
|
65
|
-
it
|
71
|
+
it 'saves the configured solution_path to the belajar store' do
|
66
72
|
path = File.join(test_basepath, 'test_solutions')
|
67
|
-
|
73
|
+
create_directory(path)
|
68
74
|
subject.solutions_path = path
|
69
75
|
subject.save
|
70
76
|
|
71
77
|
expect(QuickStore.store.solutions_path).to eq path
|
72
78
|
end
|
73
79
|
|
74
|
-
it
|
80
|
+
it 'does not save the storage file path' do
|
75
81
|
subject.save
|
76
82
|
expect(QuickStore.store.storage_file).to be_nil
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
80
|
-
describe
|
81
|
-
context
|
82
|
-
before
|
83
|
-
FileUtils.rm(local_storage_file) if File.exist?(local_storage_file)
|
84
|
-
end
|
86
|
+
describe '#import' do
|
87
|
+
context 'with non-existent belajar store entries:' do
|
88
|
+
before { remove_file(local_storage_file) }
|
85
89
|
|
86
|
-
it
|
87
|
-
QuickStore.store.courses_path
|
90
|
+
it 'uses the default configuration' do
|
91
|
+
QuickStore.store.courses_path = nil
|
88
92
|
QuickStore.store.solutions_path = nil
|
89
93
|
subject.instance_variable_set(:@courses_path, local_courses_path)
|
90
94
|
|
91
|
-
loaded_config = subject.import
|
95
|
+
loaded_config = subject.import
|
92
96
|
|
93
97
|
expect(loaded_config.courses_path).to eq local_courses_path
|
94
98
|
expect { loaded_config.solutions_path }
|
@@ -96,17 +100,18 @@ describe Belajar::Configuration do
|
|
96
100
|
end
|
97
101
|
end
|
98
102
|
|
99
|
-
context
|
100
|
-
it
|
101
|
-
expect(subject.import
|
103
|
+
context 'with existing belajar storage file:' do
|
104
|
+
it 'returns a Belajar::Configuration' do
|
105
|
+
expect(subject.import).to be_a Belajar::Configuration
|
102
106
|
end
|
103
107
|
|
104
|
-
it
|
105
|
-
wanted_courses_path
|
108
|
+
it 'loads the belajar store entries into the configuration' do
|
109
|
+
wanted_courses_path = '/courses/path'
|
106
110
|
wanted_solutions_path = solutions_basepath
|
107
|
-
temp_solutions_path
|
108
|
-
|
109
|
-
|
111
|
+
temp_solutions_path = File.join(solutions_basepath, 'temp')
|
112
|
+
|
113
|
+
create_directory(wanted_solutions_path)
|
114
|
+
create_directory(temp_solutions_path)
|
110
115
|
|
111
116
|
# save wanted settings
|
112
117
|
subject.courses_path = wanted_courses_path
|
@@ -114,11 +119,11 @@ describe Belajar::Configuration do
|
|
114
119
|
subject.save
|
115
120
|
|
116
121
|
# overwrite in memory settings
|
117
|
-
subject.courses_path
|
122
|
+
subject.courses_path = '/some/other/path/'
|
118
123
|
subject.solutions_path = temp_solutions_path
|
119
124
|
|
120
125
|
# fetch stored settings
|
121
|
-
subject.import
|
126
|
+
subject.import
|
122
127
|
expect(File.exist?(local_storage_file)).to be_truthy
|
123
128
|
expect(subject.courses_path).to eq wanted_courses_path
|
124
129
|
expect(subject.solutions_path).to eq wanted_solutions_path
|
@@ -128,34 +133,33 @@ describe Belajar::Configuration do
|
|
128
133
|
|
129
134
|
describe '#summary' do
|
130
135
|
before do
|
131
|
-
subject.courses_path
|
136
|
+
subject.courses_path = 'wanted/courses/path'
|
132
137
|
subject.solutions_path = solutions_basepath
|
133
|
-
@summary
|
138
|
+
@summary = subject.summary
|
134
139
|
end
|
135
140
|
|
136
|
-
it
|
141
|
+
it 'returns a string' do
|
137
142
|
expect(@summary).to be_a String
|
138
143
|
end
|
139
144
|
|
140
|
-
it
|
145
|
+
it 'returns a string with all properties but @configuration_file' do
|
141
146
|
expect(@summary.lines.count).to eq subject.instance_variables.count - 1
|
142
147
|
end
|
143
148
|
|
144
|
-
it
|
149
|
+
it 'returns a string including the courses path' do
|
145
150
|
expect(@summary =~ /courses path/).to be_truthy
|
146
151
|
end
|
147
152
|
|
148
|
-
it
|
153
|
+
it 'returns a string including the courses path' do
|
149
154
|
expect(@summary =~ /solutions path/).to be_truthy
|
150
155
|
end
|
151
156
|
end
|
152
157
|
|
153
158
|
describe '#initial_course' do
|
154
|
-
it {
|
159
|
+
it { is_expected.to respond_to :initial_course }
|
155
160
|
|
156
|
-
it
|
157
|
-
expect(subject.initial_course).to eq 'wong-bejo/
|
161
|
+
it 'returns the initial course github repo partial path' do
|
162
|
+
expect(subject.initial_course).to eq 'wong-bejo/Belajar_Ruby'
|
158
163
|
end
|
159
164
|
end
|
160
|
-
|
161
165
|
end
|
@@ -1,23 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Belajar::Congratulator do
|
4
|
-
|
5
|
-
it "responds to #message" do
|
4
|
+
it 'responds to #message' do
|
6
5
|
expect(Belajar::Congratulator).to respond_to :message
|
7
6
|
end
|
8
7
|
|
9
|
-
describe
|
10
|
-
it
|
8
|
+
describe '#message' do
|
9
|
+
it 'returns a string' do
|
11
10
|
expect(Belajar::Congratulator.message).to be_a String
|
12
11
|
end
|
13
12
|
|
14
|
-
it
|
15
|
-
messages = 1.upto(10).map { |
|
13
|
+
it 'returns a random congratulation method' do
|
14
|
+
messages = 1.upto(10).map { |_| Belajar::Congratulator.message }
|
16
15
|
expect(messages.uniq.count).to be > 1
|
17
16
|
end
|
18
17
|
|
19
|
-
it
|
20
|
-
expect(Belajar::Terminal)
|
18
|
+
it 'receives the congratulation texts from a Terminal text' do
|
19
|
+
expect(Belajar::Terminal)
|
20
|
+
.to receive(:text)
|
21
|
+
.with(:congratulations)
|
22
|
+
.and_return('')
|
23
|
+
|
21
24
|
Belajar::Congratulator.message
|
22
25
|
end
|
23
26
|
end
|
data/spec/belajar/course_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Belajar::Course do
|
4
|
-
|
5
4
|
it { is_expected.to respond_to :title }
|
6
5
|
it { is_expected.to respond_to :chapters }
|
7
6
|
it { is_expected.to respond_to :path }
|
@@ -22,73 +21,82 @@ describe Belajar::Course do
|
|
22
21
|
|
23
22
|
subject { Belajar::Course.new(course_path) }
|
24
23
|
|
25
|
-
it
|
24
|
+
it 'responds to .unzip' do
|
26
25
|
expect(Belajar::Course).to respond_to :unzip
|
27
26
|
end
|
28
27
|
|
29
|
-
it
|
28
|
+
it 'has the prescribed title' do
|
30
29
|
expect(subject.title).to eq course_titles.first
|
31
30
|
end
|
32
31
|
|
33
|
-
it
|
32
|
+
it 'has the prescribed path' do
|
34
33
|
expect(subject.path).to eq course_path
|
35
34
|
end
|
36
35
|
|
37
|
-
it
|
38
|
-
expect(subject.started?).to
|
36
|
+
it 'is not started by default' do
|
37
|
+
expect(subject.started?).to be false
|
39
38
|
end
|
40
39
|
|
41
|
-
it
|
42
|
-
expect(subject.mastered?).to
|
40
|
+
it 'is not mastered by default' do
|
41
|
+
expect(subject.mastered?).to be false
|
43
42
|
end
|
44
43
|
|
45
|
-
describe
|
46
|
-
it
|
44
|
+
describe '#chapters' do
|
45
|
+
it 'loads the prescribed number of chapters' do
|
47
46
|
expect(subject.chapters.count).to eq available_chapters(course_path).count
|
48
47
|
end
|
49
48
|
|
50
|
-
it
|
49
|
+
it 'lazy-loads the chapters' do
|
51
50
|
expect(subject.instance_variable_get(:@chapters)).to be_nil
|
52
51
|
subject.chapters
|
53
52
|
expect(subject.instance_variable_get(:@chapters)).not_to be_nil
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
57
|
-
describe
|
58
|
-
it
|
59
|
-
allow(subject.chapters.first).to receive(:started?)
|
56
|
+
describe '#started?' do
|
57
|
+
it 'returns true if at least one chapter has been started' do
|
58
|
+
allow(subject.chapters.first).to receive(:started?).and_return(true)
|
60
59
|
expect(subject.started?).to be true
|
61
60
|
end
|
62
61
|
|
63
|
-
it
|
64
|
-
allow_any_instance_of(Belajar::Chapter)
|
62
|
+
it 'returns false if no chapter has been started' do
|
63
|
+
allow_any_instance_of(Belajar::Chapter)
|
64
|
+
.to receive(:started?)
|
65
|
+
.and_return(false)
|
66
|
+
|
65
67
|
expect(subject.started?).to be false
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
69
|
-
describe
|
70
|
-
it
|
71
|
-
allow_any_instance_of(Belajar::Chapter)
|
71
|
+
describe '#mastered?' do
|
72
|
+
it 'returns true if all chapters have been mastered' do
|
73
|
+
allow_any_instance_of(Belajar::Chapter)
|
74
|
+
.to receive(:mastered?)
|
75
|
+
.and_return(true)
|
76
|
+
|
72
77
|
expect(subject.mastered?).to be true
|
73
78
|
end
|
74
79
|
|
75
|
-
it
|
76
|
-
allow_any_instance_of(Belajar::Chapter)
|
77
|
-
|
80
|
+
it 'returns false unless all chapters have been mastered' do
|
81
|
+
allow_any_instance_of(Belajar::Chapter)
|
82
|
+
.to receive(:mastered?)
|
83
|
+
.and_return(false)
|
84
|
+
|
85
|
+
allow(subject.chapters.first).to receive(:mastered?).and_return(true)
|
78
86
|
expect(subject.mastered?).to be false
|
79
87
|
end
|
80
88
|
end
|
81
89
|
|
82
|
-
describe
|
83
|
-
it
|
84
|
-
allow(subject).to receive(:title)
|
85
|
-
key =
|
90
|
+
describe '#key' do
|
91
|
+
it 'returns the courses store key for the given key name' do
|
92
|
+
allow(subject).to receive(:title).and_return('1-Course title')
|
93
|
+
key = 'courses/course_title/some_key'
|
86
94
|
expect(subject.key('1-some Key')).to eq key
|
87
95
|
end
|
88
96
|
end
|
89
97
|
|
90
|
-
describe
|
91
|
-
it
|
98
|
+
describe '#author' do
|
99
|
+
it 'returns the author of Github courses form the store' do
|
92
100
|
author = 'author'
|
93
101
|
QuickStore.store.set(subject.key(:author), author)
|
94
102
|
|
@@ -97,77 +105,87 @@ describe Belajar::Course do
|
|
97
105
|
end
|
98
106
|
end
|
99
107
|
|
100
|
-
describe
|
108
|
+
describe '.unzip' do
|
101
109
|
before do
|
102
110
|
Belajar.config.courses_path = local_courses_path
|
103
|
-
|
111
|
+
|
112
|
+
@zip_file_name = 'unzip/repo.zip'
|
104
113
|
@zip_file_path = File.join(courses_basepath, @zip_file_name)
|
105
|
-
@file_content
|
114
|
+
@file_content = prepare_download(@zip_file_name)
|
106
115
|
end
|
107
116
|
|
108
117
|
after do
|
109
118
|
cleanup_download(@zip_file_name)
|
110
119
|
dir = File.dirname(@zip_file_path)
|
111
|
-
|
120
|
+
remove_directory(dir)
|
112
121
|
end
|
113
122
|
|
114
123
|
def expect_course_dirs_exists_to_be(boolean)
|
115
124
|
unit_dirs(course_dir_names.first).each do |chapter_dirs|
|
116
125
|
chapter_dirs.each do |dir|
|
117
|
-
path = [
|
126
|
+
path = [
|
127
|
+
dir.split('/')[0..-4],
|
128
|
+
'unzip',
|
129
|
+
dir.split('/')[-3..-1]
|
130
|
+
].join('/')
|
131
|
+
|
118
132
|
expect(Dir.exist?(path)).to be boolean
|
119
133
|
end
|
120
134
|
end
|
121
135
|
end
|
122
136
|
|
123
|
-
it
|
137
|
+
it 'unzips a course zip file' do
|
124
138
|
expect_course_dirs_exists_to_be false
|
125
139
|
Belajar::Course.unzip(@zip_file_path)
|
126
140
|
expect_course_dirs_exists_to_be true
|
127
141
|
end
|
128
142
|
|
129
|
-
it
|
130
|
-
dir
|
131
|
-
path
|
132
|
-
course = Belajar::Course.new(path)
|
143
|
+
it 'returns the unzipped course' do
|
144
|
+
dir = course_dirs.first
|
145
|
+
path = File.join(File.dirname(dir), 'unzip', File.basename(dir))
|
133
146
|
|
134
|
-
|
147
|
+
actual = Belajar::Course.unzip(@zip_file_path)
|
148
|
+
expected = Belajar::Course.new(path)
|
149
|
+
|
150
|
+
expect(actual.path).to eq expected.path
|
151
|
+
expect(actual.title).to eq expected.title
|
152
|
+
expect(actual.author).to eq expected.author
|
135
153
|
end
|
136
154
|
|
137
|
-
it
|
155
|
+
it 'removes the zip file' do
|
138
156
|
expect(File.exist?(@zip_file_path)).to be true
|
139
157
|
Belajar::Course.unzip(@zip_file_path)
|
140
158
|
expect(File.exist?(@zip_file_path)).to be false
|
141
159
|
end
|
142
160
|
|
143
|
-
context
|
161
|
+
context 'with the same course already available' do
|
144
162
|
before do
|
145
163
|
dir = course_dirs.first
|
146
164
|
@path = File.join(File.dirname(dir), 'unzip', File.basename(dir))
|
147
165
|
@old_chapter_dir = File.join(@path, 'Old_chapter')
|
148
166
|
|
149
|
-
|
167
|
+
create_directory(@old_chapter_dir)
|
150
168
|
end
|
151
169
|
|
152
|
-
it
|
170
|
+
it 'overwrites all chapters' do
|
153
171
|
expect(Dir.exist?(@old_chapter_dir)).to be true
|
154
172
|
Belajar::Course.unzip(@zip_file_path)
|
155
173
|
expect(Dir.exist?(@old_chapter_dir)).to be false
|
156
174
|
end
|
157
175
|
|
158
|
-
context
|
176
|
+
context 'if an error occurs' do
|
159
177
|
before do
|
160
178
|
allow_any_instance_of(Zip::File)
|
161
|
-
.to receive(:extract) { raise
|
179
|
+
.to receive(:extract) { raise StandardError.new, 'error' }
|
162
180
|
end
|
163
181
|
|
164
|
-
it
|
182
|
+
it 'restores an old state' do
|
165
183
|
Belajar::Course.unzip(@zip_file_path)
|
166
184
|
expect(Dir.exist?(@old_chapter_dir)).to be true
|
167
185
|
expect(Dir.exist?("#{@path}_old")).to be false
|
168
186
|
end
|
169
187
|
|
170
|
-
it
|
188
|
+
it 'keeps the zip file' do
|
171
189
|
expect(File.exist?(@zip_file_path)).to be true
|
172
190
|
Belajar::Course.unzip(@zip_file_path)
|
173
191
|
expect(File.exist?(@zip_file_path)).to be true
|
@@ -175,12 +193,12 @@ describe Belajar::Course do
|
|
175
193
|
end
|
176
194
|
end
|
177
195
|
|
178
|
-
context
|
196
|
+
context 'with the github_repo option:' do
|
179
197
|
before { @github_course_dir = prepare_github_course }
|
180
|
-
after
|
198
|
+
after { remove_directory(@github_course_dir) }
|
181
199
|
|
182
|
-
it
|
183
|
-
zip_file_name =
|
200
|
+
it 'removes the "-master" from the root directory' do
|
201
|
+
zip_file_name = 'unzip/repo-master.zip'
|
184
202
|
zip_file_path = File.join(courses_basepath, zip_file_name)
|
185
203
|
prepare_github_download(zip_file_name)
|
186
204
|
|
@@ -189,7 +207,12 @@ describe Belajar::Course do
|
|
189
207
|
|
190
208
|
unit_dirs("#{course_dir_names.first}-master").each do |chapter_dirs|
|
191
209
|
chapter_dirs.each do |dir|
|
192
|
-
path = [
|
210
|
+
path = [
|
211
|
+
dir.split('/')[0..-4],
|
212
|
+
'unzip',
|
213
|
+
dir.split('/')[-3..-1]
|
214
|
+
].join('/')
|
215
|
+
|
193
216
|
expect(Dir.exist?(path)).to be false
|
194
217
|
end
|
195
218
|
end
|