daigaku 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +7 -4
  3. data/CODE_OF_CONDUCT.md +77 -0
  4. data/README.md +11 -11
  5. data/bin/daigaku +6 -2
  6. data/daigaku.gemspec +22 -26
  7. data/lib/daigaku.rb +0 -1
  8. data/lib/daigaku/chapter.rb +3 -4
  9. data/lib/daigaku/coloring.rb +22 -27
  10. data/lib/daigaku/configuration.rb +25 -28
  11. data/lib/daigaku/congratulator.rb +17 -5
  12. data/lib/daigaku/course.rb +9 -8
  13. data/lib/daigaku/exceptions.rb +0 -2
  14. data/lib/daigaku/generator.rb +13 -15
  15. data/lib/daigaku/github_client.rb +5 -5
  16. data/lib/daigaku/loadable.rb +23 -14
  17. data/lib/daigaku/loading/chapters.rb +0 -2
  18. data/lib/daigaku/loading/courses.rb +0 -2
  19. data/lib/daigaku/loading/units.rb +0 -2
  20. data/lib/daigaku/markdown.rb +1 -0
  21. data/lib/daigaku/markdown/printer.rb +89 -0
  22. data/lib/daigaku/markdown/ruby_doc.rb +15 -15
  23. data/lib/daigaku/solution.rb +23 -15
  24. data/lib/daigaku/storeable.rb +11 -12
  25. data/lib/daigaku/task.rb +1 -1
  26. data/lib/daigaku/terminal.rb +3 -4
  27. data/lib/daigaku/terminal/cli.rb +8 -8
  28. data/lib/daigaku/terminal/courses.rb +22 -19
  29. data/lib/daigaku/terminal/output.rb +46 -53
  30. data/lib/daigaku/terminal/setup.rb +13 -18
  31. data/lib/daigaku/terminal/solutions.rb +27 -32
  32. data/lib/daigaku/terminal/welcome.rb +9 -11
  33. data/lib/daigaku/test.rb +7 -10
  34. data/lib/daigaku/test_result.rb +54 -21
  35. data/lib/daigaku/unit.rb +2 -4
  36. data/lib/daigaku/version.rb +1 -1
  37. data/lib/daigaku/views.rb +29 -33
  38. data/lib/daigaku/views/chapters_menu.rb +16 -20
  39. data/lib/daigaku/views/courses_menu.rb +12 -15
  40. data/lib/daigaku/views/main_menu.rb +23 -23
  41. data/lib/daigaku/views/menu.rb +14 -18
  42. data/lib/daigaku/views/splash.rb +11 -13
  43. data/lib/daigaku/views/subscriber.rb +38 -0
  44. data/lib/daigaku/views/task_view.rb +97 -80
  45. data/lib/daigaku/views/top_bar.rb +4 -10
  46. data/lib/daigaku/views/units_menu.rb +16 -21
  47. data/lib/daigaku/window.rb +12 -70
  48. data/spec/daigaku/chapter_spec.rb +23 -18
  49. data/spec/daigaku/coloring_spec.rb +0 -1
  50. data/spec/daigaku/configuration_spec.rb +54 -50
  51. data/spec/daigaku/congratulator_spec.rb +11 -8
  52. data/spec/daigaku/course_spec.rb +75 -52
  53. data/spec/daigaku/generator_spec.rb +24 -25
  54. data/spec/daigaku/github_client_spec.rb +17 -18
  55. data/spec/daigaku/loading/chapters_spec.rb +2 -3
  56. data/spec/daigaku/loading/courses_spec.rb +2 -3
  57. data/spec/daigaku/loading/units_spec.rb +4 -5
  58. data/spec/daigaku/markdown/ruby_doc_spec.rb +12 -6
  59. data/spec/daigaku/reference_solution_spec.rb +8 -10
  60. data/spec/daigaku/solution_spec.rb +21 -22
  61. data/spec/daigaku/storeable_spec.rb +12 -10
  62. data/spec/daigaku/task_spec.rb +3 -4
  63. data/spec/daigaku/terminal/cli_spec.rb +29 -21
  64. data/spec/daigaku/terminal/courses_spec.rb +104 -99
  65. data/spec/daigaku/terminal/output_spec.rb +44 -39
  66. data/spec/daigaku/terminal/setup_spec.rb +1 -3
  67. data/spec/daigaku/terminal/solutions_spec.rb +0 -2
  68. data/spec/daigaku/terminal/welcome_spec.rb +0 -2
  69. data/spec/daigaku/terminal_spec.rb +5 -7
  70. data/spec/daigaku/test_example_spec.rb +16 -14
  71. data/spec/daigaku/test_result_spec.rb +21 -25
  72. data/spec/daigaku/test_spec.rb +11 -12
  73. data/spec/daigaku/unit_spec.rb +24 -27
  74. data/spec/daigaku/views/chapters_menu_spec.rb +0 -1
  75. data/spec/daigaku/views/courses_menu_spec.rb +0 -1
  76. data/spec/daigaku/views/menu_spec.rb +1 -2
  77. data/spec/daigaku/views/task_view_spec.rb +0 -2
  78. data/spec/daigaku/views/units_menu_spec.rb +0 -1
  79. data/spec/daigaku/views_spec.rb +0 -1
  80. data/spec/daigaku_spec.rb +9 -12
  81. data/spec/path_helpers_spec.rb +11 -12
  82. data/spec/resource_helpers_spec.rb +11 -12
  83. data/spec/spec_helper.rb +3 -4
  84. data/spec/support/macros/content_helpers.rb +16 -17
  85. data/spec/support/macros/mock_helpers.rb +6 -6
  86. data/spec/support/macros/path_helpers.rb +15 -15
  87. data/spec/support/macros/resource_helpers.rb +34 -35
  88. metadata +32 -44
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Terminal::Output do
4
-
5
4
  subject do
