githug 0.4.2 → 0.4.3

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -0
  3. data/README.md +15 -18
  4. data/levels/fetch.rb +2 -2
  5. data/levels/push.rb +1 -1
  6. data/levels/push_branch.rb +1 -1
  7. data/levels/rebase.rb +16 -0
  8. data/levels/rebase/.githug/COMMIT_EDITMSG +1 -0
  9. data/levels/rebase/.githug/HEAD +1 -0
  10. data/levels/rebase/.githug/ORIG_HEAD +1 -0
  11. data/levels/rebase/.githug/config +7 -0
  12. data/levels/rebase/.githug/index +0 -0
  13. data/levels/rebase/.githug/logs/HEAD +13 -0
  14. data/levels/rebase/.githug/logs/refs/heads/feature +4 -0
  15. data/levels/rebase/.githug/logs/refs/heads/master +2 -0
  16. data/levels/rebase/.githug/objects/0c/d212c5b28da2e65ed4900712dd36c8adce48ad +0 -0
  17. data/levels/rebase/.githug/objects/44/19b972c0cd1b346ac90332aa7c5cc949589f78 +0 -0
  18. data/levels/rebase/.githug/objects/54/3b9bebdc6bd5c4b22136034a95dd097a57d3dd +0 -0
  19. data/levels/rebase/.githug/objects/81/78c76d627cade75005b40711b92f4177bc6cfc +0 -0
  20. data/levels/rebase/.githug/objects/98/205e9faf10cf33d2ef7c0f66e402540c62613a +2 -0
  21. data/levels/rebase/.githug/objects/a7/8bcab6232e9382a86436cdfcb2ed0391b1f0ac +4 -0
  22. data/levels/rebase/.githug/objects/b7/7313d7be366609dd2e77aa96d7fd73f4e27853 +0 -0
  23. data/levels/rebase/.githug/objects/b9/2d5d55d379cfb90b750e6472fc983f32ad9a71 +0 -0
  24. data/levels/rebase/.githug/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
  25. data/levels/rebase/.githug/objects/ed/0fdcf366b21b8984fb37ea34106978a2e5c5ba +0 -0
  26. data/levels/rebase/.githug/refs/heads/feature +1 -0
  27. data/levels/rebase/.githug/refs/heads/master +1 -0
  28. data/levels/rebase/README +1 -0
  29. data/levels/reorder.rb +1 -4
  30. data/levels/restructure.rb +1 -1
  31. data/lib/githug/cli.rb +30 -15
  32. data/lib/githug/level.rb +1 -1
  33. data/lib/githug/profile.rb +21 -12
  34. data/lib/githug/ui.rb +6 -12
  35. data/lib/githug/version.rb +1 -1
  36. data/spec/githug/cli_spec.rb +47 -46
  37. data/spec/githug/game_spec.rb +12 -12
  38. data/spec/githug/level_spec.rb +64 -93
  39. data/spec/githug/profile_spec.rb +34 -28
  40. data/spec/githug/repository_spec.rb +37 -38
  41. data/spec/githug/ui_spec.rb +51 -51
  42. data/spec/githug_spec.rb +60 -53
  43. data/spec/support/files/test_level.rb +16 -0
  44. metadata +26 -3
data/lib/githug/ui.rb CHANGED
@@ -1,29 +1,23 @@
1
1
  module Githug
2
2
  module UI
3
3
 
4
- @@out_stream = STDOUT
5
- @@in_stream = STDIN
6
-
7
4
  class << self
8
5
 
9
- def out_stream=(out)
10
- @@out_stream = out
11
- end
6
+ attr_accessor :out_stream, :in_stream
12
7
 
13
- def in_stream=(in_stream)
14
- @@in_stream = in_stream
15
- end
8
+ @out_stream = STDOUT
9
+ @in_stream = STDIN
16
10
 
17
11
  def puts(string = "")
18
- @@out_stream.puts(string)
12
+ out_stream.puts(string)
19
13
  end
20
14
 
21
15
  def print(string)
22
- @@out_stream.print(string)
16
+ out_stream.print(string)
23
17
  end
