vertiginous-github 0.1.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/spec/ui_spec.rb ADDED
@@ -0,0 +1,406 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "github" do
4
+ # -- home --
5
+ specify "home should open the project home page" do
6
+ running :home do
7
+ setup_url_for
8
+ @helper.should_receive(:open).once.with("https://github.com/user/project/tree/master")
9
+ end
10
+ end
11
+
12
+ specify "home defunkt should open the home page of defunkt's fork" do
13
+ running :home, "defunkt" do
14
+ setup_url_for
15
+ @helper.should_receive(:open).once.with("https://github.com/defunkt/project/tree/master")
16
+ end
17
+ end
18
+
19
+ # -- browse --
20
+ specify "browse should open the project home page with the current branch" do
21
+ running :browse do
22
+ setup_url_for
23
+ setup_user_and_branch("user", "test-branch")
24
+ @helper.should_receive(:open).once.with("https://github.com/user/project/tree/test-branch")
25
+ end
26
+ end
27
+
28
+ specify "browse pending should open the project home page with the 'pending' branch" do
29
+ running :browse, "pending" do
30
+ setup_url_for
31
+ setup_user_and_branch("user", "test-branch")
32
+ @helper.should_receive(:open).once.with("https://github.com/user/project/tree/pending")
33
+ end
34
+ end
35
+
36
+ specify "browse defunkt pending should open the home page of defunkt's fork with the 'pending' branch" do
37
+ running :browse, "defunkt", "pending" do
38
+ setup_url_for
39
+ @helper.should_receive(:open).once.with("https://github.com/defunkt/project/tree/pending")
40
+ end
41
+ end
42
+
43
+ specify "browse defunkt/pending should open the home page of defunkt's fork with the 'pending' branch" do
44
+ running :browse, "defunkt/pending" do
45
+ setup_url_for
46
+ @helper.should_receive(:open).once.with("https://github.com/defunkt/project/tree/pending")
47
+ end
48
+ end
49
+
50
+ # -- network --
51
+ specify "network should open the network page for this repo" do
52
+ running :network do
53
+ setup_url_for
54
+ @helper.should_receive(:open).once.with("https://github.com/user/project/network")
55
+ end
56
+ end
57
+
58
+ specify "network defunkt should open the network page for defunkt's fork" do
59
+ running :network, "defunkt" do
60
+ setup_url_for
61
+ @helper.should_receive(:open).once.with("https://github.com/defunkt/project/network")
62
+ end
63
+ end
64
+
65
+ # -- info --
66
+ specify "info should show info for this project" do
67
+ running :info do
68
+ setup_url_for
69
+ setup_remote(:origin, :user => "user", :ssh => true)
70
+ setup_remote(:defunkt)
71
+ setup_remote(:external, :url => "home:/path/to/project.git")
72
+ stdout.should == <<-EOF
73
+ == Info for project
74
+ You are user
75
+ Currently tracking:
76
+ - user (as origin)
77
+ - defunkt (as defunkt)
78
+ - home:/path/to/project.git (as external)
79
+ EOF
80
+ end
81
+ end
82
+
83
+ # -- track --
84
+ specify "track defunkt should track a new remote for defunkt" do
85
+ running :track, "defunkt" do
86
+ setup_url_for
87
+ @helper.should_receive(:tracking?).with("defunkt").once.and_return(false)
88
+ @command.should_receive(:git).with("remote add defunkt git://github.com/defunkt/project.git").once
89
+ end
90
+ end
91
+
92
+ specify "track --private defunkt should track a new remove for defunkt using ssh" do
93
+ running :track, "--private", "defunkt" do
94
+ setup_url_for
95
+ @helper.should_receive(:tracking?).with("defunkt").once.and_return(false)
96
+ @command.should_receive(:git).with("remote add defunkt git@github.com:defunkt/project.git").once
97
+ end
98
+ end
99
+
100
+ specify "track defunkt should die if the defunkt remote exists" do
101
+ running :track, "defunkt" do
102
+ setup_url_for
103
+ @helper.should_receive(:tracking?).with("defunkt").once.and_return(true)
104
+ @command.should_receive(:die).with("Already tracking defunkt").and_return { raise "Died" }
105
+ self.should raise_error("Died")
106
+ end
107
+ end
108
+
109
+ specify "track should die with no args" do
110
+ running :track do
111
+ @command.should_receive(:die).with("Specify a user to track").and_return { raise "Died" }
112
+ self.should raise_error("Died")
113
+ end
114
+ end
115
+
116
+ # -- pull --
117
+ specify "pull should die with no args" do
118
+ running :pull do
119
+ @command.should_receive(:die).with("Specify a user to pull from").and_return { raise "Died" }
120
+ self.should raise_error("Died")
121
+ end
122
+ end
123
+
124
+ specify "pull defunkt should start tracking defunkt if they're not already tracked" do
125
+ running :pull, "defunkt" do
126
+ setup_remote(:origin, :user => "user", :ssh => true)
127
+ setup_remote(:external, :url => "home:/path/to/project.git")
128
+ GitHub.should_receive(:invoke).with(:track, "defunkt").and_return { raise "Tracked" }
129
+ self.should raise_error("Tracked")
130
+ end
131
+ end
132
+
133
+ specify "pull defunkt should create defunkt/master and pull from the defunkt remote" do
134
+ running :pull, "defunkt" do
135
+ setup_remote(:defunkt)
136
+ @command.should_receive(:git).with("checkout -b defunkt/master").ordered.and_return do
137
+ mock("checkout -b defunkt/master").tap { |m| m.stub!(:error?) }
138
+ end
139
+ @command.should_receive(:git_exec).with("pull defunkt master").ordered
140
+ stdout.should == "Switching to defunkt/master"
141
+ end
142
+ end
143
+
144
+ specify "pull defunkt should switch to pre-existing defunkt/master and pull from the defunkt remote" do
145
+ running :pull, "defunkt" do
146
+ setup_remote(:defunkt)
147
+ @command.should_receive(:git).with("checkout -b defunkt/master").ordered.and_return do
148
+ mock("checkout -b defunkt/master").tap { |m| m.should_receive(:error?) { true } }
149
+ end
150
+ @command.should_receive(:git).with("checkout defunkt/master").ordered
151
+ @command.should_receive(:git_exec).with("pull defunkt master").ordered
152
+ stdout.should == "Switching to defunkt/master"
153
+ end
154
+ end
155
+
156
+ specify "pull defunkt wip should create defunkt/wip and pull from wip branch on defunkt remote" do
157
+ running :pull, "defunkt", "wip" do
158
+ setup_remote(:defunkt)
159
+ @command.should_receive(:git).with("checkout -b defunkt/wip").ordered.and_return do
160
+ mock("checkout -b defunkt/wip").tap { |m| m.stub!(:error?) }
161
+ end
162
+ @command.should_receive(:git_exec).with("pull defunkt wip").ordered
163
+ stdout.should == "Switching to defunkt/wip"
164
+ end
165
+ end
166
+
167
+ specify "pull defunkt/wip should switch to pre-existing defunkt/wip and pull from wip branch on defunkt remote" do
168
+ running :pull, "defunkt/wip" do
169
+ setup_remote(:defunkt)
170
+ @command.should_receive(:git).with("checkout -b defunkt/wip").ordered.and_return do
171
+ mock("checkout -b defunkt/wip").tap { |m| m.should_receive(:error?) { true } }
172
+ end
173
+ @command.should_receive(:git).with("checkout defunkt/wip").ordered
174
+ @command.should_receive(:git_exec).with("pull defunkt wip").ordered
175
+ stdout.should == "Switching to defunkt/wip"
176
+ end
177
+ end
178
+
179
+ specify "pull --merge defunkt should pull from defunkt remote into current branch" do
180
+ running :pull, "--merge", "defunkt" do
181
+ setup_remote(:defunkt)
182
+ @command.should_receive(:git_exec).with("pull defunkt master")
183
+ end
184
+ end
185
+
186
+ # -- clone --
187
+ specify "clone should die with no args" do
188
+ running :clone do
189
+ @command.should_receive(:die).with("Specify a user to pull from").and_return { raise "Died" }
190
+ self.should raise_error("Died")
191
+ end
192
+ end
193
+
194
+ specify "clone should die with just one arg" do
195
+ running :clone, "user" do
196
+ @command.should_receive(:die).with("Specify a repo to pull from").and_return { raise "Died" }
197
+ self.should raise_error("Died")
198
+ end
199
+ end
200
+
201
+ specify "clone defunkt github-gem should clone the repo" do
202
+ running :clone, "defunkt", "github-gem" do
203
+ @command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git")
204
+ end
205
+ end
206
+
207
+ specify "clone --ssh defunkt github-gem should clone the repo using the private URL" do
208
+ running :clone, "--ssh", "defunkt", "github-gem" do
209
+ @command.should_receive(:git_exec).with("clone git@github.com:defunkt/github-gem.git")
210
+ end
211
+ end
212
+
213
+ specify "clone defunkt github-gem repo should clone the repo into the dir 'repo'" do
214
+ running :clone, "defunkt", "github-gem", "repo" do
215
+ @command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git repo")
216
+ end
217
+ end
218
+
219
+ specify "clone --ssh defunkt github-gem repo should clone the repo using the private URL into the dir 'repo'" do
220
+ running :clone, "--ssh", "defunkt", "github-gem", "repo" do
221
+ @command.should_receive(:git_exec).with("clone git@github.com:defunkt/github-gem.git repo")
222
+ end
223
+ end
224
+
225
+ # -- pull-request --
226
+ specify "pull-request should die with no args" do
227
+ running :'pull-request' do
228
+ setup_url_for
229
+ @command.should_receive(:die).with("Specify a user for the pull request").and_return { raise "Died" }
230
+ self.should raise_error("Died")
231
+ end
232
+ end
233
+
234
+ specify "pull-request user should track user if untracked" do
235
+ running :'pull-request', "user" do
236
+ setup_url_for
237
+ setup_remote :origin, :user => "kballard"
238
+ setup_remote :defunkt
239
+ GitHub.should_receive(:invoke).with(:track, "user").and_return { raise "Tracked" }
240
+ self.should raise_error("Tracked")
241
+ end
242
+ end
243
+
244
+ specify "pull-request user/branch should generate a pull request" do
245
+ running :'pull-request', "user/branch" do
246
+ setup_url_for
247
+ setup_remote :origin, :user => "kballard"
248
+ setup_remote :user
249
+ @command.should_receive(:git_exec).with("request-pull user/branch origin")
250
+ end
251
+ end
252
+
253
+ specify "pull-request user should generate a pull request with branch master" do
254
+ running :'pull-request', "user" do
255
+ setup_url_for
256
+ setup_remote :origin, :user => "kballard"
257
+ setup_remote :user
258
+ @command.should_receive(:git_exec).with("request-pull user/master origin")
259
+ end
260
+ end
261
+
262
+ specify "pull-request user branch should generate a pull request" do
263
+ running:'pull-request', "user", "branch" do
264
+ setup_url_for
265
+ setup_remote :origin, :user => "kballard"
266
+ setup_remote :user
267
+ @command.should_receive(:git_exec).with("request-pull user/branch origin")
268
+ end
269
+ end
270
+
271
+ # -- default --
272
+ specify "should print the default message" do
273
+ running :default do
274
+ GitHub.should_receive(:descriptions).any_number_of_times.and_return({
275
+ "home" => "Open the home page",
276
+ "track" => "Track a new repo",
277
+ "browse" => "Browse the github page for this branch",
278
+ "command" => "description"
279
+ })
280
+ GitHub.should_receive(:flag_descriptions).any_number_of_times.and_return({
281
+ "home" => {:flag => "Flag description"},
282
+ "track" => {:flag1 => "Flag one", :flag2 => "Flag two"},
283
+ "browse" => {},
284
+ "command" => {}
285
+ })
286
+ @command.should_receive(:puts).with("Usage: github command <space separated arguments>", '').ordered
287
+ @command.should_receive(:puts).with("Available commands:", '').ordered
288
+ @command.should_receive(:puts).with(" home => Open the home page")
289
+ @command.should_receive(:puts).with(" --flag: Flag description")
290
+ @command.should_receive(:puts).with(" track => Track a new repo")
291
+ @command.should_receive(:puts).with(" --flag1: Flag one")
292
+ @command.should_receive(:puts).with(" --flag2: Flag two")
293
+ @command.should_receive(:puts).with(" browse => Browse the github page for this branch")
294
+ @command.should_receive(:puts).with(" command => description")
295
+ @command.should_receive(:puts).with()
296
+ end
297
+ end
298
+
299
+ # -----------------
300
+
301
+ def running(cmd, *args, &block)
302
+ Runner.new(self, cmd, *args, &block).run
303
+ end
304
+
305
+ class Runner
306
+ include SetupMethods
307
+
308
+ def initialize(parent, cmd, *args, &block)
309
+ @cmd_name = cmd.to_s
310
+ @command = GitHub.commands[cmd.to_s]
311
+ @helper = @command.helper
312
+ @args = args
313
+ @block = block
314
+ @parent = parent
315
+ end
316
+
317
+ def run
318
+ self.instance_eval &@block
319
+ mock_remotes unless @remotes.nil?
320
+ GitHub.should_receive(:load).with("commands.rb")
321
+ GitHub.should_receive(:load).with("helpers.rb")
322
+ args = @args.clone
323
+ GitHub.parse_options(args) # strip out the flags
324
+ GitHub.should_receive(:invoke).with(@cmd_name, *args).and_return do
325
+ GitHub.send(GitHub.send(:__mock_proxy).send(:munge, :invoke), @cmd_name, *args)
326
+ end
327
+ invoke = lambda { GitHub.activate([@cmd_name, *@args]) }
328
+ if @expected_result
329
+ expectation, result = @expected_result
330
+ case result
331
+ when Spec::Matchers::RaiseError, Spec::Matchers::Change, Spec::Matchers::ThrowSymbol
332
+ invoke.send expectation, result
333
+ else
334
+ invoke.call.send expectation, result
335
+ end
336
+ else
337
+ invoke.call
338
+ end
339
+ @stdout_mock.invoke unless @stdout_mock.nil?
340
+ end
341
+
342
+ def setup_remote(remote, options = {:user => nil, :project => "project"})
343
+ @remotes ||= {}
344
+ user = options[:user] || remote
345
+ project = options[:project]
346
+ ssh = options[:ssh]
347
+ url = options[:url]
348
+ if url
349
+ @remotes[remote.to_sym] = url
350
+ elsif ssh
351
+ @remotes[remote.to_sym] = "git@github.com:#{user}/#{project}.git"
352
+ else
353
+ @remotes[remote.to_sym] = "git://github.com/#{user}/#{project}.git"
354
+ end
355
+ end
356
+
357
+ def mock_remotes()
358
+ @helper.should_receive(:remotes).any_number_of_times.and_return(@remotes)
359
+ end
360
+
361
+ def should(result)
362
+ @expected_result = [:should, result]
363
+ end
364
+
365
+ def should_not(result)
366
+ @expected_result = [:should_not, result]
367
+ end
368
+
369
+ def stdout
370
+ if @stdout_mock.nil?
371
+ output = ""
372
+ @stdout_mock = DeferredMock.new(output)
373
+ STDOUT.should_receive(:write).any_number_of_times do |str|
374
+ output << str
375
+ end
376
+ end
377
+ @stdout_mock
378
+ end
379
+
380
+ class DeferredMock
381
+ def initialize(obj = nil)
382
+ @obj = obj
383
+ @calls = []
384
+ end
385
+
386
+ def invoke(obj = nil)
387
+ obj ||= @obj
388
+ @calls.each do |sym, args|
389
+ obj.send sym, *args
390
+ end
391
+ end
392
+
393
+ def should(*args)
394
+ @calls << [:should, args]
395
+ end
396
+
397
+ def should_not(*args)
398
+ @calls << [:should_not, args]
399
+ end
400
+ end
401
+
402
+ def method_missing(sym, *args)
403
+ @parent.send sym, *args
404
+ end
405
+ end
406
+ end
@@ -0,0 +1,36 @@
1
+ # this is an extremely hacky spec
2
+ # intended purely to test the Windoze-specific code
3
+
4
+ require 'rubygems'
5
+ require 'spec'
6
+
7
+ describe "github/command.rb" do
8
+ before(:all) do
9
+ @orig_platform = RUBY_PLATFORM
10
+ Object.send :remove_const, :RUBY_PLATFORM
11
+ Object.const_set :RUBY_PLATFORM, "mswin"
12
+ end
13
+
14
+ after(:all) do
15
+ Object.send :remove_const, :RUBY_PLATFORM
16
+ Object.const_set :RUBY_PLATFORM, @orig_platform
17
+ end
18
+
19
+ before(:each) do
20
+ @filename = File.dirname(__FILE__) + "/../lib/github/command.rb"
21
+ @data = File.read(@filename)
22
+ end
23
+
24
+ it "should require win32/open3 under Windows" do
25
+ mod = Module.new
26
+ mod.should_receive(:require).with("win32/open3")
27
+ mod.class_eval @data, @filename
28
+ end
29
+
30
+ it "should blow up if win32/open3 isn't present under Windows" do
31
+ mod = Module.new
32
+ mod.should_receive(:require).with("win32/open3").and_return { raise LoadError }
33
+ mod.should_receive(:warn).with("You must 'gem install win32-open3' to use the github command on Windows")
34
+ lambda { mod.class_eval @data, @filename }.should raise_error(SystemExit)
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vertiginous-github
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Chris Wanstrath, Kevin Ballard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-18 00:00:00 -07:00
13
+ default_executable: github
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: launchy
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: The official `github` command line helper for simplifying your GitHub experience.
25
+ email: chris@ozmm.org
26
+ executables:
27
+ - github
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - bin/github
32
+ - lib/extensions.rb
33
+ - lib/github/command.rb
34
+ - lib/github/helper.rb
35
+ - lib/github.rb
36
+ - LICENSE
37
+ - README
38
+ files:
39
+ - bin/github
40
+ - commands/commands.rb
41
+ - commands/helpers.rb
42
+ - lib/extensions.rb
43
+ - lib/github/command.rb
44
+ - lib/github/helper.rb
45
+ - lib/github.rb
46
+ - LICENSE
47
+ - Manifest
48
+ - README
49
+ - spec/command_spec.rb
50
+ - spec/extensions_spec.rb
51
+ - spec/github_spec.rb
52
+ - spec/helper_spec.rb
53
+ - spec/spec_helper.rb
54
+ - spec/ui_spec.rb
55
+ - spec/windoze_spec.rb
56
+ - github.gemspec
57
+ has_rdoc: true
58
+ homepage: http://github.com/
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --line-numbers
62
+ - --inline-source
63
+ - --title
64
+ - Github
65
+ - --main
66
+ - README
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: github
84
+ rubygems_version: 1.0.1
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: The official `github` command line helper for simplifying your GitHub experience.
88
+ test_files: []
89
+