6
5
  require 'thor'
7
6
  class Test < Thor
@@ -30,61 +29,64 @@ describe Daigaku::Terminal::Output do
30
29
  end
31
30
  end
32
31
 
33
- describe "::say" do
34
- it "prints the prescribed output to the $stdout" do
35
- line = "line"
32
+ describe '.say' do
33
+ it 'prints the prescribed output to the $stdout' do
34
+ line = 'line'
36
35
  expect($stdout).to receive(:puts).with("\t#{line}")
37
36
  subject.send(:say, line)
38
37
  end
39
38
 
40
- it "adds the line start in case of multiline inputs" do
41
- lines = "first line\nsecond line\nthird line\n"
42
- out_lines = lines.split("\n").map {|l| "\t#{l}" }.join("\n")
39
+ it 'adds the line start in case of multiline inputs' do
40
+ lines = "first line\nsecond line\nthird line\n"
41
+ out_lines = lines.split("\n").map { |l| "\t#{l}" }.join("\n")
42
+
43
43
  expect($stdout).to receive(:puts).with(out_lines)
44
44
  subject.send(:say, lines)
45
45
  end
46
46
  end
47
47
 
48
- describe "::empty_line" do
49
- it "prints an empty line to the $stdout" do
48
+ describe '.empty_line' do
49
+ it 'prints an empty line to the $stdout' do
50
50
  expect($stdout).to receive(:puts).with('')
51
51
  subject.send(:empty_line)
52
52
  end
53
53
  end
54
54
 
55
- describe "::get" do
56
- it "prints a string to $stdout to get a line on $stdin" do
57
- printed = 'printed'
58
- received = 'received'
55
+ describe '.get' do
56
+ let(:text) { 'printed' }
57
+
58
+ it 'prints a string to $stdout to get a line on $stdin' do
59
+ allow($stdin).to receive(:gets).and_return('received')
59
60
 
