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,85 +1,82 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Belajar::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) { course_dir_names.first }
10
+ let(:course_name) { course_dir_names.first }
12
11
  let(:chapter_name) { chapter_dir_names.first }
13
- let(:unit_name) { unit_dir_names.first }
12
+ let(:unit_name) { unit_dir_names.first }
14
13
 
15
14
  subject { Belajar::Unit.new(unit_dirs(course_name).first[0]) }
16
15
 
17
- it "has the prescribed title" do
16
+ it 'has the prescribed title' do
18
17
  expect(subject.title).to eq unit_titles.first
19
18
  end
20
19
 
21
- describe "#task" do
22
- it "returns an object of type Belajar::Task" do
20
+ describe '#task' do
21
+ it 'returns an object of type Belajar::Task' do
23
22
  expect(subject.task).to be_a Belajar::Task
24
23
  end
25
24
 
26
- it "returns the unit's appropriate task" do
25
+ it 'returns the units 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 "lazy-loads the task" do
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 "#reference_solution" do
39
- it "returns an object of type Belajar::ReferenceSolution" do
37
+ describe '#reference_solution' do
38
+ it 'returns an object of type Belajar::ReferenceSolution' do
40
39
  expect(subject.reference_solution).to be_a Belajar::ReferenceSolution
41
40
  end
42
41
 
