githug 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +7 -1
- data/Rakefile +5 -0
- data/githug.gemspec +1 -0
- data/levels/rename.rb +18 -0
- data/levels/squash.rb +26 -0
- data/lib/githug/game.rb +5 -0
- data/lib/githug/level.rb +20 -6
- data/lib/githug/profile.rb +3 -0
- data/lib/githug/version.rb +1 -1
- data/spec/githug/game_spec.rb +8 -0
- data/spec/githug/level_spec.rb +25 -5
- data/spec/githug/profile_spec.rb +2 -2
- metadata +15 -1
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#Githug
|
2
|
-
Git Your Game On
|
2
|
+
Git Your Game On [![Build Status](https://secure.travis-ci.org/Gazler/githug.png?branch=master)](http://travis-ci.org/Gazler/githug)
|
3
3
|
|
4
4
|
##About
|
5
5
|
Githug is designed to give you a practical way of learning git. It has a series of levels, each utilizing git commands to ensure a correct answer.
|
@@ -62,6 +62,12 @@ An example level:
|
|
62
62
|
|
63
63
|
`difficulty`, `description` and `solution` are required.
|
64
64
|
|
65
|
+
You can also include multiple hints like this:
|
66
|
+
|
67
|
+
hints [
|
68
|
+
"You can type `git` in your shell to get a list of available git commands",
|
69
|
+
"Check the man for `git add`"]
|
70
|
+
|
65
71
|
**note** Because `solution` is a Proc, you cannot prematurely return out of it and as a result, must put an implicit return on the last line of the solution block.
|
66
72
|
|
67
73
|
|
data/Rakefile
CHANGED
data/githug.gemspec
CHANGED
data/levels/rename.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
difficulty 3
|
2
|
+
|
3
|
+
description "We have a file called oldfile.txt. We want to rename it to newfile.txt and stage this change."
|
4
|
+
|
5
|
+
setup do
|
6
|
+
repo.init
|
7
|
+
FileUtils.touch("oldfile.txt")
|
8
|
+
repo.add("oldfile.txt")
|
9
|
+
repo.commit_all("Commited oldfile.txt")
|
10
|
+
end
|
11
|
+
|
12
|
+
solution do
|
13
|
+
repo.status["oldfile.txt"].type == "D" && repo.status["newfile.txt"].type == "A" && repo.status["oldfile.txt"].stage.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
hint do
|
17
|
+
puts "Take a look at `git mv`"
|
18
|
+
end
|
data/levels/squash.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
difficulty 4
|
2
|
+
description "You have committed several times but would like all those changes to be one commit"
|
3
|
+
|
4
|
+
setup do
|
5
|
+
repo.init
|
6
|
+
FileUtils.touch("README")
|
7
|
+
repo.add("README")
|
8
|
+
repo.commit_all("Adding README")
|
9
|
+
File.open("README", 'w') { |f| f.write("hey there") }
|
10
|
+
repo.add("README")
|
11
|
+
repo.commit_all("Updating README")
|
12
|
+
File.open("README", 'a') { |f| f.write("\nAdding some more text") }
|
13
|
+
repo.add("README")
|
14
|
+
repo.commit_all("Updating README")
|
15
|
+
File.open("README", 'a') { |f| f.write("\neven more text") }
|
16
|
+
repo.add("README")
|
17
|
+
repo.commit_all("Updating README")
|
18
|
+
end
|
19
|
+
|
20
|
+
solution do
|
21
|
+
repo.commits.length == 2
|
22
|
+
end
|
23
|
+
|
24
|
+
hint do
|
25
|
+
puts "Take a look the -i flag of the rebase command"
|
26
|
+
end
|
data/lib/githug/game.rb
CHANGED
data/lib/githug/level.rb
CHANGED
@@ -3,10 +3,10 @@ module Githug
|
|
3
3
|
include UI
|
4
4
|
|
5
5
|
LEVELS = [nil, "init", "add", "commit", "config", "clone",
|
6
|
-
"clone_to_folder", "ignore", "status", "rm", "rm_cached", "
|
7
|
-
"commit_ammend", "reset", "checkout_file", "remote",
|
8
|
-
"remote_add", "diff", "blame", "branch", "checkout",
|
9
|
-
"contribute"]
|
6
|
+
"clone_to_folder", "ignore", "status", "rm", "rm_cached", "rename",
|
7
|
+
"log", "commit_ammend", "reset", "checkout_file", "remote",
|
8
|
+
"remote_url", "remote_add", "diff", "blame", "branch", "checkout",
|
9
|
+
"merge", "squash", "contribute"]
|
10
10
|
|
11
11
|
attr_accessor :level_no, :level_path
|
12
12
|
|
@@ -50,6 +50,10 @@ module Githug
|
|
50
50
|
@hint = hint
|
51
51
|
end
|
52
52
|
|
53
|
+
def hints(hints)
|
54
|
+
@hints = hints
|
55
|
+
end
|
56
|
+
|
53
57
|
def full_description
|
54
58
|
UI.puts
|
55
59
|
UI.puts "Level: #{level_no}"
|
@@ -74,10 +78,20 @@ module Githug
|
|
74
78
|
false
|
75
79
|
end
|
76
80
|
|
77
|
-
|
78
81
|
def show_hint
|
79
82
|
UI.word_box("Githug")
|
80
|
-
|
83
|
+
profile = Profile.load
|
84
|
+
current_hint_index = profile.current_hint_index
|
85
|
+
if @hints
|
86
|
+
puts @hints[current_hint_index]
|
87
|
+
if current_hint_index < @hints.size - 1
|
88
|
+
profile.current_hint_index += 1
|
89
|
+
profile.save
|
90
|
+
else
|
91
|
+
profile.current_hint_index = 0
|
92
|
+
profile.save
|
93
|
+
end
|
94
|
+
elsif @hint
|
81
95
|
@hint.call
|
82
96
|
else
|
83
97
|
UI.puts("No hints available for this level")
|
data/lib/githug/profile.rb
CHANGED
@@ -10,6 +10,7 @@ module Githug
|
|
10
10
|
settings = {
|
11
11
|
:level => nil,
|
12
12
|
:current_attempts => 0,
|
13
|
+
:current_hint_index => 0,
|
13
14
|
:current_levels => [],
|
14
15
|
:completed_levels => []
|
15
16
|
}
|
@@ -50,6 +51,8 @@ module Githug
|
|
50
51
|
|
51
52
|
settings[:current_attempts] = 0
|
52
53
|
|
54
|
+
settings[:current_hint_index] = 0
|
55
|
+
|
53
56
|
next_level = (levels - settings[:completed_levels]).first || levels.last
|
54
57
|
|
55
58
|
settings[:level] = next_level
|
data/lib/githug/version.rb
CHANGED
data/spec/githug/game_spec.rb
CHANGED
@@ -61,6 +61,14 @@ describe Githug::Game do
|
|
61
61
|
|
62
62
|
end
|
63
63
|
|
64
|
+
|
65
|
+
describe "dry run" do
|
66
|
+
it "should play the game without altering the profile" do
|
67
|
+
Level.should_receive(:load)
|
68
|
+
@level.dry_run
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
64
72
|
it "should output the description of the next level" do
|
65
73
|
@level.should_receive(:full_description)
|
66
74
|
@profile.stub(:level=)
|
data/spec/githug/level_spec.rb
CHANGED
@@ -14,6 +14,10 @@ solution do
|
|
14
14
|
Grit::Repo.new("githug/notadir")
|
15
15
|
end
|
16
16
|
|
17
|
+
hints [
|
18
|
+
"this is hint 1",
|
19
|
+
"this is hint 2"]
|
20
|
+
|
17
21
|
hint do
|
18
22
|
puts "this is a hint"
|
19
23
|
end
|
@@ -107,7 +111,26 @@ end
|
|
107
111
|
end
|
108
112
|
|
109
113
|
describe "hint" do
|
110
|
-
|
114
|
+
|
115
|
+
before(:each) do
|
116
|
+
@profile = mock.as_null_object
|
117
|
+
Githug::Profile.stub(:load).and_return(@profile)
|
118
|
+
@profile.stub(:current_hint_index).and_return(0,0,1,0)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should return sequential hint if there are multiple" do
|
122
|
+
@level.should_receive(:puts).ordered.with("this is hint 1")
|
123
|
+
@level.show_hint
|
124
|
+
|
125
|
+
@level.should_receive(:puts).ordered.with("this is hint 2")
|
126
|
+
@level.show_hint
|
127
|
+
|
128
|
+
@level.should_receive(:puts).ordered.with("this is hint 1")
|
129
|
+
@level.show_hint
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should display a hint if there are not multiple" do
|
133
|
+
@level.instance_variable_set("@hints", nil)
|
111
134
|
@level.should_receive(:puts).with("this is a hint")
|
112
135
|
@level.show_hint
|
113
136
|
end
|
@@ -125,7 +148,4 @@ end
|
|
125
148
|
@level.init_from_level
|
126
149
|
end
|
127
150
|
end
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
151
|
+
end
|
data/spec/githug/profile_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Githug::Profile do
|
4
4
|
|
5
5
|
it "should load the profile" do
|
6
|
-
settings = {:level => 1, :current_attempts => 0, :current_levels => [], :completed_levels => []}
|
6
|
+
settings = {:level => 1, :current_attempts => 0, :current_hint_index => 0, :current_levels => [], :completed_levels => []}
|
7
7
|
File.should_receive(:exists?).with(Githug::Profile::PROFILE_FILE).and_return(true)
|
8
8
|
File.should_receive(:open).with(Githug::Profile::PROFILE_FILE).and_return("settings")
|
9
9
|
YAML.should_receive(:load).with("settings").and_return(settings)
|
@@ -12,7 +12,7 @@ describe Githug::Profile do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should load the defaults if the file does not exist" do
|
15
|
-
defaults = {:level => nil, :current_attempts => 0, :current_levels => [], :completed_levels => []}
|
15
|
+
defaults = {:level => nil, :current_attempts => 0, :current_hint_index => 0, :current_levels => [], :completed_levels => []}
|
16
16
|
File.should_receive(:exists?).with(Githug::Profile::PROFILE_FILE).and_return(false)
|
17
17
|
Githug::Profile.should_receive(:new).with(defaults)
|
18
18
|
Githug::Profile.load
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: githug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gary Rennie
|
@@ -46,6 +46,17 @@ dependencies:
|
|
46
46
|
version: 0.14.6
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id004
|
49
60
|
description: An interactive way to learn git.
|
50
61
|
email:
|
51
62
|
- webmaster@gazler.com
|
@@ -58,6 +69,7 @@ extra_rdoc_files: []
|
|
58
69
|
files:
|
59
70
|
- .gitignore
|
60
71
|
- .rspec
|
72
|
+
- .travis.yml
|
61
73
|
- Gemfile
|
62
74
|
- README.md
|
63
75
|
- Rakefile
|
@@ -167,9 +179,11 @@ files:
|
|
167
179
|
- levels/remote.rb
|
168
180
|
- levels/remote_add.rb
|
169
181
|
- levels/remote_url.rb
|
182
|
+
- levels/rename.rb
|
170
183
|
- levels/reset.rb
|
171
184
|
- levels/rm.rb
|
172
185
|
- levels/rm_cached.rb
|
186
|
+
- levels/squash.rb
|
173
187
|
- levels/status.rb
|
174
188
|
- lib/githug.rb
|
175
189
|
- lib/githug/cli.rb
|