60
- allow($stdin).to receive(:gets) { received }
61
- expect($stdout).to receive(:print).with("\n\t#{printed} ")
61
+ expect($stdout).to receive(:print).with("\n\t#{text} ")
62
62
  expect($stdin).to receive(:gets)
63
- subject.send(:get, printed)
63
+ subject.send(:get, text)
64
64
  end
65
65
  end
66
66
 
67
- describe "::say_info" do
68
- it "prints the prescribed output to the $stdout" do
69
- line = "line"
70
- expect($stdout).to receive(:puts).exactly(4).times.with("")
67
+ describe '.say_info' do
68
+ let(:line) { 'line' }
69
+
70
+ it 'prints the prescribed output to the $stdout' do
71
+ expect($stdout).to receive(:puts).exactly(4).times.with('')
71
72
  expect($stdout).to receive(:puts).with("\t" + " ℹ #{line}".light_blue)
72
- expect($stdout).to receive(:puts).twice.times.with("\t" + ('-' * 70).light_blue)
73
+ expect($stdout).to receive(:puts).twice.with("\t" + ('-' * 70).light_blue)
73
74
  subject.send(:say_info, line)
74
75
  end
75
76
  end
76
77
 
77
- describe "::say_warning" do
78
- it "prints the prescribed output to the $stdout" do
79
- line = "line"
80
- expect($stdout).to receive(:puts).exactly(4).times.with("")
78
+ describe '.say_warning' do
79
+ let(:line) { 'line' }
80
+
81
+ it 'prints the prescribed output to the $stdout' do
82
+ expect($stdout).to receive(:puts).exactly(4).times.with('')
81
83
  expect($stdout).to receive(:puts).with("\t" + "⚠ #{line}".light_red)
82
- expect($stdout).to receive(:puts).twice.times.with("\t" + ('-' * 70).light_red)
84
+ expect($stdout).to receive(:puts).twice.with("\t" + ('-' * 70).light_red)
83
85
  subject.send(:say_warning, line)
84
86
  end
85
87
  end
86
88
 
87
- describe "::get_command" do
89
+ describe '.get_command' do
88
90
  before do
89
91
  @correct_command = 'correct command'
90
92
  @description = 'description'
@@ -92,27 +94,30 @@ describe Daigaku::Terminal::Output do
92
94
  allow(Kernel).to receive(:system) { '' }
93
95
  end
94
96
 
95
- it "prints a description" do
97
+ it 'prints a description' do
96
98
  expect($stdout).to receive(:puts).once.with("\t#{@description}")
97
99
  subject.send(:get_command, @correct_command, @description)
98
100
  end
99
101
 
100
- it "gets a command from the $stdin" do
102
+ it 'gets a command from the $stdin' do
101
103
  expect($stdin).to receive(:gets)
102
104
  subject.send(:get_command, @correct_command, @description)
103
105
  end
104
106
 
105
- context "with the right command typed in:" do
106
- it "gets a specified command from the user" do
107
+ context 'with the right command typed in' do
108
+ it 'gets a specified command from the user' do
107
109
  subject.send(:get_command, @correct_command, @description)
108
110
  end
109
111
  end
110
112
 
111
- context "with a wrong command typed in:" do
112
- it "writes a hint" do
113
+ context 'with a wrong command typed in' do
114
+ it 'writes a hint' do
113
115
  wrong_command = 'wrong command'
114
116
  error = "This was something else. Try \"#{@correct_command}\"."
115
- allow($stdin).to receive(:gets).and_return(wrong_command, @correct_command)
117
+
118
+ allow($stdin)
119
+ .to receive(:gets)
120
+ .and_return(wrong_command, @correct_command)
116
121
 
117
122
  expect($stdout).to receive(:puts).once.with("\t#{error}")
118
123
  subject.send(:get_command, @correct_command, @description)
@@ -120,29 +125,29 @@ describe Daigaku::Terminal::Output do
120
125
  end
