defunkt-github 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +7 -7
- data/README +2 -1
- data/commands/commands.rb +79 -25
- data/commands/helpers.rb +69 -30
- data/lib/github/command.rb +4 -4
- data/lib/github/extensions.rb +28 -0
- data/lib/github.rb +42 -14
- data/spec/command_spec.rb +66 -0
- data/spec/extensions_spec.rb +36 -0
- data/spec/github_spec.rb +65 -0
- data/spec/helper_spec.rb +212 -0
- data/spec/spec_helper.rb +133 -4
- data/spec/ui_spec.rb +506 -0
- data/spec/windoze_spec.rb +36 -0
- metadata +12 -11
- data/spec/helpers/owner_spec.rb +0 -12
- data/spec/helpers/project_spec.rb +0 -12
- data/spec/helpers/public_url_for_spec.rb +0 -12
- data/spec/helpers/repo_for_spec.rb +0 -12
- data/spec/helpers/user_and_repo_from_spec.rb +0 -15
- data/spec/helpers/user_for_spec.rb +0 -12
data/spec/helper_spec.rb
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class HelperRunner
|
4
|
+
def initialize(parent, name)
|
5
|
+
@parent = parent
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(&block)
|
10
|
+
self.instance_eval(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def it(str, &block)
|
14
|
+
@parent.send :it, "#{@name} #{str}", &block
|
15
|
+
end
|
16
|
+
alias specify it
|
17
|
+
end
|
18
|
+
|
19
|
+
describe GitHub::Helper do
|
20
|
+
include SetupMethods
|
21
|
+
|
22
|
+
def self.helper(name, &block)
|
23
|
+
HelperRunner.new(self, name).run(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
@helper = GitHub::Helper.new
|
28
|
+
end
|
29
|
+
|
30
|
+
helper :owner do
|
31
|
+
it "should return repo owner" do
|
32
|
+
setup_url_for :origin, "hacker"
|
33
|
+
@helper.owner.should == "hacker"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
helper :private_url_for do
|
38
|
+
it "should return an ssh-style url" do
|
39
|
+
setup_url_for :origin, "user", "merb-core"
|
40
|
+
@helper.private_url_for("wycats").should == "git@github.com:wycats/merb-core.git"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
helper :private_url_for_user_and_repo do
|
45
|
+
it "should return an ssh-style url" do
|
46
|
+
@helper.should_not_receive(:project)
|
47
|
+
@helper.private_url_for_user_and_repo("defunkt", "github-gem").should == "git@github.com:defunkt/github-gem.git"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
helper :public_url_for do
|
52
|
+
it "should return a git:// URL" do
|
53
|
+
setup_url_for :origin, "user", "merb-core"
|
54
|
+
@helper.public_url_for("wycats").should == "git://github.com/wycats/merb-core.git"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
helper :public_url_for_user_and_repo do
|
59
|
+
it "should return a git:// URL" do
|
60
|
+
@helper.should_not_receive(:project)
|
61
|
+
@helper.public_url_for_user_and_repo("defunkt", "github-gem").should == "git://github.com/defunkt/github-gem.git"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
helper :project do
|
66
|
+
it "should return project-awesome" do
|
67
|
+
setup_url_for :origin, "user", "project-awesome"
|
68
|
+
@helper.project.should == "project-awesome"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should exit due to missing origin" do
|
72
|
+
@helper.should_receive(:url_for).twice.with(:origin).and_return("")
|
73
|
+
STDERR.should_receive(:puts).with("Error: missing remote 'origin'")
|
74
|
+
lambda { @helper.project }.should raise_error(SystemExit)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should exit due to non-github origin" do
|
78
|
+
@helper.should_receive(:url_for).twice.with(:origin).and_return("home:path/to/repo.git")
|
79
|
+
STDERR.should_receive(:puts).with("Error: remote 'origin' is not a github URL")
|
80
|
+
lambda { @helper.project }.should raise_error(SystemExit)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
helper :repo_for do
|
85
|
+
it "should return mephisto.git" do
|
86
|
+
setup_url_for :mojombo, "mojombo", "mephisto"
|
87
|
+
@helper.repo_for(:mojombo).should == "mephisto.git"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
helper :user_and_repo_from do
|
92
|
+
it "should parse a git:// url" do
|
93
|
+
@helper.user_and_repo_from("git://github.com/defunkt/github.git").should == ["defunkt", "github.git"]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should parse a ssh-based url" do
|
97
|
+
@helper.user_and_repo_from("git@github.com:mojombo/god.git").should == ["mojombo", "god.git"]
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should parse a non-standard ssh-based url" do
|
101
|
+
@helper.user_and_repo_from("ssh://git@github.com:mojombo/god.git").should == ["mojombo", "god.git"]
|
102
|
+
@helper.user_and_repo_from("github.com:mojombo/god.git").should == ["mojombo", "god.git"]
|
103
|
+
@helper.user_and_repo_from("ssh://github.com:mojombo/god.git").should == ["mojombo", "god.git"]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return nothing for other urls" do
|
107
|
+
@helper.user_and_repo_from("home:path/to/repo.git").should == nil
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return nothing for invalid git:// urls" do
|
111
|
+
@helper.user_and_repo_from("git://github.com/foo").should == nil
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should return nothing for invalid ssh-based urls" do
|
115
|
+
@helper.user_and_repo_from("git@github.com:kballard").should == nil
|
116
|
+
@helper.user_and_repo_from("git@github.com:kballard/test/repo.git").should == nil
|
117
|
+
@helper.user_and_repo_from("ssh://git@github.com:kballard").should == nil
|
118
|
+
@helper.user_and_repo_from("github.com:kballard").should == nil
|
119
|
+
@helper.user_and_repo_from("ssh://github.com:kballard").should == nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
helper :user_for do
|
124
|
+
it "should return defunkt" do
|
125
|
+
setup_url_for :origin, "defunkt"
|
126
|
+
@helper.user_for(:origin).should == "defunkt"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
helper :url_for do
|
131
|
+
it "should call out to the shell" do
|
132
|
+
@helper.should_receive(:`).with("git config --get remote.origin.url").and_return "git://github.com/user/project.git\n"
|
133
|
+
@helper.url_for(:origin).should == "git://github.com/user/project.git"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
helper :remotes do
|
138
|
+
it "should return a list of remotes" do
|
139
|
+
@helper.should_receive(:`).with('git config --get-regexp \'^remote\.(.+)\.url$\'').and_return <<-EOF
|
140
|
+
remote.origin.url git@github.com:kballard/github-gem.git
|
141
|
+
remote.defunkt.url git://github.com/defunkt/github-gem.git
|
142
|
+
remote.nex3.url git://github.com/nex3/github-gem.git
|
143
|
+
EOF
|
144
|
+
@helper.remotes.should == {
|
145
|
+
:origin => "git@github.com:kballard/github-gem.git",
|
146
|
+
:defunkt => "git://github.com/defunkt/github-gem.git",
|
147
|
+
:nex3 => "git://github.com/nex3/github-gem.git"
|
148
|
+
}
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
helper :tracking do
|
153
|
+
it "should return a list of remote/user_or_url pairs" do
|
154
|
+
@helper.should_receive(:remotes).and_return({
|
155
|
+
:origin => "git@github.com:kballard/github-gem.git",
|
156
|
+
:defunkt => "git://github.com/defunkt/github-gem.git",
|
157
|
+
:external => "server:path/to/github-gem.git"
|
158
|
+
})
|
159
|
+
@helper.tracking.should == {
|
160
|
+
:origin => "kballard",
|
161
|
+
:defunkt => "defunkt",
|
162
|
+
:external => "server:path/to/github-gem.git"
|
163
|
+
}
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
helper :tracking? do
|
168
|
+
it "should return whether the user is tracked" do
|
169
|
+
@helper.should_receive(:tracking).any_number_of_times.and_return({
|
170
|
+
:origin => "kballard",
|
171
|
+
:defunkt => "defunkt",
|
172
|
+
:external => "server:path/to/github-gem.git"
|
173
|
+
})
|
174
|
+
@helper.tracking?("kballard").should == true
|
175
|
+
@helper.tracking?("defunkt").should == true
|
176
|
+
@helper.tracking?("nex3").should == false
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
helper :user_and_branch do
|
181
|
+
it "should return owner and branch for unqualified branches" do
|
182
|
+
setup_url_for
|
183
|
+
@helper.should_receive(:`).with("git rev-parse --symbolic-full-name HEAD").and_return "refs/heads/master"
|
184
|
+
@helper.user_and_branch.should == ["user", "master"]
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should return user and branch for user/branch-style branches" do
|
188
|
+
@helper.should_receive(:`).with("git rev-parse --symbolic-full-name HEAD").and_return "refs/heads/defunkt/wip"
|
189
|
+
@helper.user_and_branch.should == ["defunkt", "wip"]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
helper :open do
|
194
|
+
it "should launch the URL when Launchy is installed" do
|
195
|
+
begin
|
196
|
+
require 'launchy'
|
197
|
+
@helper.should_receive(:gem).with('launchy')
|
198
|
+
# @helper.should_receive(:has_launchy?).and_return { |blk| blk.call }
|
199
|
+
Launchy::Browser.next_instance.should_receive(:visit).with("http://www.google.com")
|
200
|
+
@helper.open "http://www.google.com"
|
201
|
+
rescue LoadError
|
202
|
+
fail "Launchy is required for this spec"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should fail when Launchy is not installed" do
|
207
|
+
@helper.should_receive(:gem).with('launchy').and_raise(Gem::LoadError)
|
208
|
+
STDERR.should_receive(:puts).with("Sorry, you need to install launchy: `gem install launchy`")
|
209
|
+
@helper.open "http://www.google.com"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,136 @@ require 'spec'
|
|
3
3
|
|
4
4
|
require File.dirname(__FILE__) + '/../lib/github'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
class Module
|
7
|
+
def metaclass
|
8
|
+
class << self;self;end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Spec::NextInstanceProxy
|
13
|
+
def initialize
|
14
|
+
@deferred = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(sym, *args)
|
18
|
+
proxy = Spec::NextInstanceProxy.new
|
19
|
+
@deferred << [sym, args, proxy]
|
20
|
+
proxy
|
21
|
+
end
|
22
|
+
|
23
|
+
def should_receive(*args)
|
24
|
+
method_missing(:should_receive, *args)
|
25
|
+
end
|
26
|
+
alias stub! should_receive
|
27
|
+
|
28
|
+
def invoke(obj)
|
29
|
+
@deferred.each do |(sym, args, proxy)|
|
30
|
+
result = obj.send(sym, *args)
|
31
|
+
proxy.invoke(result)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Class
|
37
|
+
def next_instance
|
38
|
+
meth = metaclass.instance_method(:new)
|
39
|
+
proxy = Spec::NextInstanceProxy.new
|
40
|
+
metaclass.send :define_method, :new do |*args|
|
41
|
+
instance = meth.bind(self).call(*args)
|
42
|
+
proxy.invoke(instance)
|
43
|
+
metaclass.send :define_method, :new, meth
|
44
|
+
instance
|
45
|
+
end
|
46
|
+
proxy
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Spec::Example::ExampleGroupSubclassMethods
|
51
|
+
def add_guard(klass, name, is_class = false)
|
52
|
+
guarded = nil # define variable now for scoping
|
53
|
+
target = (is_class ? klass.metaclass : klass)
|
54
|
+
sep = (is_class ? "." : "#")
|
55
|
+
target.class_eval do
|
56
|
+
guarded = instance_method(name)
|
57
|
+
define_method name do |*args|
|
58
|
+
raise "Testing guards violated: Cannot call #{klass}#{sep}#{name}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
@guards ||= []
|
62
|
+
@guards << [klass, name, is_class, guarded]
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_class_guard(klass, name)
|
66
|
+
add_guard(klass, name, true)
|
67
|
+
end
|
68
|
+
|
69
|
+
def unguard(klass, name, is_class = false)
|
70
|
+
row = @guards.find { |(k,n,i)| k == klass and n == name and i == is_class }
|
71
|
+
raise "#{klass}#{is_class ? "." : "#"}#{name} is not guarded" if row.nil?
|
72
|
+
(is_class ? klass.metaclass : klass).class_eval do
|
73
|
+
define_method name, row.last
|
74
|
+
end
|
75
|
+
@guards.delete row
|
76
|
+
end
|
77
|
+
|
78
|
+
def class_unguard(klass, name)
|
79
|
+
unguard(klass, name, true)
|
80
|
+
end
|
81
|
+
|
82
|
+
def unguard_all
|
83
|
+
@guards ||= []
|
84
|
+
@guards.each do |klass, name, is_class, guarded|
|
85
|
+
(is_class ? klass.metaclass : klass).class_eval do
|
86
|
+
define_method name, guarded
|
87
|
+
end
|
88
|
+
end
|
89
|
+
@guards.clear
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# prevent the use of `` in tests
|
94
|
+
Spec::Runner.configure do |configuration|
|
95
|
+
# load this here so it's covered by the `` guard
|
96
|
+
configuration.prepend_before(:all) do
|
97
|
+
module GitHub
|
98
|
+
load 'helpers.rb'
|
99
|
+
load 'commands.rb'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
configuration.prepend_after(:each) do
|
104
|
+
GitHub.instance_variable_set :'@options', nil
|
105
|
+
GitHub.instance_variable_set :'@debug', nil
|
106
|
+
end
|
107
|
+
|
108
|
+
configuration.prepend_before(:all) do
|
109
|
+
self.class.send :include, Spec::Example::ExampleGroupSubclassMethods
|
110
|
+
end
|
111
|
+
|
112
|
+
configuration.prepend_before(:each) do
|
113
|
+
add_guard Kernel, :`
|
114
|
+
add_guard Kernel, :system
|
115
|
+
add_guard Kernel, :fork
|
116
|
+
add_guard Kernel, :exec
|
117
|
+
add_class_guard Process, :fork
|
118
|
+
end
|
119
|
+
|
120
|
+
configuration.append_after(:each) do
|
121
|
+
unguard_all
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# include this in any example group that defines @helper
|
126
|
+
module SetupMethods
|
127
|
+
def setup_user_and_branch(user = :user, branch = :master)
|
128
|
+
@helper.should_receive(:user_and_branch).any_number_of_times.and_return([user, branch])
|
129
|
+
end
|
130
|
+
|
131
|
+
def setup_url_for(remote = :origin, user = nil, project = :project)
|
132
|
+
if user.nil?
|
133
|
+
user = remote
|
134
|
+
user = "user" if remote == :origin
|
135
|
+
end
|
136
|
+
@helper.should_receive(:url_for).any_number_of_times.with(remote).and_return("git://github.com/#{user}/#{project}.git")
|
137
|
+
end
|
138
|
+
end
|