24
18
 
25
19
  def gets
26
- @@in_stream.gets
20
+ in_stream.gets
27
21
  end
28
22
 
29
23
  def word_box(string,width=80,char='*')
@@ -1,3 +1,3 @@
1
1
  module Githug
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -5,115 +5,116 @@ describe Githug::CLI do
5
5
 
6
6
  before(:each) do
7
7
  game = mock.as_null_object
8
- @cli = Githug::CLI.new
9
8
  Githug::Game.stub(:new).and_return(game)
10
9
  end
11
10
 
12
- it "should print the logo" do
11
+ it "prints the logo" do
13
12
  Githug::UI.should_receive(:word_box).with("Githug")
14
- @cli.stub(:make_directory)
15
- @cli.play
13
+ subject.stub(:make_directory!)
14
+ subject.play
16
15
  end
17
16
 
18
- it "should create a directory if one does not exist" do
17
+ it "creates a directory if one does not exist" do
19
18
  Githug::UI.stub(:ask).and_return(true)
20
19
  Dir.should_receive(:mkdir).with("./git_hug")
21
20
  Dir.should_receive(:chdir).with("git_hug")
22
- @cli.make_directory
21
+ subject.make_directory!
23
22
  end
24
23
 
25
- it "should not make a directory if you are in the game directory" do
24
+ it "does not create a directory if you are in the game directory" do
26
25
  Dir.stub(:pwd).and_return("/home/git_hug")
27
26
  Githug::UI.should_not_receive(:ask)
28
- @cli.make_directory
27
+ subject.make_directory!
29
28
  end
30
29
 
31
- it "should exit if the user selects no" do
30
+ it "exits if the user selects no" do
32
31
  Githug::UI.stub(:ask).and_return(false)
33
- lambda {@cli.make_directory}.should raise_error(SystemExit)
32
+ lambda {subject.prompt_githug_directory!}.should raise_error(SystemExit)
34
33
  end
35
34
 
36
- it "should prompt to change into the directory if it exists" do
35
+ it "prompts to change into the directory if it exists" do
37
36
  File.stub(:exists?).and_return(true)
38
37
  Githug::UI.should_receive(:puts).with("Please change into the git_hug directory")
39
- lambda {@cli.make_directory}.should raise_error(SystemExit)
38
+ lambda {subject.check_githug_directory!}.should raise_error(SystemExit)
40
39
  end
41
40
 
42
- describe "test" do
43
- it "should perform a test run of the level" do
41
+ describe "#test" do
42
+ it "performs a test run of the level" do
44
43
  level = mock
45
44
  game = mock
46
- @cli.stub(:make_directory)
45
+ subject.stub(:make_directory!)
47
46
  Githug::Level.should_receive(:load_from_file).with("/foo/bar/test/level.rb").and_return(level)
48
47
  Githug::Game.stub(:new).and_return(game)
49
48
  game.should_receive(:test_level).with(level, anything)
50
- @cli.test("/foo/bar/test/level.rb")
49
+ subject.test("/foo/bar/test/level.rb")
51
50
  end
52
51
  end
53
52
 
54
53
  describe "level methods" do
54
+
55
+ let(:level) { mock }
56
+ let(:profile) { mock }
57
+
55
58
  before(:each) do
56
- @level = mock
57
- @profile = mock
58
- @profile.stub(:level).and_return(1)
59
- Githug::Profile.stub(:load).and_return(@profile)
60
- Githug::Level.stub(:load).and_return(@level)
61
- Githug::Level.stub(:load_from_file).with("/foo/bar/level.rb").and_return(@level)
59
+ profile.stub(:level).and_return(1)
60
+ Githug::Profile.stub(:load).and_return(profile)
61
+ Githug::Level.stub(:load).and_return(level)
62
+ Githug::Level.stub(:load_from_file).with("/foo/bar/level.rb").and_return(level)
62
63
  end
63
64
 
64
- it "should call the hint method on the level" do
65
- @level.should_receive(:show_hint)
66
- @cli.hint
65
+ it "calls the hint method on the level" do
66
+ level.should_receive(:show_hint)
67
+ subject.hint
67
68
  end