121
126
  end
122
127
 
123
- describe "::get_confirm" do
128
+ describe '.get_confirm' do
124
129
  before do
125
130
  @description = 'description'
126
131
  allow($stdin).to receive(:gets).and_return('yes')
127
132
  end
128
133
 
129
- it "prints a warning with the given description" do
134
+ it 'prints a warning with the given description' do
130
135
  expect(subject).to receive(:say_warning).once.with(@description)
131
136
  subject.send(:get_confirm, @description)
132
137
  end
133
138
 
134
- it "gets a command from the $stdin" do
139
+ it 'gets a command from the $stdin' do
135
140
  expect($stdin).to receive(:gets)
136
141
  subject.send(:get_confirm, @description)
137
142
  end
138
143
 
139
- it "takes a block to run when confirmed" do
144
+ it 'takes a block to run when confirmed' do
140
145
  allow(subject).to receive(:mocked_method).and_return('mocked method')
141
146
  expect(subject).to receive(:mocked_method)
142
147
  subject.send(:get_confirm, @description) { subject.mocked_method }
143
148
  end
144
149
 
145
- it "does not run the given block if not confirmed" do
150
+ it 'does not run the given block if not confirmed' do
146
151
  allow(subject).to receive(:get).and_return('no')
147
152
  expect(subject).not_to receive(:mocked_method)
148
153
  subject.send(:get_confirm, @description) { subject.mocked_method }
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Terminal::Setup do
4
-
5
4
  it { is_expected.to be_a Thor }
6
5
  it { is_expected.to respond_to :list }
7
6
  it { is_expected.to respond_to :set }
8
7
  it { is_expected.to respond_to :init }
9
-
10
- end
8
+ end
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Terminal::Solutions do
4
-
5
4
  it { is_expected.to be_a Thor }
6
5
  it { is_expected.to respond_to :open }
7
-
8
6
  end
@@ -1,12 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Terminal::Welcome do
4
-
5
4
  [:run, :about].each do |method|
6
5
  it "has the singleton method ::#{method}" do
7
6
  singleton_methods = Daigaku::Terminal::Welcome.singleton_methods
8
7
  expect(singleton_methods.include?(method)).to be_truthy
9
8
  end
10
9
  end
11
-
12
10
  end
@@ -1,24 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Terminal do
4
-
5
4
  it { is_expected.to respond_to :text }
6
5
 
7
- describe "::text" do
8
- it "loads a text from a file in the terminal/texts" do
6
+ describe '.text' do
7
+ it 'loads a text from a file in the terminal/texts' do
9
8
  text = Daigaku::Terminal.text(:welcome)
10
9
  expect(text).to be_a String
11
10
  end
12
11
 
13
- it "returns an empty string if the file does not exist" do
12
+ it 'returns an empty string if the file does not exist' do
14
13
  text = Daigaku::Terminal.text(:non_existent_text)
15
14
  expect(text).to eq ''
16
15
  end
17
16
 
18
- it "returns an empty string if the file has no content" do
19
- allow(File).to receive(:read) { '' }
17
+ it 'returns an empty string if the file has no content' do
18
+ allow(File).to receive(:read).and_return('')
20
19
  expect(Daigaku::Terminal.text(:congratulations)).to eq ''
21
20
  end
22
21
  end
23
-
24
22
  end
@@ -1,31 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::TestExample do
4
+ subject { Daigaku::TestExample.new(description: '', status: '') }
4
5
 
5
- it { is_expected.to respond_to :description }
6
- it { is_expected.to respond_to :status }
7
- it { is_expected.to respond_to :message }
6
+ it { is_expected.to respond_to :description }
7
+ it { is_expected.to respond_to :status }
8
+ it { is_expected.to respond_to :message }
8
9
 
9
- context "when passed:" do
10
+ context 'when passed' do
10
11
  let(:description) { test_passed_json_parsed[:examples].first[:description] }
