belajar 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -4
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/Gemfile +1 -1
  5. data/README.md +76 -1
  6. data/Rakefile +1 -1
  7. data/belajar.gemspec +23 -26
  8. data/belajar.png +0 -0
  9. data/bin/belajar +6 -2
  10. data/lib/belajar.rb +0 -1
  11. data/lib/belajar/chapter.rb +3 -4
  12. data/lib/belajar/coloring.rb +32 -0
  13. data/lib/belajar/configuration.rb +25 -28
  14. data/lib/belajar/congratulator.rb +17 -5
  15. data/lib/belajar/course.rb +9 -8
  16. data/lib/belajar/exceptions.rb +0 -2
  17. data/lib/belajar/generator.rb +13 -15
  18. data/lib/belajar/github_client.rb +5 -5
  19. data/lib/belajar/loadable.rb +23 -14
  20. data/lib/belajar/loading/chapters.rb +0 -2
  21. data/lib/belajar/loading/courses.rb +0 -2
  22. data/lib/belajar/loading/units.rb +0 -2
  23. data/lib/belajar/markdown.rb +2 -0
  24. data/lib/belajar/markdown/printer.rb +89 -0
  25. data/lib/belajar/markdown/ruby_doc.rb +104 -0
  26. data/lib/belajar/solution.rb +23 -15
  27. data/lib/belajar/storeable.rb +11 -12
  28. data/lib/belajar/task.rb +1 -1
  29. data/lib/belajar/terminal.rb +3 -4
  30. data/lib/belajar/terminal/cli.rb +8 -8
  31. data/lib/belajar/terminal/courses.rb +24 -21
  32. data/lib/belajar/terminal/output.rb +46 -53
  33. data/lib/belajar/terminal/setup.rb +13 -18
  34. data/lib/belajar/terminal/solutions.rb +27 -32
  35. data/lib/belajar/terminal/texts/hint_course_download.txt +2 -2
  36. data/lib/belajar/terminal/welcome.rb +9 -11
  37. data/lib/belajar/test.rb +7 -10
  38. data/lib/belajar/test_result.rb +54 -21
  39. data/lib/belajar/unit.rb +2 -4
  40. data/lib/belajar/version.rb +1 -1
  41. data/lib/belajar/views.rb +29 -33
  42. data/lib/belajar/views/chapters_menu.rb +16 -20
  43. data/lib/belajar/views/courses_menu.rb +12 -15
  44. data/lib/belajar/views/main_menu.rb +23 -23
  45. data/lib/belajar/views/menu.rb +14 -18
  46. data/lib/belajar/views/splash.rb +11 -13
  47. data/lib/belajar/views/subscriber.rb +38 -0
  48. data/lib/belajar/views/task_view.rb +97 -80
  49. data/lib/belajar/views/top_bar.rb +4 -10
  50. data/lib/belajar/views/units_menu.rb +16 -21
  51. data/lib/belajar/window.rb +20 -140
  52. data/spec/belajar/chapter_spec.rb +23 -18
  53. data/spec/belajar/coloring_spec.rb +35 -0
  54. data/spec/belajar/configuration_spec.rb +55 -51
  55. data/spec/belajar/congratulator_spec.rb +11 -8
  56. data/spec/belajar/course_spec.rb +75 -52
  57. data/spec/belajar/generator_spec.rb +24 -25
  58. data/spec/belajar/github_client_spec.rb +17 -18
  59. data/spec/belajar/loading/chapters_spec.rb +2 -3
  60. data/spec/belajar/loading/courses_spec.rb +2 -3
  61. data/spec/belajar/loading/units_spec.rb +4 -5
  62. data/spec/belajar/markdown/ruby_doc_spec.rb +116 -0
  63. data/spec/belajar/reference_solution_spec.rb +8 -10
  64. data/spec/belajar/solution_spec.rb +21 -22
  65. data/spec/belajar/storeable_spec.rb +12 -10
  66. data/spec/belajar/task_spec.rb +3 -4
  67. data/spec/belajar/terminal/cli_spec.rb +29 -21
  68. data/spec/belajar/terminal/courses_spec.rb +104 -99
  69. data/spec/belajar/terminal/output_spec.rb +44 -39
  70. data/spec/belajar/terminal/setup_spec.rb +1 -3
  71. data/spec/belajar/terminal/solutions_spec.rb +0 -2
  72. data/spec/belajar/terminal/welcome_spec.rb +0 -2
  73. data/spec/belajar/terminal_spec.rb +5 -7
  74. data/spec/belajar/test_example_spec.rb +16 -14
  75. data/spec/belajar/test_result_spec.rb +21 -25
  76. data/spec/belajar/test_spec.rb +11 -12
  77. data/spec/belajar/unit_spec.rb +24 -27
  78. data/spec/belajar/views/chapters_menu_spec.rb +0 -1
  79. data/spec/belajar/views/courses_menu_spec.rb +0 -1
  80. data/spec/belajar/views/menu_spec.rb +1 -2
  81. data/spec/belajar/views/task_view_spec.rb +0 -2
  82. data/spec/belajar/views/units_menu_spec.rb +0 -1
  83. data/spec/belajar/views_spec.rb +0 -1
  84. data/spec/belajar_spec.rb +9 -12
  85. data/spec/path_helpers_spec.rb +11 -12
  86. data/spec/resource_helpers_spec.rb +11 -12
  87. data/spec/spec_helper.rb +3 -4
  88. data/spec/support/macros/content_helpers.rb +16 -17
  89. data/spec/support/macros/mock_helpers.rb +6 -6
  90. data/spec/support/macros/path_helpers.rb +15 -15
  91. data/spec/support/macros/resource_helpers.rb +34 -35
  92. metadata +56 -75
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Belajar::Terminal::Output do
4
-
5
4
  subject do
6
5
  require 'thor'
7
6
  class Test < Thor
@@ -30,61 +29,64 @@ describe Belajar::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 Belajar::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 Belajar::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 Belajar::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 Belajar::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 Belajar::Terminal::Welcome do
4
-
5
4
  [:run, :about].each do |method|
6
5
  it "has the singleton method ::#{method}" do
7
6
  singleton_methods = Belajar::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 Belajar::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 = Belajar::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 = Belajar::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(Belajar::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 Belajar::TestExample do
4
+ subject { Belajar::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 { Belajar::TestExample.new(description: description, status: status) }
14
+ subject do
15
+ Belajar::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 Belajar::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 Belajar::TestResult do
4
-
5
4
  subject { Belajar::TestResult.new(test_passed_json) }
6
5
 
7
6
  it { is_expected.to respond_to :example_count }
@@ -11,55 +10,53 @@ describe Belajar::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 { Belajar::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 { Belajar::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 Belajar::TestExample" do
48
+ it 'returns examples of type Belajar::TestExample' do
52
49
  subject.examples.each do |example|
53
50
  expect(example).to be_a Belajar::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 Belajar::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 Belajar::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 Belajar::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 Belajar::Test do
15
14
 
16
15
  subject { Belajar::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 Belajar::TestResult" do
30
+ it 'returns a Belajar::TestResult' do
31
31
  expect(subject.run(@code)).to be_a Belajar::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