43
- it "returns the units appropriate predefined reference solution" do
44
- reference_solution = available_reference_solution(course_name,
45
- chapter_name,
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 "lazy-loads the reference solution" do
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 "#solution" do
58
- it "returns an object of type Belajar::Solution" do
55
+ describe '#solution' do
56
+ it 'returns an object of type Belajar::Solution' do
59
57
  expect(subject.solution).to be_a Belajar::Solution
60
58
  end
61
59
 
62
- it "returns the units appropriate solution provided by the user" do
63
- expect(subject.solution.code).to eq available_solution(course_name,
64
- chapter_name,
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 "lazy-loads the reference solution" do
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 "#mastered?" do
76
- it "returns false by default" do
77
- expect(subject.mastered?).to be_falsey
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 "returns true if the solution has been verified" do
77
+ it 'returns true if the solution has been verified' do
81
78
  allow_any_instance_of(Belajar::Solution).to receive(:verified?) { true }
82
- expect(subject.mastered?).to be_truthy
79
+ expect(subject.mastered?).to be true
83
80
  end
84
81
  end
85
82
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Belajar::Views::ChaptersMenu, type: :view do
4
-
5
4
  it { is_expected.to be_a Belajar::Views::Menu }
6
5
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Belajar::Views::CoursesMenu, type: :view do
4
-
5
4
  it { is_expected.to be_a Belajar::Views::Menu }
6
5
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Belajar::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 Belajar::Views::Menu do
16
15
  expect(subject.protected_methods).to include(method)
17
16
  end
18
17
  end
19
- end
18
+ end
@@ -1,7 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Belajar::Views::TaskView, type: :view do
4
-
5
4
  it { is_expected.to respond_to :enter }
6
-
7
5
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Belajar::Views::UnitsMenu, type: :view do
4
-
5
4
  it { is_expected.to be_a Belajar::Views::Menu }
6
5
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Belajar::Views do
4
-
5
4
  subject do
6
5
  class Test
7
6
  include Belajar::Views
@@ -1,28 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Belajar module" do
4
-
5
- describe "::config" do
6
-
3
+ describe 'Belajar module' do
4
+ describe '.config' do
7
5
  subject { Belajar.config }
8
6
 
9
7
  [:config, :configure, :start].each do |method|
10
- it "responds to ::#{method}" do
8
+ it "responds to .#{method}" do
11
9
  expect(Belajar.singleton_methods).to include method
12
10
  end
13
11
  end
14
12
 
15
- it "returns Configuration of class Belajar::Configuration" do
13
+ it 'returns Configuration of class Belajar::Configuration' do
16
14
  expect(subject).to be_an_instance_of Belajar::Configuration
17
15
  end
18
16
 
19
- it "returns a singleton setting" do
17
+ it 'returns a singleton setting' do
20
18
  expect(subject).to be Belajar.config
21
19
  end
22
20
  end
23
21
 
24
- describe "::configure" do
25
-
22
+ describe '.configure' do
26
23
  let(:configure) do
27
24
  proc do
28
25
  Belajar.configure do |config|
@@ -31,16 +28,16 @@ describe "Belajar module" do
31
28
  end
32
29
  end
33
30
 
34
- it "allows to configure the app" do
31
+ it 'allows to configure the app' do
35
32
  expect { configure.call }.not_to raise_error
36
33
  end
37
34
 
38
- it "sets configutation properties" do
35
+ it 'sets configuration properties' do
39
36
  configure.call
40
37
  expect(Belajar.config.solutions_path).to eq test_basepath
41
38
  end
42
39
 
43
- it "allows to change the config during runtime" do
40
+ it 'allows to change the config during runtime' do
44
41
  Belajar.configure do |config|
45
42
  config.solutions_path = courses_basepath
46
43
  end
@@ -1,28 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "PathHelpers" do
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 "provides a test base path" do
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 "provides a courses base path" do
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 "provides the course directories" do
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 "provides each course's chapter directories" do
24
+ it 'provides each courses 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 "provides each chapter's unit directories" do
32
+ it 'provides each chapters 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 "provides all unit directories as flattened array" do
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 "provides all solution file paths" do
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 "provides all test file paths" do
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 "provides the local_storage_file path" do
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 "ResourceHelpers" do
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 "provides the available courses" do
8
+ it 'provides the available courses' do
10
9
  puts "\n* available courses:"
11
- puts available_courses.map &:inspect
10
+ puts available_courses.map(&:inspect)
12
11
  end
13
12
 
14
- it "provides a course's available chapters" do
13
+ it 'provides a courses available chapters' do
15
14
  puts "\n* available chapters:"
16
- puts available_chapters(course).map &:inspect
15
+ puts available_chapters(course).map(&:inspect)
17
16
  end
18
17
 
19
- it "provides a chapter's avaliable units" do
18
+ it 'provides a chapters avaliable units' do
20
19
  puts "\n* available units:"
21
- puts available_units(course, chapter).map &:inspect
20
+ puts available_units(course, chapter).map(&:inspect)
22
21
  end
23
22
 
24
- it "provides a unit's task file" do
23
+ it 'provides a units task file' do
25
24
  puts "\n* task:"
26
- puts available_task(course, chapter, unit).map &:inspect
25
+ puts available_task(course, chapter, unit).map(&:inspect)
27
26
  end
28
27
 
29
- it "provides a unit's reference solution file" do
28
+ it 'provides a units reference solution file' do
30
29
  puts "\n* reference solution:"
31
- puts available_reference_solution(course, chapter, unit).map &:inspect
30
+ puts available_reference_solution(course, chapter, unit).map(&:inspect)
32
31
  end
33
32
  end
@@ -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.each do |file|
7
- require file
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/belajar', __FILE__)
16
- require_files_from ["../support/**/"]
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======", "##Task",
5
- "Solve this task!",
6
- "##Hints",
7
- "Just do it right..."
8
- ].join("\n\n")
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
- " end",
24
- "end"
25
- ].join("\n")
23
+ ' end',
24
+ 'end'
25
+ ].join("\n").freeze
26
26
 
27
27
  TEST_FAILED_JSON =
28
- %Q#
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
- %Q#
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 = "Your code passed all tests."
91
- EXAMPLE_PASSED_MESSAGE = "Your code passed this requirement."
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
- allow($stdout).to receive(:puts) {}
23
- allow($stdout).to receive(:print) {}
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