11
- let(:status) { test_passed_json_parsed[:examples].first[:status] }
12
+ let(:status) { test_passed_json_parsed[:examples].first[:status] }
12
13
 
13
- subject { Daigaku::TestExample.new(description: description, status: status) }
14
+ subject do
15
+ Daigaku::TestExample.new(description: description, status: status)
16
+ end
14
17
 
15
- it "has the prescribed description" do
18
+ it 'has the prescribed description' do
16
19
  expect(subject.description).to eq description
17
20
  end
18
21
 
19
- it "has the prescribed status" do
22
+ it 'has the prescribed status' do
20
23
  expect(subject.status).to eq status
21
24
  end
22
25
 
23
- it "has the prescribed message" do
26
+ it 'has the prescribed message' do
24
27
  expect(subject.message).to eq example_passed_message
25
28
  end
26
29
  end
27
30
 
28
- context "when failed:" do
31
+ context 'when failed' do
29
32
  let(:description) { test_failed_json_parsed[:examples].first[:description] }
30
33
  let(:status) { test_failed_json_parsed[:examples].first[:status] }
31
34
  let(:message) { test_failed_json_parsed[:examples].first[:exception][:message] }
@@ -38,17 +41,16 @@ describe Daigaku::TestExample do
38
41
  )
39
42
  end
40
43
 
41
- it "has the prescribed description" do
44
+ it 'has the prescribed description' do
42
45
  expect(subject.description).to eq description
43
46
  end
44
47
 
45
- it "has the prescribed status" do
48
+ it 'has the prescribed status' do
46
49
  expect(subject.status).to eq status
47
50
  end
48
51
 
49
- it "has the prescribed message" do
52
+ it 'has the prescribed message' do
50
53
  expect(subject.message).to eq message
51
54
  end
52
55
  end
53
-
54
56
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::TestResult do
4
-
5
4
  subject { Daigaku::TestResult.new(test_passed_json) }
6
5
 
7
6
  it { is_expected.to respond_to :example_count }
@@ -11,55 +10,53 @@ describe Daigaku::TestResult do
11
10
  it { is_expected.to respond_to :summary }
12
11
  it { is_expected.to respond_to :summary_lines }
13
12
 
14
- context "with passed input:" do
15
-
13
+ context 'with passed input' do
16
14
  subject { Daigaku::TestResult.new(test_passed_json) }
17
15
 
18
- it "is marked passed" do
19
- expect(subject.passed?).to be_truthy
16
+ it 'is marked passed' do
17
+ expect(subject.passed?).to be true
20
18
  end
21
19
 
22
- it "has a default summary" do
20
+ it 'has a default summary' do
23
21
  expect(subject.summary).to include test_passed_summary
24
22
  end
25
23
  end
26
24
 
27
- context "with failed input:" do
28
-
25
+ context 'with failed input' do
29
26
  subject { Daigaku::TestResult.new(test_failed_json) }
30
27
 
31
- it "is not marked passed" do
32
- expect(subject.passed?).to be_falsey
28
+ it 'is not marked passed' do
29
+ expect(subject.passed?).to be false
33
30
  end
34
31
 
35
- it "has the prescribed example count" do
32
+ it 'has the prescribed example count' do
36
33
  example_count = test_failed_json_parsed[:summary][:example_count]
37
34
  expect(subject.example_count).to eq example_count
38
35
  end
39
36
 
40
- it "has the prescribed failure count" do
37
+ it 'has the prescribed failure count' do
41
38
  failure_count = test_failed_json_parsed[:summary][:failure_count]
42
39
  expect(subject.failure_count).to eq failure_count
43
40
  end
44
41
 
45
- describe "#examples" do
46
- it "returns the prescribed number of examples" do
42
+ describe '#examples' do
43
+ it 'returns the prescribed number of examples' do
47
44
  examples_count = test_failed_json_parsed[:examples].count