68
69
 
69
- describe "reset" do
70
+ describe "#reset" do
70
71
 
71
72
 
72
- it "should reset the current level" do
73
- @level.should_receive(:setup_level)
74
- @level.should_receive(:full_description)
73
+ it "resets the current level" do
74
+ level.should_receive(:setup_level)
75
+ level.should_receive(:full_description)
75
76
  Githug::UI.should_receive(:word_box).with("Githug")
76
77
  Githug::UI.should_receive(:puts).with("resetting level")
77
- @cli.reset
78
+ subject.reset
78
79
  end
79
80
 
80
- it "should not reset if the level cannot be loaded" do
81
+ it "does not reset if the level cannot be loaded" do
81
82
  Githug::Level.stub(:load).and_return(false)
82
- @level.should_not_receive(:setup_level)
83
- @level.should_not_receive(:full_description)
83
+ level.should_not_receive(:setup_level)
84
+ level.should_not_receive(:full_description)
84
85
  Githug::UI.should_receive(:error).with("Level does not exist")
85
- @cli.reset
86
+ subject.reset
86
87
  end
87
88
 
88
- it "should reset the level with a level name" do
89
- @level.should_receive(:setup_level)
90
- @level.should_receive(:full_description)
89
+ it "resets the level with a level name" do
90
+ level.should_receive(:setup_level)
91
+ level.should_receive(:full_description)
91
92
  profile = mock
92
93
  Githug::Profile.stub(:load).and_return(profile)
93
94
  profile.should_receive(:set_level).with("add")
94
- Githug::Level.should_receive(:load).with("add").and_return(@level)
95
+ Githug::Level.should_receive(:load).with("add").and_return(level)
95
96
  Githug::UI.should_receive(:word_box).with("Githug")
96
97
  Githug::UI.should_receive(:puts).with("resetting level")
97
- @cli.reset("add")
98
+ subject.reset("add")
98
99
  end
99
100
 
100
- it "should reset the level with a path" do
101
- @level.should_receive(:setup_level)
102
- @level.should_receive(:full_description)
101
+ it "resets the level with a path" do
102
+ level.should_receive(:setup_level)
103
+ level.should_receive(:full_description)
103
104
  Githug::UI.should_receive(:word_box).with("Githug")
104
105
  Githug::UI.should_receive(:puts).with("resetting level")
105
- @cli.reset("/foo/bar/level.rb")
106
+ subject.reset("/foo/bar/level.rb")
106
107
  end
107
108
  end
108
109
 
109
110
  end
110
111
 
111
- describe "levels" do
112
+ describe "#levels" do
112
113
 
113
- it "should should print the levels and their numbers" do
114
+ it "prints the levels and their numbers" do
114
115
  Githug::Level.stub(:list).and_return(["commit", "add"])
115
116
  Githug::UI.should_receive(:puts).with(["#1: commit", "#2: add"])
116
- @cli.levels
117
+ subject.levels
117
118
  end
118
119
  end
119
120
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Githug::Game do
4
4
 
