daigaku 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +7 -4
- data/CODE_OF_CONDUCT.md +77 -0
- data/README.md +11 -11
- data/bin/daigaku +6 -2
- data/daigaku.gemspec +22 -26
- data/lib/daigaku.rb +0 -1
- data/lib/daigaku/chapter.rb +3 -4
- data/lib/daigaku/coloring.rb +22 -27
- data/lib/daigaku/configuration.rb +25 -28
- data/lib/daigaku/congratulator.rb +17 -5
- data/lib/daigaku/course.rb +9 -8
- data/lib/daigaku/exceptions.rb +0 -2
- data/lib/daigaku/generator.rb +13 -15
- data/lib/daigaku/github_client.rb +5 -5
- data/lib/daigaku/loadable.rb +23 -14
- data/lib/daigaku/loading/chapters.rb +0 -2
- data/lib/daigaku/loading/courses.rb +0 -2
- data/lib/daigaku/loading/units.rb +0 -2
- data/lib/daigaku/markdown.rb +1 -0
- data/lib/daigaku/markdown/printer.rb +89 -0
- data/lib/daigaku/markdown/ruby_doc.rb +15 -15
- data/lib/daigaku/solution.rb +23 -15
- data/lib/daigaku/storeable.rb +11 -12
- data/lib/daigaku/task.rb +1 -1
- data/lib/daigaku/terminal.rb +3 -4
- data/lib/daigaku/terminal/cli.rb +8 -8
- data/lib/daigaku/terminal/courses.rb +22 -19
- data/lib/daigaku/terminal/output.rb +46 -53
- data/lib/daigaku/terminal/setup.rb +13 -18
- data/lib/daigaku/terminal/solutions.rb +27 -32
- data/lib/daigaku/terminal/welcome.rb +9 -11
- data/lib/daigaku/test.rb +7 -10
- data/lib/daigaku/test_result.rb +54 -21
- data/lib/daigaku/unit.rb +2 -4
- data/lib/daigaku/version.rb +1 -1
- data/lib/daigaku/views.rb +29 -33
- data/lib/daigaku/views/chapters_menu.rb +16 -20
- data/lib/daigaku/views/courses_menu.rb +12 -15
- data/lib/daigaku/views/main_menu.rb +23 -23
- data/lib/daigaku/views/menu.rb +14 -18
- data/lib/daigaku/views/splash.rb +11 -13
- data/lib/daigaku/views/subscriber.rb +38 -0
- data/lib/daigaku/views/task_view.rb +97 -80
- data/lib/daigaku/views/top_bar.rb +4 -10
- data/lib/daigaku/views/units_menu.rb +16 -21
- data/lib/daigaku/window.rb +12 -70
- data/spec/daigaku/chapter_spec.rb +23 -18
- data/spec/daigaku/coloring_spec.rb +0 -1
- data/spec/daigaku/configuration_spec.rb +54 -50
- data/spec/daigaku/congratulator_spec.rb +11 -8
- data/spec/daigaku/course_spec.rb +75 -52
- data/spec/daigaku/generator_spec.rb +24 -25
- data/spec/daigaku/github_client_spec.rb +17 -18
- data/spec/daigaku/loading/chapters_spec.rb +2 -3
- data/spec/daigaku/loading/courses_spec.rb +2 -3
- data/spec/daigaku/loading/units_spec.rb +4 -5
- data/spec/daigaku/markdown/ruby_doc_spec.rb +12 -6
- data/spec/daigaku/reference_solution_spec.rb +8 -10
- data/spec/daigaku/solution_spec.rb +21 -22
- data/spec/daigaku/storeable_spec.rb +12 -10
- data/spec/daigaku/task_spec.rb +3 -4
- data/spec/daigaku/terminal/cli_spec.rb +29 -21
- data/spec/daigaku/terminal/courses_spec.rb +104 -99
- data/spec/daigaku/terminal/output_spec.rb +44 -39
- data/spec/daigaku/terminal/setup_spec.rb +1 -3
- data/spec/daigaku/terminal/solutions_spec.rb +0 -2
- data/spec/daigaku/terminal/welcome_spec.rb +0 -2
- data/spec/daigaku/terminal_spec.rb +5 -7
- data/spec/daigaku/test_example_spec.rb +16 -14
- data/spec/daigaku/test_result_spec.rb +21 -25
- data/spec/daigaku/test_spec.rb +11 -12
- data/spec/daigaku/unit_spec.rb +24 -27
- data/spec/daigaku/views/chapters_menu_spec.rb +0 -1
- data/spec/daigaku/views/courses_menu_spec.rb +0 -1
- data/spec/daigaku/views/menu_spec.rb +1 -2
- data/spec/daigaku/views/task_view_spec.rb +0 -2
- data/spec/daigaku/views/units_menu_spec.rb +0 -1
- data/spec/daigaku/views_spec.rb +0 -1
- data/spec/daigaku_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 +32 -44
data/spec/daigaku/unit_spec.rb
CHANGED
@@ -1,85 +1,82 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Daigaku::Unit do
|
4
|
-
|
5
4
|
it { is_expected.to respond_to :title }
|
6
5
|
it { is_expected.to respond_to :task }
|
7
6
|
it { is_expected.to respond_to :solution }
|
8
7
|
it { is_expected.to respond_to :reference_solution }
|
9
8
|
it { is_expected.to respond_to :mastered? }
|
10
9
|
|
11
|
-
let(:course_name)
|
10
|
+
let(:course_name) { course_dir_names.first }
|
12
11
|
let(:chapter_name) { chapter_dir_names.first }
|
13
|
-
let(:unit_name)
|
12
|
+
let(:unit_name) { unit_dir_names.first }
|
14
13
|
|
15
14
|
subject { Daigaku::Unit.new(unit_dirs(course_name).first[0]) }
|
16
15
|
|
17
|
-
it
|
16
|
+
it 'has the prescribed title' do
|
18
17
|
expect(subject.title).to eq unit_titles.first
|
19
18
|
end
|
20
19
|
|
21
|
-
describe
|
22
|
-
it
|
20
|
+
describe '#task' do
|
21
|
+
it 'returns an object of type Daigaku::Task' do
|
23
22
|
expect(subject.task).to be_a Daigaku::Task
|
24
23
|
end
|
25
24
|
|
26
|
-
it
|
25
|
+
it 'returns the unit’s appropriate task' do
|
27
26
|
task = available_task(course_name, chapter_name, unit_name).first
|
28
27
|
expect(subject.task.markdown).to eq task.markdown
|
29
28
|
end
|
30
29
|
|
31
|
-
it
|
30
|
+
it 'lazy-loads the task' do
|
32
31
|
expect(subject.instance_variable_get(:@task)).to be_nil
|
33
32
|
subject.task
|
34
33
|
expect(subject.instance_variable_get(:@task)).not_to be_nil
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
describe
|
39
|
-
it
|
37
|
+
describe '#reference_solution' do
|
38
|
+
it 'returns an object of type Daigaku::ReferenceSolution' do
|
40
39
|
expect(subject.reference_solution).to be_a Daigaku::ReferenceSolution
|
41
40
|
end
|
42
41
|
|
43
|
-
it
|
44
|
-
|
45
|
-
|
46
|
-
unit_name).first
|
42
|
+
it 'returns the units appropriate predefined reference solution' do
|
43
|
+
names = [course_name, chapter_name, unit_name]
|
44
|
+
reference_solution = available_reference_solution(*names).first
|
47
45
|
expect(subject.reference_solution.code).to eq reference_solution.code
|
48
46
|
end
|
49
47
|
|
50
|
-
it
|
48
|
+
it 'lazy-loads the reference solution' do
|
51
49
|
expect(subject.instance_variable_get(:@reference_solution)).to be_nil
|
52
50
|
subject.reference_solution
|
53
51
|
expect(subject.instance_variable_get(:@reference_solution)).not_to be_nil
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
|
-
describe
|
58
|
-
it
|
55
|
+
describe '#solution' do
|
56
|
+
it 'returns an object of type Daigaku::Solution' do
|
59
57
|
expect(subject.solution).to be_a Daigaku::Solution
|
60
58
|
end
|
61
59
|
|
62
|
-
it
|
63
|
-
|
64
|
-
|
65
|
-
unit_name).code
|
60
|
+
it 'returns the units appropriate solution provided by the user' do
|
61
|
+
code = available_solution(course_name, chapter_name, unit_name).code
|
62
|
+
expect(subject.solution.code).to eq code
|
66
63
|
end
|
67
64
|
|
68
|
-
it
|
65
|
+
it 'lazy-loads the reference solution' do
|
69
66
|
expect(subject.instance_variable_get(:@solution)).to be_nil
|
70
67
|
subject.solution
|
71
68
|
expect(subject.instance_variable_get(:@solution)).not_to be_nil
|
72
69
|
end
|
73
70
|
end
|
74
71
|
|
75
|
-
describe
|
76
|
-
it
|
77
|
-
expect(subject.mastered?).to
|
72
|
+
describe '#mastered?' do
|
73
|
+
it 'returns false by default' do
|
74
|
+
expect(subject.mastered?).to be false
|
78
75
|
end
|
79
76
|
|
80
|
-
it
|
77
|
+
it 'returns true if the solution has been verified' do
|
81
78
|
allow_any_instance_of(Daigaku::Solution).to receive(:verified?) { true }
|
82
|
-
expect(subject.mastered?).to
|
79
|
+
expect(subject.mastered?).to be true
|
83
80
|
end
|
84
81
|
end
|
85
82
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Daigaku::Views::Menu do
|
4
|
-
|
5
4
|
it { is_expected.to respond_to :enter }
|
6
5
|
it { is_expected.to respond_to :reenter }
|
7
6
|
|
@@ -16,4 +15,4 @@ describe Daigaku::Views::Menu do
|
|
16
15
|
expect(subject.protected_methods).to include(method)
|
17
16
|
end
|
18
17
|
end
|
19
|
-
end
|
18
|
+
end
|
data/spec/daigaku/views_spec.rb
CHANGED
data/spec/daigaku_spec.rb
CHANGED
@@ -1,28 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
describe "::config" do
|
6
|
-
|
3
|
+
describe 'Daigaku module' do
|
4
|
+
describe '.config' do
|
7
5
|
subject { Daigaku.config }
|
8
6
|
|
9
7
|
[:config, :configure, :start].each do |method|
|
10
|
-
it "responds to
|
8
|
+
it "responds to .#{method}" do
|
11
9
|
expect(Daigaku.singleton_methods).to include method
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
|
-
it
|
13
|
+
it 'returns Configuration of class Daigaku::Configuration' do
|
16
14
|
expect(subject).to be_an_instance_of Daigaku::Configuration
|
17
15
|
end
|
18
16
|
|
19
|
-
it
|
17
|
+
it 'returns a singleton setting' do
|
20
18
|
expect(subject).to be Daigaku.config
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
describe
|
25
|
-
|
22
|
+
describe '.configure' do
|
26
23
|
let(:configure) do
|
27
24
|
proc do
|
28
25
|
Daigaku.configure do |config|
|
@@ -31,16 +28,16 @@ describe "Daigaku module" do
|
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
34
|
-
it
|
31
|
+
it 'allows to configure the app' do
|
35
32
|
expect { configure.call }.not_to raise_error
|
36
33
|
end
|
37
34
|
|
38
|
-
it
|
35
|
+
it 'sets configuration properties' do
|
39
36
|
configure.call
|
40
37
|
expect(Daigaku.config.solutions_path).to eq test_basepath
|
41
38
|
end
|
42
39
|
|
43
|
-
it
|
40
|
+
it 'allows to change the config during runtime' do
|
44
41
|
Daigaku.configure do |config|
|
45
42
|
config.solutions_path = courses_basepath
|
46
43
|
end
|
data/spec/path_helpers_spec.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
it "provides a temp base path" do
|
3
|
+
describe 'PathHelpers' do
|
4
|
+
it 'provides a temp base path' do
|
6
5
|
puts "\n* temp base path:"
|
7
6
|
puts temp_basepath
|
8
7
|
end
|
9
8
|
|
10
|
-
it
|
9
|
+
it 'provides a test base path' do
|
11
10
|
puts "\n* test base path:"
|
12
11
|
puts test_basepath
|
13
12
|
end
|
14
13
|
|
15
|
-
it
|
14
|
+
it 'provides a courses base path' do
|
16
15
|
puts "\n* courses base path:"
|
17
16
|
puts courses_basepath
|
18
17
|
end
|
19
18
|
|
20
|
-
it
|
19
|
+
it 'provides the course directories' do
|
21
20
|
puts "\n* course dirs:"
|
22
21
|
puts course_dirs
|
23
22
|
end
|
24
23
|
|
25
|
-
it
|
24
|
+
it 'provides each course’s chapter directories' do
|
26
25
|
puts "\n* chapter dirs: "
|
27
26
|
|
28
27
|
course_dir_names.each do |course_name|
|
@@ -30,7 +29,7 @@ describe "PathHelpers" do
|
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
|
-
it
|
32
|
+
it 'provides each chapter’s unit directories' do
|
34
33
|
puts "\n* unit dirs:"
|
35
34
|
|
36
35
|
course_dir_names.each do |course_name|
|
@@ -38,22 +37,22 @@ describe "PathHelpers" do
|
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
it
|
40
|
+
it 'provides all unit directories as flattened array' do
|
42
41
|
puts "\n* all unit dirs:"
|
43
42
|
puts all_unit_dirs
|
44
43
|
end
|
45
44
|
|
46
|
-
it
|
45
|
+
it 'provides all solution file paths' do
|
47
46
|
puts "\n* all solution file paths:"
|
48
47
|
puts all_solution_file_paths
|
49
48
|
end
|
50
49
|
|
51
|
-
it
|
50
|
+
it 'provides all test file paths' do
|
52
51
|
puts "\n* all test file paths:"
|
53
52
|
puts all_test_file_paths
|
54
53
|
end
|
55
54
|
|
56
|
-
it
|
55
|
+
it 'provides the local_storage_file path' do
|
57
56
|
puts "\n* local storage file path:"
|
58
57
|
puts local_storage_file
|
59
58
|
end
|
@@ -1,33 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
3
|
+
describe 'ResourceHelpers' do
|
5
4
|
let(:course) { course_dir_names.first }
|
6
5
|
let(:chapter) { chapter_dir_names.first }
|
7
6
|
let(:unit) { unit_dir_names.first }
|
8
7
|
|
9
|
-
it
|
8
|
+
it 'provides the available courses' do
|
10
9
|
puts "\n* available courses:"
|
11
|
-
puts available_courses.map
|
10
|
+
puts available_courses.map(&:inspect)
|
12
11
|
end
|
13
12
|
|
14
|
-
it
|
13
|
+
it 'provides a course’s available chapters' do
|
15
14
|
puts "\n* available chapters:"
|
16
|
-
puts available_chapters(course).map
|
15
|
+
puts available_chapters(course).map(&:inspect)
|
17
16
|
end
|
18
17
|
|
19
|
-
it
|
18
|
+
it 'provides a chapter’s avaliable units' do
|
20
19
|
puts "\n* available units:"
|
21
|
-
puts available_units(course, chapter).map
|
20
|
+
puts available_units(course, chapter).map(&:inspect)
|
22
21
|
end
|
23
22
|
|
24
|
-
it
|
23
|
+
it 'provides a unit’s task file' do
|
25
24
|
puts "\n* task:"
|
26
|
-
puts available_task(course, chapter, unit).map
|
25
|
+
puts available_task(course, chapter, unit).map(&:inspect)
|
27
26
|
end
|
28
27
|
|
29
|
-
it
|
28
|
+
it 'provides a unit’s reference solution file' do
|
30
29
|
puts "\n* reference solution:"
|
31
|
-
puts available_reference_solution(course, chapter, unit).map
|
30
|
+
puts available_reference_solution(course, chapter, unit).map(&:inspect)
|
32
31
|
end
|
33
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,9 +3,8 @@ require 'webmock/rspec'
|
|
3
3
|
|
4
4
|
def require_files_from(paths = [])
|
5
5
|
paths.each do |path|
|
6
|
-
Dir[File.join(File.expand_path("#{path}*.rb", __FILE__))].sort
|
7
|
-
|
8
|
-
end
|
6
|
+
files = Dir[File.join(File.expand_path("#{path}*.rb", __FILE__))].sort
|
7
|
+
files.each { |file| require file }
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
@@ -13,7 +12,7 @@ RSpec.configure do |config|
|
|
13
12
|
config.color = true
|
14
13
|
|
15
14
|
require File.expand_path('../../lib/daigaku', __FILE__)
|
16
|
-
require_files_from [
|
15
|
+
require_files_from ['../support/**/']
|
17
16
|
|
18
17
|
config.include TestHelpers
|
19
18
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module ContentHelpers
|
2
|
-
|
3
2
|
TASK_FILE_CONTENT = [
|
4
|
-
"Heading\n======",
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
"Heading\n======",
|
4
|
+
'##Task',
|
5
|
+
'Solve this task!',
|
6
|
+
'##Hints',
|
7
|
+
'Just do it right...'
|
8
|
+
].join("\n\n").freeze
|
9
9
|
|
10
|
-
SOLUTION_CONTENT = 'print "hello world".upcase'
|
10
|
+
SOLUTION_CONTENT = 'print "hello world".upcase'.freeze
|
11
11
|
|
12
12
|
TEST_CONTENT = [
|
13
13
|
"require 'rspec'\n",
|
@@ -20,12 +20,12 @@ module ContentHelpers
|
|
20
20
|
" allow(self).to receive(:print).and_return ''",
|
21
21
|
" expect_any_instance_of(String).to receive(:upcase).and_return('HELLO WORLD')\n",
|
22
22
|
" [['solution::code']]",
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
' end',
|
24
|
+
'end'
|
25
|
+
].join("\n").freeze
|
26
26
|
|
27
27
|
TEST_FAILED_JSON =
|
28
|
-
|
28
|
+
'
|
29
29
|
{ "examples":
|
30
30
|
[
|
31
31
|
{ "description": "description 1",
|
@@ -56,10 +56,10 @@ module ContentHelpers
|
|
56
56
|
},
|
57
57
|
"summary_line": "2 example, 1 failure"
|
58
58
|
}
|
59
|
-
|
59
|
+
'.freeze
|
60
60
|
|
61
61
|
TEST_PASSED_JSON =
|
62
|
-
|
62
|
+
'
|
63
63
|
{ "examples":
|
64
64
|
[
|
65
65
|
{ "description":"description 1",
|
@@ -85,10 +85,10 @@ module ContentHelpers
|
|
85
85
|
},
|
86
86
|
"summary_line":"2 example, 0 failures"
|
87
87
|
}
|
88
|
-
|
88
|
+
'.freeze
|
89
89
|
|
90
|
-
TEST_PASSED_MESSAGE
|
91
|
-
EXAMPLE_PASSED_MESSAGE =
|
90
|
+
TEST_PASSED_MESSAGE = 'Your code passed all tests.'.freeze
|
91
|
+
EXAMPLE_PASSED_MESSAGE = 'Your code passed this requirement.'.freeze
|
92
92
|
|
93
93
|
def task_file_content
|
94
94
|
TASK_FILE_CONTENT
|
@@ -125,5 +125,4 @@ module ContentHelpers
|
|
125
125
|
def example_passed_message
|
126
126
|
EXAMPLE_PASSED_MESSAGE
|
127
127
|
end
|
128
|
-
|
129
128
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module MockHelpers
|
2
|
-
|
3
2
|
def mock_default_window
|
4
3
|
allow_any_instance_of(described_class).to receive(:default_window) { true }
|
5
4
|
end
|
@@ -16,10 +15,11 @@ module MockHelpers
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def suppress_print_out
|
19
|
-
allow(described_class).to receive(:say_warning)
|
20
|
-
allow(described_class).to receive(:say_info)
|
21
|
-
allow(described_class).to receive(:say)
|
22
|
-
|
23
|
-
allow($stdout).to receive(:
|
18
|
+
allow(described_class).to receive(:say_warning)
|
19
|
+
allow(described_class).to receive(:say_info)
|
20
|
+
allow(described_class).to receive(:say)
|
21
|
+
|
22
|
+
allow($stdout).to receive(:puts)
|
23
|
+
allow($stdout).to receive(:print)
|
24
24
|
end
|
25
25
|
end
|