gitscrub 0.0.2 → 0.0.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.
- data/levels/2.rb +8 -0
- data/lib/gitscrub/cli.rb +2 -1
- data/lib/gitscrub/game.rb +16 -3
- data/lib/gitscrub/level.rb +1 -1
- data/lib/gitscrub/ui.rb +1 -1
- data/lib/gitscrub/version.rb +1 -1
- data/spec/gitscrub/cli_spec.rb +1 -0
- data/spec/gitscrub/game_spec.rb +9 -0
- data/spec/gitscrub/level_spec.rb +6 -0
- data/spec/gitscrub/ui_spec.rb +5 -0
- metadata +2 -1
data/levels/2.rb
ADDED
data/lib/gitscrub/cli.rb
CHANGED
|
@@ -31,8 +31,9 @@ module Gitscrub
|
|
|
31
31
|
|
|
32
32
|
def make_directory
|
|
33
33
|
unless File.exists?("./git_scrub") || Dir.pwd.split("/").last == "git_scrub"
|
|
34
|
-
if UI.ask("No
|
|
34
|
+
if UI.ask("No gitscrub directory found, do you wish to create one?")
|
|
35
35
|
Dir.mkdir("./git_scrub")
|
|
36
|
+
Dir.chdir("git_scrub")
|
|
36
37
|
else
|
|
37
38
|
UI.puts("Exiting")
|
|
38
39
|
exit
|
data/lib/gitscrub/game.rb
CHANGED
|
@@ -11,20 +11,33 @@ module Gitscrub
|
|
|
11
11
|
solve = true
|
|
12
12
|
if profile.level == 0
|
|
13
13
|
UI.puts("Welcome to Gitscrub")
|
|
14
|
-
profile.level = 1
|
|
15
|
-
profile.save
|
|
16
14
|
solve = false
|
|
15
|
+
level_bump
|
|
17
16
|
else
|
|
18
17
|
level = Level.load(profile.level)
|
|
19
|
-
if solve
|
|
18
|
+
if solve && level
|
|
20
19
|
if level.solve
|
|
21
20
|
UI.puts "Congratulations, you have solved the level"
|
|
21
|
+
level_bump
|
|
22
22
|
else
|
|
23
23
|
UI.puts "Sorry, this solution is not quite right!"
|
|
24
|
+
UI.puts
|
|
25
|
+
UI.puts level.ldescription
|
|
26
|
+
UI.puts
|
|
24
27
|
end
|
|
25
28
|
end
|
|
26
29
|
end
|
|
27
30
|
end
|
|
28
31
|
|
|
32
|
+
def level_bump
|
|
33
|
+
profile.level += 1
|
|
34
|
+
profile.save
|
|
35
|
+
if level = Level.load(profile.level)
|
|
36
|
+
UI.puts
|
|
37
|
+
UI.puts(level.ldescription)
|
|
38
|
+
UI.puts
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
29
42
|
end
|
|
30
43
|
end
|
data/lib/gitscrub/level.rb
CHANGED
|
@@ -8,6 +8,7 @@ module Gitscrub
|
|
|
8
8
|
def load(level_no)
|
|
9
9
|
level = new
|
|
10
10
|
location = "#{File.dirname(__FILE__)}/../../levels/#{level_no}.rb"
|
|
11
|
+
return false unless File.exists?(location)
|
|
11
12
|
level.instance_eval(File.read(location))
|
|
12
13
|
level
|
|
13
14
|
end
|
|
@@ -28,7 +29,6 @@ module Gitscrub
|
|
|
28
29
|
|
|
29
30
|
def solve
|
|
30
31
|
lsolution.call
|
|
31
|
-
true
|
|
32
32
|
rescue
|
|
33
33
|
false
|
|
34
34
|
end
|
data/lib/gitscrub/ui.rb
CHANGED
data/lib/gitscrub/version.rb
CHANGED
data/spec/gitscrub/cli_spec.rb
CHANGED
data/spec/gitscrub/game_spec.rb
CHANGED
|
@@ -9,6 +9,7 @@ describe Gitscrub::Game do
|
|
|
9
9
|
@profile.stub(:level).and_return(1)
|
|
10
10
|
@profile.stub(:save)
|
|
11
11
|
@level = mock
|
|
12
|
+
@level.stub(:ldescription)
|
|
12
13
|
Gitscrub::UI.stub(:puts)
|
|
13
14
|
Gitscrub::Level.stub(:load).and_return(@level)
|
|
14
15
|
end
|
|
@@ -28,6 +29,7 @@ describe Gitscrub::Game do
|
|
|
28
29
|
|
|
29
30
|
it "should echo congratulations if the level is solved" do
|
|
30
31
|
@level.stub(:solve).and_return(true)
|
|
32
|
+
@profile.should_receive(:level=).with(2)
|
|
31
33
|
Gitscrub::UI.should_receive(:puts).with("Congratulations, you have solved the level")
|
|
32
34
|
@game.play_level
|
|
33
35
|
end
|
|
@@ -37,5 +39,12 @@ describe Gitscrub::Game do
|
|
|
37
39
|
Gitscrub::UI.should_receive(:puts).with("Sorry, this solution is not quite right!")
|
|
38
40
|
@game.play_level
|
|
39
41
|
end
|
|
42
|
+
|
|
43
|
+
it "should output the description of the next level" do
|
|
44
|
+
@level.stub(:ldescription).and_return("Description")
|
|
45
|
+
@profile.stub(:level=)
|
|
46
|
+
Gitscrub::UI.should_receive(:puts).with("Description")
|
|
47
|
+
@game.level_bump
|
|
48
|
+
end
|
|
40
49
|
|
|
41
50
|
end
|
data/spec/gitscrub/level_spec.rb
CHANGED
|
@@ -17,12 +17,18 @@ end
|
|
|
17
17
|
|
|
18
18
|
it "should load the level" do
|
|
19
19
|
File.stub(:dirname).and_return("")
|
|
20
|
+
File.stub(:exists?).and_return(true)
|
|
20
21
|
File.should_receive(:read).with('/../../levels/1.rb').and_return(@file)
|
|
21
22
|
level = Gitscrub::Level.load(1)
|
|
22
23
|
level.ldifficulty.should eql(1)
|
|
23
24
|
level.ldescription.should eql("A test description")
|
|
24
25
|
end
|
|
25
26
|
|
|
27
|
+
it "should return false if the level does not exist" do
|
|
28
|
+
File.stub(:exists?).and_return(false)
|
|
29
|
+
Gitscrub::Level.load(1).should eql(false)
|
|
30
|
+
end
|
|
31
|
+
|
|
26
32
|
it "should solve the problem" do
|
|
27
33
|
@level.solve.should eql(false)
|
|
28
34
|
end
|
data/spec/gitscrub/ui_spec.rb
CHANGED
|
@@ -17,6 +17,11 @@ describe Gitscrub::UI do
|
|
|
17
17
|
@out.string.should eql("hello\n")
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
it "should print an empty line with no arguments" do
|
|
21
|
+
@ui.puts
|
|
22
|
+
@out.string.should eql("\n")
|
|
23
|
+
end
|
|
24
|
+
|
|
20
25
|
it "should print without a new line" do
|
|
21
26
|
@ui.print("hello")
|
|
22
27
|
@out.string.should eql("hello")
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: gitscrub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.0.
|
|
5
|
+
version: 0.0.3
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Gary Rennie
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- bin/gitscrub
|
|
64
64
|
- gitscrub.gemspec
|
|
65
65
|
- levels/1.rb
|
|
66
|
+
- levels/2.rb
|
|
66
67
|
- lib/gitscrub.rb
|
|
67
68
|
- lib/gitscrub/cli.rb
|
|
68
69
|
- lib/gitscrub/game.rb
|