5
- let(:profile) { mock(:level => 1,
5
+ let(:profile) { mock(:level => 1,
6
6
  :current_attempts => 0).as_null_object }
7
7
  let(:game) { Githug::Game.new }
8
8
  let(:level) { mock(:full_description => nil, :setup_level => nil) }
@@ -17,11 +17,11 @@ describe Githug::Game do
17
17
  Githug::Level.stub(:load).and_return(level)
18
18
  end
19
19
 
20
- it "should have a profile" do
20
+ it "has a profile" do
21
21
  game.profile.should eql(profile)
22
22
  end
23
23
 
24
- it "should show a description if the level is 0" do
24
+ it "shows a description if the level is 0" do
25
25
  level.should_not_receive(:solve)
26
26
  profile.stub(:level).and_return(nil)
27
27
  profile.should_receive(:level_bump)
@@ -31,27 +31,27 @@ describe Githug::Game do
31
31
 
32
32
  describe "play_level" do
33
33
 
34
- it "should echo congratulations if the level is solved" do
34
+ it "outputs congratulations if the level is solved" do
35
35
  level.stub(:solve).and_return(true)
36
36
  profile.should_receive(:level_bump)
37
37
  Githug::UI.should_receive(:success).with("Congratulations, you have solved the level!")
38
38
  game.play_level
39
39
  end
40
40
 
41
- it "should echo the solution is not right" do
41
+ it "outputs a message if the solution is not right" do
42
42
  level.stub(:solve).and_return(false)
43
43
  Githug::UI.should_receive(:error).with("Sorry, this solution is not quite right!")
44
44
  game.play_level
45
45
  end
46
46
 
47
- it "should increment the number of failed attempts" do
47
+ it "increments the number of failed attempts" do
48
48
  level.stub(:solve).and_return(false)
49
49
  profile.should_receive(:current_attempts=).with(1)
50
50
  profile.should_receive(:save)
51
51
  game.play_level
52
52
  end
53
53
 
54
- it "should prompt for a hint if the user has failed 3 times." do
54
+ it "prompts for a hint if the user has failed 3 times." do
55
55
  profile.stub(:current_attempts).and_return(3)
56
56
  level.stub(:solve).and_return(false)
57
57
  Githug::UI.should_receive(:error).with("Sorry, this solution is not quite right!")
@@ -63,31 +63,31 @@ describe Githug::Game do
63
63
 
64
64
 
65
65
  describe "test_level" do
66
- it "Should output Valid solution if the solution is valid" do
66
+ it "outputs Valid solution if the solution is valid" do
67
67
  level.stub(:solve).and_return(true)
68
68
  Githug::UI.should_receive(:success).with("Valid solution")
69
69
  game.test_level(level)
70
70
  end
71
71
 
72
- it "Should output Invalid solution if the solution is invalid" do
72
+ it "outputs Invalid solution if the solution is invalid" do
73
73
  level.stub(:solve).and_return(false)
74
74
  Githug::UI.should_receive(:error).with("Invalid solution")
75
75
  game.test_level(level)
76
76
  end
77
77
 
78
- it "should call test when errors is true" do
78
+ it "calls test when errors is true" do
79
79
  level.should_receive(:test)
80
80
  game.test_level(level, true)
81
81
  end
82
82
  end
83
83
 
84
- it "should output the description of the next level" do
84
+ it "outputs the description of the next level" do
85
85
  level.should_receive(:full_description)
86
86
  profile.stub(:level=)
87
87
  game.level_bump
88
88
  end
89
89
 
90
- it "should call setup_level for the next level" do
90
+ it "calls setup_level for the next level" do
91
91
  level.should_receive(:setup_level)
92
92
  profile.stub(:level=)
93
93
  game.level_bump
@@ -3,31 +3,11 @@ require 'grit'
3
3
 
4
4
  describe Githug::Level do
5
5
 
6
- before(:each) do
7
- @file = <<-eof
8
- difficulty 1
9
- description "A test description"
10
- setup do
11
- "test"
12
- end
13
- solution do
14
- Grit::Repo.new("githug/notadir")
15
- end
6
+ let(:subject) { Githug::Level.load_from_file(File.expand_path("spec/support/files/test_level.rb")) }
7
+ let(:repo) { mock(:reset) }
16
8
 
17
- hints [
18
- "this is hint 1",
19
- "this is hint 2"]
20
-
21
- hint do
22
- puts "this is a hint"
23
- end
24
- eof
25
- File.stub(:exists?).and_return(true)
26
- File.stub(:read).and_return(@file)
27
- @level = Githug::Level.load("init")
28
- @repo = mock
29
- @repo.stub(:reset)
30
- Githug::Repository.stub(:new).and_return(@repo)
9
+ before(:each) do
10
+ Githug::Repository.stub(:new).and_return(repo)
31
11
  Githug::UI.stub(:puts)
32
12
  Githug::UI.stub(:print)
33
13
  end
@@ -36,48 +16,42 @@ end
36
16
  Githug::Level.ancestors.should include(Githug::UI)
37
17
  end
38
18
 
19
+ describe ".load" do
39
20
 
40
- describe "load" do
41
-
42
- it "should load the level" do
21
+ it "loads the level" do
43
22
  File.stub(:dirname).and_return("")
44
- File.should_receive(:read).with('/../../levels/init.rb').and_return(@file)
45
- level = Githug::Level.load("init")
46
- level.instance_variable_get("@difficulty").should eql(1)
47
- level.instance_variable_get("@description").should eql("A test description")
23
+ Githug::Level.should_receive(:setup).with("/../../levels/init.rb")
24
+ Githug::Level.load("init")
48
25
  end
49
26
 
50
- it "should return false if the level does not exist" do
27
+ it "returns false if the level does not exist" do
51
28
  File.stub(:exists?).and_return(false)
52
29
  Githug::Level.load(1).should eql(false)
53
30
  end
54
31
 
55
32
  end
56
33
 
57
- describe "list" do
58
- it "should list the levels without nil" do
34
+ describe ".list" do
35
+ it "lists the levels without nil" do
59
36
  Githug::Level.list.should eql(Githug::Level::LEVELS - [nil])
60
37
  end
61
38
  end
62
39
 
63
- describe "load_from_file" do
64
- it "should load the level" do
65
- File.stub(:dirname).and_return("")
66
- File.should_receive(:read).with('/foo/bar/test/level.rb').and_return(@file)
67
- level = Githug::Level.load_from_file("/foo/bar/test/level.rb")
68
- level.instance_variable_get("@difficulty").should eql(1)
69
- level.instance_variable_get("@description").should eql("A test description")
40
+ describe ".load_from_file" do
41
+ it "loads the level" do
42
+ subject.instance_variable_get("@difficulty").should eql(1)
43
+ subject.instance_variable_get("@description").should eql("A test description")
70
44
  end
71
45
 
72
- it "should return false if the level does not exist" do
46
+ it "return false if the level does not exist" do
73
47
  File.stub(:exists?).and_return(false)
74
48
  Githug::Level.load_from_file("/foo/bar/test/level.rb").should eql(false)
75
49
  end
76
50
  end
77
51
 
78
- describe "setup" do
52
+ describe ".setup" do
79
53
 
80
- it "should return false if the level does not exist" do
54
+ it "returns false if the level does not exist" do
81
55
  File.stub(:exists?).and_return(false)
82
56
  Githug::Level.setup("/foo/bar/test/level.rb").should eql(false)
83
57
  end
@@ -85,104 +59,101 @@ end
85
59
  end
86
60
 
87
61
 
88
- describe "solve" do
62
+ describe "#solve" do
89
63
 
90
- it "should solve the problem" do
91
- @level.solve.should eql(false)
64
+ it "returns false if the level requirements have not been met" do
65
+ subject.solve.should eql(false)
92
66
  end
93
67
 
94
- it "should return true if the requirements have been met" do
68
+ it "returns true if the level requirements have been met" do
95
69
  Grit::Repo.stub(:new).and_return(true)
96
- @level.solve.should eql(true)
70
+ subject.solve.should eql(true)
97
71
  end
98
72
 
99
73
  end
100
74
 
101
- describe "test" do
102
- it "should call solve" do
103
- @level.should_receive(:_solution)
104
- @level.test
75
+ describe "#test" do
76
+ it "calls solve" do
77
+ subject.should_receive(:_solution)
78
+ subject.test
105
79
  end
106
80
  end
107
81
 
108
82
 
109
- describe "full_description" do
83
+ describe "#full_description" do
110
84
 
111
- it "should display a full description" do
85
+ it "displays a full description" do
112
86
  Githug::UI.stub(:puts)
113
87
  Githug::UI.should_receive(:puts).with("Level: 1")
114
88
  Githug::UI.should_receive(:puts).with("Difficulty: *")
115
89
  Githug::UI.should_receive(:puts).with("A test description")
116
- @level.full_description
90
+ subject.full_description
117
91
  end
118
92
 
119
93
  end
120
94
 
121
- describe "setup" do
95
+ describe "#setup" do
122
96
 
123
- it "should call setup" do
124
- @level.setup_level.should eql("test")
97
+ it "calls setup" do
98
+ repo.should_receive(:reset)
99
+ subject.setup_level.should eql("test")
125
100
  end
126
101
 
127
- it "should not call the setup if none exists" do
128
- @level.instance_variable_set("@setup", nil)
129
- lambda {@level.setup_level}.should_not raise_error(NoMethodError)
102
+ it "does not call the setup if none exists" do
103
+ subject.instance_variable_set("@setup", nil)
104
+ lambda {subject.setup_level}.should_not raise_error(NoMethodError)
130
105
  end
131
106
 
132
107
  end
133
108
 
134
109
 
135
- describe "repo" do
110
+ describe "#repo" do
136
111
 
137
- it "should initialize a repository when repo is called" do
138
- @level.repo.should equal(@repo)
112
+ it "initializes a repository when repo is called" do
113
+ subject.repo.should equal(repo)
139
114
  Githug::Repository.should_not_receive(:new)
140
- @level.repo.should equal(@repo)
141
- end
142
-
143
- it "should call reset on setup_level" do
144
- @repo.should_receive(:reset)
145
- @level.setup_level
115
+ subject.repo.should equal(repo)
146
116
  end
147
117
 
148
118
  end
149
119
 
150
- describe "hint" do
120
+ describe "#hint" do
121
+
122
+ let(:profile) { mock.as_null_object }
151
123
 
152
124
  before(:each) do
153
- @profile = mock.as_null_object
154
- Githug::Profile.stub(:load).and_return(@profile)
155
- @profile.stub(:current_hint_index).and_return(0,0,1,0)
125
+ profile.stub(:current_hint_index).and_return(0,0,1,0)
126
+ Githug::Profile.stub(:load).and_return(profile)
156
127
  end
157
128
 
158
- it "should return sequential hint if there are multiple" do
159
- @level.should_receive(:puts).ordered.with("this is hint 1")
160
- @level.show_hint
129
+ it "returns sequential hint if there are multiple" do
130
+ subject.should_receive(:puts).ordered.with("this is hint 1")
131
+ subject.show_hint
161
132
 
162
- @level.should_receive(:puts).ordered.with("this is hint 2")
163
- @level.show_hint
133
+ subject.should_receive(:puts).ordered.with("this is hint 2")
134
+ subject.show_hint
164
135
 
165
- @level.should_receive(:puts).ordered.with("this is hint 1")
166
- @level.show_hint
136
+ subject.should_receive(:puts).ordered.with("this is hint 1")
137
+ subject.show_hint
167
138
  end
168
139
 
169
- it "should display a hint if there are not multiple" do
170
- @level.instance_variable_set("@hints", nil)
171
- @level.should_receive(:puts).with("this is a hint")
172
- @level.show_hint
140
+ it "displays a hint if there are not multiple" do
141
+ subject.instance_variable_set("@hints", nil)
142
+ subject.should_receive(:puts).with("this is a hint")
143
+ subject.show_hint
173
144
  end
174
145
 
175
- it "should not call the hint if none exist" do
176
- @level.instance_variable_set("@hint", nil)
177
- lambda {@level.show_hint}.should_not raise_error(NoMethodError)
146
+ it "does not call the hint if none exist" do
147
+ subject.instance_variable_set("@hint", nil)
148
+ lambda {subject.show_hint}.should_not raise_error(NoMethodError)
178
149
  end
179
150
  end
180
151
 
181
- describe "init_from_level" do
182
- it "should copy the files from the level folder" do
183
- FileUtils.should_receive(:cp_r).with("#{@level.level_path}/.", ".")
152
+ describe "#init_from_level" do
153
+ it "copies the files from the level folder" do
154
+ FileUtils.should_receive(:cp_r).with("#{subject.level_path}/.", ".")
184
155
  FileUtils.should_receive(:mv).with(".githug", ".git")
185
- @level.init_from_level
156
+ subject.init_from_level
186
157
  end
187
158
  end
188
159
  end