-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathgithug_spec.rb
316 lines (251 loc) · 6.87 KB
/
githug_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
require 'spec_helper'
RSpec::Matchers.define :be_solved do
match do |actual|
!actual.match("Congratulations, you have solved the level!").nil?
end
end
def skip_level
Githug::Profile.load.level_bump
`githug reset`
end
describe "The Game" do
before(:all) do
@dir = Dir.pwd
`rake build`
`gem install pkg/githug-#{Githug::VERSION}.gem`
FileUtils.rm_rf("/tmp/git_hug")
Dir.chdir("/tmp")
`echo "y" | githug`
Dir.chdir("/tmp/git_hug")
end
after(:all) do
Dir.chdir(@dir)
end
it "solves the init level" do
`git init`
`githug`.should be_solved
end
it "solves the config level" do
skip_level #The CI server does not have git config set
#full_name = `git config --get user.name`.chomp
#email = `git config --get user.email`.chomp
#f = IO::popen('githug', 'w')
#f.puts(full_name)
#f.puts(email)
#f.close
end
it "solves the add level" do
`git add README`
`githug`.should be_solved
end
it "solves the commit level" do
`git commit -m "test message"`
`githug`.should be_solved
end
it "solves the clone level" do
`git clone https://github.com/Gazler/cloneme`
`githug`.should be_solved
end
it "solves the clone_to_folder level" do
`git clone https://github.com/Gazler/cloneme my_cloned_repo`
`githug`.should be_solved
end
it "solves the ignore level" do
`echo "*.swp" >> .gitignore`
`githug`.should be_solved
end
it "solves the include level" do
`echo "*.a\n!lib.a" >> .gitignore`
`githug`.should be_solved
end
it "solves the status level" do
`git ls-files --other --exclude-standard | githug`.should be_solved
end
it "solves the number of files committed level" do
`git diff --name-only --cached | wc -l | githug`.should be_solved
end
it "solves the rm level" do
file_name = `git status | grep deleted | cut -d " " -f 5`
`git rm #{file_name}`
`githug`.should be_solved
end
it "solves the rm cached level" do
file_name = `git status | grep "new file" | cut -d " " -f 5`
`git rm --cached #{file_name}`
`githug`.should be_solved
end
it "solves the stash level" do
`git stash save`
`githug`.should be_solved
end
it "solves the rename level" do
`git mv oldfile.txt newfile.txt`
`githug`.should be_solved
end
it "solves the restructure level" do
`mkdir src`
`git mv *.html src`
`githug`.should be_solved
end
it "solves the log level" do
`git log --pretty=short | grep commit | cut -c 8-14 | githug`.should be_solved
end
it "solves the tag level" do
`git tag new_tag`
`githug`.should be_solved
end
it "solves the push_tags level" do
`git push origin master --tags`
`githug`.should be_solved
end
it "solves the commit_amend level" do
`git add forgotten_file.rb`
`git commit --amend -C HEAD`
`githug`.should be_solved
end
it "solves the commit_in_future level" do
authored_date = Time.now + 14
authored_date = authored_date.rfc2822
`git commit -m "Test of future date" --date="#{authored_date}"`
`githug`.should be_solved
end
it "solves the reset level" do
`git reset HEAD to_commit_second.rb`
`githug`.should be_solved
end
it "solves the reset_soft level" do
`git reset --soft HEAD^`
`githug`.should be_solved
end
it "solves the checkout_file level" do
`git checkout -- config.rb`
`githug`.should be_solved
end
it "solves the remove level" do
`git remote | githug`.should be_solved
end
it "solves the remote_url level" do
`git remote -v | tail -2 | head -1 | cut -c 17-52 | githug`.should be_solved
end
it "solves the pull level" do
`git pull origin master`
`githug`.should be_solved
end
it "solves the remote_add level" do
`git remote add origin https://github.com/githug/githug`
`githug`.should be_solved
end
it "solves the push level" do
`git rebase origin/master`
`git push origin`
`githug`.should be_solved
end
it "solves the diff level" do
`echo "26" | githug`.should be_solved
end
it "solves the blame level" do
`echo "spider man" | githug`.should be_solved
end
it "solves the branch level" do
`git branch test_code`
`githug`.should be_solved
end
it "solves the checkout level" do
`git checkout -b my_branch`
`githug`.should be_solved
end
it "solves the checkout_tag level" do
`git checkout v1.2`
`githug`.should be_solved
end
it "solves the checkout_tag_over_branch level" do
`git checkout tags/v1.2`
`githug`.should be_solved
end
it "solves the branch_at level" do
commit = `git log HEAD~1 --pretty=short | head -1 | cut -d " " -f 2`
`git branch test_branch #{commit}`
`githug`.should be_solved
end
it "solves the delete_branch level" do
`git branch -d delete_me`
`githug`.should be_solved
end
it "solves the push_branch level" do
`git push origin test_branch`
`githug`.should be_solved
end
it "should commit the merge level" do
`git merge feature`
`githug`.should be_solved
end
it "solves the fetch level" do
`git fetch`
`githug`.should be_solved
end
it "solves the rebase level" do
`git checkout feature`
`git rebase master`
`githug`.should be_solved
end
it "solves the rebase_onto level" do
`git checkout readme-update`
`git rebase --onto master wrong_branch readme-update`
`githug`.should be_solved
end
it "solves the repack level" do
`git repack -d`
`githug`.should be_solved
end
it "solves the cherry-pick level" do
commit = `git log new-feature --oneline -n 3 | tail -1 | cut -d " " -f 1`
`git cherry-pick #{commit}`
`githug`.should be_solved
end
it "solves the grep level" do
`echo "4" | githug`.should be_solved
end
it "solves the rename_commit level" do
skip_level
end
it "solves the squash level" do
skip_level
end
it "solves the merge squash level" do
`git merge --squash long-feature-branch`
`git commit -m "Merged Long Feature Branch"`
`githug`.should be_solved
end
it "solves the reorder level" do
skip_level
end
it "solves the bisect level" do
`echo "18ed2ac" | githug`.should be_solved
end
it "solves the stage_lines level" do
skip_level
end
it "solves the find_old_branch level" do
`git checkout solve_world_hunger`
`githug`.should be_solved
end
it "solves the revert level" do
sleep 1
`git revert HEAD~1 --no-edit`
`githug`.should be_solved
end
it "solves the restore level" do
`git reflog | grep "Restore this commit" | awk '{print $1}' | xargs git checkout`
`githug`.should be_solved
end
it "solves the conflict level" do
skip_level
end
it "solves the submodule level" do
`git submodule add https://github.com/jackmaney/githug-include-me`
`githug`.should be_solved
end
it "solves the contribute level" do
skip_level
end
end