gitscrub 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/levels/1.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  difficulty 1
2
2
  description "Initialize an empty repository"
3
+
4
+ setup do
5
+ `rm -rf .git`
6
+ end
7
+
3
8
  solution do
4
9
  Grit::Repo.new(".")
5
10
  end
data/levels/2.rb CHANGED
@@ -1,5 +1,12 @@
1
1
  difficulty 1
2
- description "Add a file called README to your repository"
2
+ description "There is a file in your folder called README, you should add it to your staging area"
3
+
4
+ setup do
5
+ `rm -rf .git`
6
+ `git init`
7
+ `touch README`
8
+ end
9
+
3
10
  solution do
4
11
  repo = Grit::Repo.new(".")
5
12
  return false unless repo.status.files.keys == ["README"]
data/lib/gitscrub/cli.rb CHANGED
@@ -24,7 +24,14 @@ module Gitscrub
24
24
  desc :reset, "reset the current level"
25
25
 
26
26
  def reset
27
- true
27
+ profile = Profile.load
28
+ level = Level.load(profile.level)
29
+ if level
30
+ UI.word_box("Gitscrub")
31
+ UI.puts("resetting level")
32
+ level.setup_level
33
+ level.full_description
34
+ end
28
35
  end
29
36
 
30
37
  no_tasks do
data/lib/gitscrub/game.rb CHANGED
@@ -21,9 +21,7 @@ module Gitscrub
21
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
+ UI.puts level.full_description
27
25
  end
28
26
  end
29
27
  end
@@ -33,9 +31,8 @@ module Gitscrub
33
31
  profile.level += 1
34
32
  profile.save
35
33
  if level = Level.load(profile.level)
36
- UI.puts
37
- UI.puts(level.ldescription)
38
- UI.puts
34
+ UI.puts(level.full_description)
35
+ level.setup_level
39
36
  end
40
37
  end
41
38
 
@@ -1,7 +1,7 @@
1
1
  module Gitscrub
2
2
  class Level
3
3
 
4
- attr_accessor :ldifficulty, :ldescription, :lsolution
4
+ attr_accessor :ldifficulty, :ldescription, :lsolution, :level_no, :lsetup
5
5
 
6
6
  class << self
7
7
 
@@ -10,6 +10,7 @@ module Gitscrub
10
10
  location = "#{File.dirname(__FILE__)}/../../levels/#{level_no}.rb"
11
11
  return false unless File.exists?(location)
12
12
  level.instance_eval(File.read(location))
13
+ level.level_no = level_no
13
14
  level
14
15
  end
15
16
 
@@ -27,6 +28,23 @@ module Gitscrub
27
28
  @lsolution = block
28
29
  end
29
30
 
31
+ def setup(&block)
32
+ @lsetup = block
33
+ end
34
+
35
+ def full_description
36
+ UI.puts
37
+ UI.puts "Level: #{level_no}"
38
+ UI.puts "Difficulty: #{"*"*ldifficulty}"
39
+ UI.puts
40
+ UI.puts ldescription
41
+ UI.puts
42
+ end
43
+
44
+ def setup_level
45
+ lsetup.call
46
+ end
47
+
30
48
  def solve
31
49
  lsolution.call
32
50
  rescue
@@ -1,3 +1,3 @@
1
1
  module Gitscrub
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -37,8 +37,32 @@ describe Gitscrub::CLI do
37
37
  @cli.check.should eql(true)
38
38
  end
39
39
 
40
- it "should reset the current level" do
41
- @cli.check.should eql(true)
42
- end
40
+ describe "reset" do
41
+
42
+ before(:each) do
43
+ @level = mock
44
+ @profile = mock
45
+ @profile.stub(:level).and_return(1)
46
+ Gitscrub::Profile.stub(:load).and_return(@profile)
47
+ Gitscrub::Level.stub(:load).and_return(@level)
48
+ end
49
+
50
+ it "should reset the current level" do
51
+ @level.should_receive(:setup_level)
52
+ @level.should_receive(:full_description)
53
+ Gitscrub::UI.should_receive(:word_box).with("Gitscrub")
54
+ Gitscrub::UI.should_receive(:puts).with("resetting level")
55
+ @cli.reset
56
+ end
57
+
58
+ it "should not reset if the level cannot be loaded" do
59
+ Gitscrub::Level.stub(:load).and_return(false)
60
+ @level.should_not_receive(:setup_level)
61
+ @level.should_not_receive(:full_description)
62
+ Gitscrub::UI.should_not_receive(:word_box).with("Gitscrub")
63
+ Gitscrub::UI.should_not_receive(:puts).with("resetting level")
64
+ @cli.reset
65
+ end
66
+ end
43
67
 
44
68
  end
@@ -9,7 +9,8 @@ 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
+ @level.stub(:full_description)
13
+ @level.stub(:setup_level)
13
14
  Gitscrub::UI.stub(:puts)
14
15
  Gitscrub::Level.stub(:load).and_return(@level)
15
16
  end
@@ -41,9 +42,14 @@ describe Gitscrub::Game do
41
42
  end
42
43
 
43
44
  it "should output the description of the next level" do
44
- @level.stub(:ldescription).and_return("Description")
45
+ @level.should_receive(:full_description)
46
+ @profile.stub(:level=)
47
+ @game.level_bump
48
+ end
49
+
50
+ it "should call setup_level for the next level" do
51
+ @level.should_receive(:setup_level)
45
52
  @profile.stub(:level=)
46
- Gitscrub::UI.should_receive(:puts).with("Description")
47
53
  @game.level_bump
48
54
  end
49
55
 
@@ -7,6 +7,9 @@ describe Gitscrub::Level do
7
7
  @file = <<-eof
8
8
  difficulty 1
9
9
  description "A test description"
10
+ setup do
11
+ "test"
12
+ end
10
13
  solution do
11
14
  Grit::Repo.new("gitscrub/notadir")
12
15
  end
@@ -37,5 +40,17 @@ end
37
40
  Grit::Repo.stub(:new).and_return(true)
38
41
  @level.solve.should eql(true)
39
42
  end
43
+
44
+ it "should display a full description" do
45
+ Gitscrub::UI.stub(:puts)
46
+ Gitscrub::UI.should_receive(:puts).with("Level: 1")
47
+ Gitscrub::UI.should_receive(:puts).with("Difficulty: *")
48
+ Gitscrub::UI.should_receive(:puts).with(@level.ldescription)
49
+ @level.full_description
50
+ end
51
+
52
+ it "should call setup" do
53
+ @level.setup_level.should eql("test")
54
+ end
40
55
 
41
56
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gitscrub
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gary Rennie
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-03-07 00:00:00 +00:00
13
+ date: 2012-03-08 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency