daigaku 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -3
  3. data/README.md +1 -1
  4. data/daigaku.gemspec +23 -26
  5. data/lib/daigaku.rb +0 -1
  6. data/lib/daigaku/chapter.rb +3 -4
  7. data/lib/daigaku/coloring.rb +13 -13
  8. data/lib/daigaku/configuration.rb +25 -28
  9. data/lib/daigaku/congratulator.rb +17 -5
  10. data/lib/daigaku/course.rb +9 -8
  11. data/lib/daigaku/exceptions.rb +0 -2
  12. data/lib/daigaku/generator.rb +13 -13
  13. data/lib/daigaku/github_client.rb +4 -4
  14. data/lib/daigaku/loadable.rb +11 -15
  15. data/lib/daigaku/loading/chapters.rb +0 -2
  16. data/lib/daigaku/loading/courses.rb +0 -2
  17. data/lib/daigaku/loading/units.rb +0 -2
  18. data/lib/daigaku/markdown.rb +1 -0
  19. data/lib/daigaku/markdown/printer.rb +89 -0
  20. data/lib/daigaku/markdown/ruby_doc.rb +6 -8
  21. data/lib/daigaku/solution.rb +18 -15
  22. data/lib/daigaku/storeable.rb +11 -12
  23. data/lib/daigaku/task.rb +1 -1
  24. data/lib/daigaku/terminal.rb +3 -4
  25. data/lib/daigaku/terminal/cli.rb +6 -8
  26. data/lib/daigaku/terminal/courses.rb +19 -16
  27. data/lib/daigaku/terminal/output.rb +0 -2
  28. data/lib/daigaku/terminal/setup.rb +13 -18
  29. data/lib/daigaku/terminal/solutions.rb +27 -32
  30. data/lib/daigaku/terminal/welcome.rb +9 -11
  31. data/lib/daigaku/test.rb +7 -10
  32. data/lib/daigaku/test_result.rb +13 -16
  33. data/lib/daigaku/unit.rb +1 -3
  34. data/lib/daigaku/version.rb +1 -1
  35. data/lib/daigaku/views.rb +4 -3
  36. data/lib/daigaku/views/chapters_menu.rb +16 -20
  37. data/lib/daigaku/views/courses_menu.rb +12 -15
  38. data/lib/daigaku/views/main_menu.rb +23 -23
  39. data/lib/daigaku/views/menu.rb +9 -13
  40. data/lib/daigaku/views/splash.rb +11 -13
  41. data/lib/daigaku/views/subscriber.rb +38 -0
  42. data/lib/daigaku/views/task_view.rb +80 -78
  43. data/lib/daigaku/views/top_bar.rb +4 -10
  44. data/lib/daigaku/views/units_menu.rb +16 -21
  45. data/lib/daigaku/window.rb +12 -70
  46. data/spec/daigaku/chapter_spec.rb +23 -18
  47. data/spec/daigaku/coloring_spec.rb +0 -1
  48. data/spec/daigaku/configuration_spec.rb +54 -50
  49. data/spec/daigaku/congratulator_spec.rb +11 -8
  50. data/spec/daigaku/course_spec.rb +70 -51
  51. data/spec/daigaku/generator_spec.rb +24 -25
  52. data/spec/daigaku/github_client_spec.rb +17 -18
  53. data/spec/daigaku/loading/chapters_spec.rb +2 -3
  54. data/spec/daigaku/loading/courses_spec.rb +2 -3
  55. data/spec/daigaku/loading/units_spec.rb +4 -5
  56. data/spec/daigaku/markdown/ruby_doc_spec.rb +3 -6
  57. data/spec/daigaku/reference_solution_spec.rb +8 -10
  58. data/spec/daigaku/solution_spec.rb +18 -20
  59. data/spec/daigaku/storeable_spec.rb +12 -10
  60. data/spec/daigaku/task_spec.rb +3 -4
  61. data/spec/daigaku/terminal/cli_spec.rb +29 -21
  62. data/spec/daigaku/terminal/courses_spec.rb +104 -99
  63. data/spec/daigaku/terminal/output_spec.rb +44 -39
  64. data/spec/daigaku/terminal/setup_spec.rb +1 -3
  65. data/spec/daigaku/terminal/solutions_spec.rb +0 -2
  66. data/spec/daigaku/terminal/welcome_spec.rb +0 -2
  67. data/spec/daigaku/terminal_spec.rb +5 -7
  68. data/spec/daigaku/test_example_spec.rb +16 -14
  69. data/spec/daigaku/test_result_spec.rb +21 -25
  70. data/spec/daigaku/test_spec.rb +11 -12
  71. data/spec/daigaku/unit_spec.rb +24 -27
  72. data/spec/daigaku/views/chapters_menu_spec.rb +0 -1
  73. data/spec/daigaku/views/courses_menu_spec.rb +0 -1
  74. data/spec/daigaku/views/menu_spec.rb +1 -2
  75. data/spec/daigaku/views/task_view_spec.rb +0 -2
  76. data/spec/daigaku/views/units_menu_spec.rb +0 -1
  77. data/spec/daigaku/views_spec.rb +0 -1
  78. data/spec/daigaku_spec.rb +9 -12
  79. data/spec/path_helpers_spec.rb +11 -12
  80. data/spec/resource_helpers_spec.rb +11 -12
  81. data/spec/spec_helper.rb +3 -4
  82. data/spec/support/macros/content_helpers.rb +16 -17
  83. data/spec/support/macros/mock_helpers.rb +6 -6
  84. data/spec/support/macros/path_helpers.rb +15 -15
  85. data/spec/support/macros/resource_helpers.rb +34 -35
  86. metadata +12 -10
@@ -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) { 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 { Daigaku::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 Daigaku::Task" do
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 "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 Daigaku::ReferenceSolution" do
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 "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 Daigaku::Solution" do
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 "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(Daigaku::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 Daigaku::Views::ChaptersMenu, type: :view do
4
-
5
4
  it { is_expected.to be_a Daigaku::Views::Menu }
6
5
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Views::CoursesMenu, type: :view do
4
-
5
4
  it { is_expected.to be_a Daigaku::Views::Menu }
6
5
  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
@@ -1,7 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::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 Daigaku::Views::UnitsMenu, type: :view do
4
-
5
4
  it { is_expected.to be_a Daigaku::Views::Menu }
6
5
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Views do
4
-
5
4
  subject do
6
5
  class Test
7
6
  include Daigaku::Views
data/spec/daigaku_spec.rb CHANGED
@@ -1,28 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Daigaku module" do
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 ::#{method}" do
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 "returns Configuration of class Daigaku::Configuration" do
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 "returns a singleton setting" do
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 "::configure" do
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 "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(Daigaku.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
  Daigaku.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
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.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/daigaku', __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