gitscrub 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/levels/2.rb ADDED
@@ -0,0 +1,8 @@
1
+ difficulty 1
2
+ description "Add a file called README to your repository"
3
+ solution do
4
+ repo = Grit::Repo.new(".")
5
+ return false unless repo.status.files.keys == ["README"]
6
+ return false if repo.status.files["README"].untracked
7
+ true
8
+ end
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 gitscrubber directory found, do you wish to create one?")
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
@@ -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
@@ -14,7 +14,7 @@ module Gitscrub
14
14
  @@in_stream = in_stream
15
15
  end
16
16
 
17
- def puts(string)
17
+ def puts(string = "")
18
18
  @@out_stream.puts(string)
19
19
  end
20
20
 
@@ -1,3 +1,3 @@
1
1
  module Gitscrub
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -18,6 +18,7 @@ describe Gitscrub::CLI do
18
18
  it "should create a directory if one does not exist" do
19
19
  Gitscrub::UI.stub(:ask).and_return(true)
20
20
  Dir.should_receive(:mkdir).with("./git_scrub")
21
+ Dir.should_receive(:chdir).with("git_scrub")
21
22
  @cli.make_directory
22
23
  end
23
24
 
@@ -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
@@ -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
@@ -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.2
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