48
45
  expect(subject.examples.count).to eq examples_count
49
46
  end
50
47
 
51
- it "returns examples of type Daigaku::TestExample" do
48
+ it 'returns examples of type Daigaku::TestExample' do
52
49
  subject.examples.each do |example|
53
50
  expect(example).to be_a Daigaku::TestExample
54
51
  end
55
52
  end
56
53
 
57
- it "return examples with the prescribed info" do
54
+ it 'return examples with the prescribed info' do
58
55
  subject.examples.each_with_index do |example, index|
59
56
  description = test_failed_json_parsed[:examples][index][:full_description]
60
- status = test_failed_json_parsed[:examples][index][:status]
61
- exception = test_failed_json_parsed[:examples][index][:exception]
62
- message = exception ? exception[:message] : example_passed_message
57
+ status = test_failed_json_parsed[:examples][index][:status]
58
+ exception = test_failed_json_parsed[:examples][index][:exception]
59
+ message = exception ? exception[:message] : example_passed_message
63
60
 
64
61
  expect(example.description).to eq description
65
62
  expect(example.status).to eq status
@@ -68,8 +65,8 @@ describe Daigaku::TestResult do
68
65
  end
69
66
  end
70
67
 
71
- describe "#summary" do
72
- it "returns a string having all example infos" do
68
+ describe '#summary' do
69
+ it 'returns a string having all example infos' do
73
70
  subject.examples.each do |example|
74
71
  expect(subject.summary).to include example.description
75
72
  expect(subject.summary).to include example.message
@@ -79,13 +76,12 @@ describe Daigaku::TestResult do
79
76
  end
80
77
  end
81
78
 
82
- describe "#summary_lines" do
83
- it "returns the summary split into lines" do
84
- lines = ['This', 'is', 'summary', 'for', 'a', 'test']
79
+ describe '#summary_lines' do
80
+ it 'returns the summary split into lines' do
81
+ lines = %w(This is a summary for a test)
85
82
  allow(subject).to receive(:summary) { lines.join("\n") }
86
83
 
87
84
  expect(subject.summary_lines).to eq lines
88
85
  end
89
86
  end
90
-
91
87
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Test do
4
-
5
4
  it { is_expected.to respond_to :path }
6
5
  it { is_expected.to respond_to :run }
7
6
 
@@ -15,34 +14,34 @@ describe Daigaku::Test do
15
14
 
16
15
  subject { Daigaku::Test.new(unit_path) }
17
16
 
18
- it "has the appropriate path" do
17
+ it 'has the appropriate path' do
19
18
  expect(subject.path).to eq test_path
20
19
  end
21
20
 
22
- describe "#run" do
21
+ describe '#run' do
23
22
  before do
24
- course_name = course_dir_names.first
23
+ course_name = course_dir_names.first
25
24
  chapter_name = chapter_dir_names.first
26
- unit_name = unit_dir_names.first
25
+ unit_name = unit_dir_names.first
26
+
27
27
  @code = available_solution(course_name, chapter_name, unit_name).code
28
28
  end
29
29
 
30
- it "returns a Daigaku::TestResult" do
30
+ it 'returns a Daigaku::TestResult' do
31
31
  expect(subject.run(@code)).to be_a Daigaku::TestResult
32
32
  end
33
33
 
34
- context "when passing" do
35
- it "returns a passing result" do
34
+ context 'when passing' do
35
+ it 'returns a passing result' do
36
36
  expect(subject.run(@code).passed?).to be_truthy
37
37
  end
38
38
  end
39
39
 
40
- context "when failing" do
41
- it "returns a failing result" do
42
- code = "print 'BYE WORLD'"
40
+ context 'when failing' do
41
+ it 'returns a failing result' do
42
+ code = 'print "BYE WORLD"'
43
43
  expect(subject.run(code).passed?).to be_falsey
44
44
  end
45
45
  end
46
46
  end
47
-
48
47
  end