ghi 0.3.1 → 0.9.0.dev

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ghi/issue.rb DELETED
@@ -1,30 +0,0 @@
1
- class GHI::Issue
2
- attr_reader :number, :title, :body, :votes, :state, :user, :created_at,
3
- :updated_at, :labels
4
-
5
- def initialize(options = {})
6
- @number = options["number"]
7
- @title = options["title"]
8
- @body = options["body"]
9
- @votes = options["votes"]
10
- @state = options["state"]
11
- @user = options["user"]
12
- @created_at = options["created_at"]
13
- @updated_at = options["updated_at"]
14
- @labels = options["labels"]
15
- end
16
-
17
- #-
18
- # REFACTOR: This code is duplicated from cli.rb:gets_from_editor.
19
- #+
20
- def ==(other_issue)
21
- case other_issue
22
- when Array
23
- other_title = other_issue.first.strip
24
- other_body = other_issue[1..-1].join.sub(/\b\n\b/, " ").strip
25
- title == other_title && body == other_body
26
- else
27
- super other_issue
28
- end
29
- end
30
- end
data/spec/ghi/api_spec.rb DELETED
@@ -1,218 +0,0 @@
1
- $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
2
- require "ghi"
3
- require "ghi/api"
4
- require "ghi/issue"
5
- include GHI
6
-
7
- ISSUES_YAML = <<-YAML
8
- ---
9
- issues:
10
- - number: 1
11
- votes: 0
12
- created_at: 2009-04-17 14:55:33 -07:00
13
- body: my sweet, sweet issue
14
- title: new issue
15
- updated_at: 2009-04-17 14:55:33 -07:00
16
- user: schacon
17
- state: open
18
- - number: 2
19
- votes: 0
20
- created_at: 2009-04-17 15:16:47 -07:00
21
- body: the body of a second issue
22
- title: another issue
23
- updated_at: 2009-04-17 15:16:47 -07:00
24
- user: schacon
25
- state: open
26
- YAML
27
-
28
- ISSUE_YAML = <<-YAML
29
- ---
30
- issue:
31
- number: 1
32
- votes: 0
33
- created_at: 2009-04-17 14:55:33 -07:00
34
- body: my sweet, sweet issue
35
- title: new issue
36
- updated_at: 2009-04-17 14:55:33 -07:00
37
- user: schacon
38
- state: open
39
- YAML
40
-
41
- LABELS_YAML = <<-YAML
42
- ---
43
- labels:
44
- - testing
45
- - test_label
46
- YAML
47
-
48
- COMMENT_YAML = <<-YAML
49
- ---
50
- comment:
51
- comment: this is amazing
52
- status: saved
53
- YAML
54
-
55
- describe GHI::API do
56
- it "should require user and repo" do
57
- proc { API.new(nil, nil) }.should raise_error(API::InvalidConnection)
58
- proc { API.new("u", nil) }.should raise_error(API::InvalidConnection)
59
- proc { API.new(nil, "r") }.should raise_error(API::InvalidConnection)
60
- proc { API.new("u", "r") }.should_not raise_error(API::InvalidConnection)
61
- end
62
-
63
- describe "requests" do
64
- before :each do
65
- @api = API.new "stephencelis", "ghi"
66
- GHI.stub!(:login).and_return "stephencelis"
67
- GHI.stub!(:token).and_return "token"
68
-
69
- @http = mock(Net::HTTP)
70
- @http.stub(:start) { |l| l.call }
71
- end
72
-
73
- it "should substitute url tokens" do
74
- @api.send(:path, :open).should ==
75
- "/api/v2/yaml/issues/open/stephencelis/ghi"
76
- @api.send(:path, :show, 1).should ==
77
- "/api/v2/yaml/issues/show/stephencelis/ghi/1"
78
- @api.send(:path, :search, :open, "me").should ==
79
- "/api/v2/yaml/issues/search/stephencelis/ghi/open/me"
80
- @api.send(:path, "label/add", "me").should ==
81
- "/api/v2/yaml/issues/label/add/stephencelis/ghi/me"
82
- end
83
-
84
- it "should process gets" do
85
- path = "/api/v2/yaml/issues/open/stephencelis/ghi"
86
- query = "?login=stephencelis&token=token"
87
- @api.stub!(:path).and_return path
88
- req = mock(Net::HTTPRequest)
89
- res = mock(Net::HTTPResponse)
90
- Net::HTTP.should_receive(:new).once.and_return @http
91
- Net::HTTP::Get.should_receive(:new).once.with(path + query).
92
- and_return req
93
- @http.should_receive(:request).once.with(req).and_return res
94
- res.should_receive(:body).once.and_return ISSUES_YAML
95
- @api.list
96
- end
97
-
98
- it "should process posts" do
99
- path = "/api/v2/yaml/issues/open/stephencelis/ghi"
100
- query = { "login" => "stephencelis",
101
- "token" => "token",
102
- "title" => "Title",
103
- "body" => "Body" }
104
- @api.stub!(:path).and_return path
105
- req = mock(Net::HTTPRequest)
106
- res = mock(Net::HTTPResponse)
107
- Net::HTTP.should_receive(:new).once.and_return @http
108
- Net::HTTP::Post.should_receive(:new).once.with(path).and_return req
109
- req.should_receive(:set_form_data).once
110
- @http.should_receive(:request).once.with(req).and_return res
111
- res.should_receive(:body).once.and_return ISSUE_YAML
112
- @api.open "Title", "Body"
113
- end
114
-
115
- def expect_get_response(body)
116
- req = mock(Net::HTTPRequest)
117
- res = mock(Net::HTTPResponse)
118
- Net::HTTP.should_receive(:new).once.and_return @http
119
- Net::HTTP::Get.should_receive(:new).once.and_return req
120
- @http.should_receive(:request).once.with(req).and_return res
121
- res.should_receive(:body).once.and_return body
122
- end
123
-
124
- def expect_post_response(body)
125
- req = mock(Net::HTTPRequest)
126
- res = mock(Net::HTTPResponse)
127
- Net::HTTP.should_receive(:new).once.and_return @http
128
- Net::HTTP::Post.should_receive(:new).once.and_return req
129
- req.should_receive(:set_form_data).once
130
- @http.should_receive(:request).once.with(req).and_return res
131
- res.should_receive(:body).once.and_return body
132
- end
133
-
134
- it "should search open by default" do
135
- @api.should_receive(:path).with(:search, :open, "me").and_return "u"
136
- expect_get_response ISSUES_YAML
137
- issues = @api.search "me"
138
- issues.should be_an_instance_of(Array)
139
- issues.each { |issue| issue.should be_an_instance_of(Issue) }
140
- end
141
-
142
- it "should search closed" do
143
- @api.should_receive(:path).with(:search, :closed, "me").and_return "u"
144
- expect_get_response ISSUES_YAML
145
- @api.search "me", :closed
146
- end
147
-
148
- it "should list open by default" do
149
- @api.should_receive(:path).with(:list, :open).and_return "u"
150
- expect_get_response ISSUES_YAML
151
- issues = @api.list
152
- issues.should be_an_instance_of(Array)
153
- issues.each { |issue| issue.should be_an_instance_of(Issue) }
154
- end
155
-
156
- it "should list closed" do
157
- @api.should_receive(:path).with(:list, :closed).and_return "u"
158
- expect_get_response ISSUES_YAML
159
- @api.list :closed
160
- end
161
-
162
- it "should show" do
163
- @api.should_receive(:path).with(:show, 1).and_return "u"
164
- expect_get_response ISSUE_YAML
165
- @api.show(1).should be_an_instance_of(Issue)
166
- end
167
-
168
- it "should open" do
169
- @api.should_receive(:path).with(:open).and_return "u"
170
- expect_post_response ISSUE_YAML
171
- @api.open("Title", "Body").should be_an_instance_of(Issue)
172
- end
173
-
174
- it "should edit" do
175
- @api.should_receive(:path).with(:edit, 1).and_return "u"
176
- expect_post_response ISSUE_YAML
177
- @api.edit(1, "Title", "Body").should be_an_instance_of(Issue)
178
- end
179
-
180
- it "should close" do
181
- @api.should_receive(:path).with(:close, 1).and_return "u"
182
- expect_post_response ISSUE_YAML
183
- @api.close(1).should be_an_instance_of(Issue)
184
- end
185
-
186
- it "should reopen" do
187
- @api.should_receive(:path).with(:reopen, 1).and_return "u"
188
- expect_post_response ISSUE_YAML
189
- @api.reopen(1).should be_an_instance_of(Issue)
190
- end
191
-
192
- it "should add labels" do
193
- @api.should_receive(:path).with("label/add", 1, "l").and_return "u"
194
- expect_post_response LABELS_YAML
195
- @api.add_label(1, "l").should be_an_instance_of(Array)
196
- end
197
-
198
- it "should remove labels" do
199
- @api.should_receive(:path).with("label/remove", 1, "l").and_return "u"
200
- expect_post_response LABELS_YAML
201
- @api.remove_label(1, "l").should be_an_instance_of(Array)
202
- end
203
-
204
- it "should comment, and escape values" do
205
- @api.should_receive(:path).with(:comment, 1).and_return "u"
206
-
207
- req = mock(Net::HTTPRequest)
208
- res = mock(Net::HTTPResponse)
209
- Net::HTTP.should_receive(:new).once.and_return @http
210
- Net::HTTP::Post.should_receive(:new).once.and_return req
211
- req.should_receive(:set_form_data).once
212
- @http.should_receive(:request).once.with(req).and_return res
213
- res.should_receive(:body).once.and_return COMMENT_YAML
214
-
215
- @api.comment(1, "Comment&so").should be_an_instance_of(Hash)
216
- end
217
- end
218
- end
data/spec/ghi/cli_spec.rb DELETED
@@ -1,267 +0,0 @@
1
- require "ghi"
2
- require "ghi/api"
3
- require "ghi/cli"
4
-
5
- describe GHI::CLI::Executable do
6
- before :each do
7
- @cli = GHI::CLI::Executable.new
8
- @cli.stub!(:api).and_return(mock(GHI::API))
9
- $stdout.stub! :close_write
10
- IO.stub!(:popen).and_return $stdout
11
- end
12
-
13
- describe "parsing" do
14
- describe "with well-formed arguments" do
15
- before :each do
16
- @user, @repo = "local_user_host", "ghi"
17
- @action = @state = @number = @term =
18
- @title = @body = @tag = @comment = nil
19
- end
20
-
21
- after :each do
22
- @cli.should_receive(@action)
23
- @cli.parse! Array(@args)
24
- @cli.action.should == @action
25
- @cli.state.should == (@state || :open)
26
- @cli.number.should == @number
27
- @cli.search_term.should == @term
28
- @cli.title.should == @title
29
- @cli.body.should == @body
30
- @cli.user.should == @user
31
- @cli.repo.should == @repo
32
- @cli.tag.should == @tag
33
- if @commenting
34
- @cli.should be_commenting
35
- else
36
- @cli.should_not be_commenting
37
- end
38
- end
39
-
40
- it "should always parse -r" do
41
- @args = ["-rremoteuser/remoterepo", "-l"]
42
- @action, @state, @user, @repo = :list, :open, "remoteuser", "remoterepo"
43
- end
44
-
45
- describe "inside a repository" do
46
- after :each do
47
- @cli.stub!(:`).and_return "stub@github.com:#@user/#@repo.git"
48
- end
49
-
50
- it "should parse empty as list open" do
51
- @action, @state = :list, :open
52
- end
53
-
54
- it "should parse -l as list open" do
55
- @args = ["-l"]
56
- @action, @state = :list, :open
57
- end
58
-
59
- it "should parse -l as list open" do
60
- @args = ["-l"]
61
- @action, @state = :list, :open
62
- end
63
-
64
- it "should parse -lo as list open" do
65
- @args = ["-lo"]
66
- @action, @state = :list, :open
67
- end
68
-
69
- it "should parse -lc as list closed" do
70
- @args = ["-lc"]
71
- @action, @state = :list, :closed
72
- end
73
-
74
- it "should parse -l2 as show issue 2" do
75
- @args = ["-l2"]
76
- @action, @number = :show, 2
77
- end
78
-
79
- it "should parse -l 'term' as search open for 'term'" do
80
- @args = ["-l", "term"]
81
- @action, @state, @term = :search, :open, "term"
82
- end
83
-
84
- it "should parse -o as open new issue" do
85
- @args = ["-o"]
86
- @action = :open
87
- end
88
-
89
- it "should parse -o 'New Issue' as open issue with title 'New Issue'" do
90
- @args = ["-o", "New Issue"]
91
- @action, @title = :open, "New Issue"
92
- end
93
-
94
- it "should parse -om 'New Issue' as open issue with'New Issue'" do
95
- @args = ["-om", "New Issue"]
96
- @action, @title = :open, "New Issue"
97
- end
98
-
99
- it "should parse -o 'New Issue' -m as open 'New Issue' in $EDITOR" do
100
- @args = ["-o", "New Issue", "-m"]
101
- @action, @title, @commenting = :open, "New Issue", true
102
- end
103
-
104
- it "should parse -o 'Issue' -m 'Body' as open 'Issue' with 'Body'" do
105
- @args = ["-o", "Issue", "-m", "Body"]
106
- @action, @title, @body = :open, "Issue", "Body"
107
- end
108
-
109
- it "should parse -o2 as reopen issue 2" do
110
- @args = ["-o2"]
111
- @action, @number = :reopen, 2
112
- end
113
-
114
- it "should parse -o2 -m as reopen issue 2 with a comment" do
115
- @args = ["-o2", "-m"]
116
- @action, @number, @commenting = :reopen, 2, true
117
- end
118
-
119
- it "should parse -o2 -m 'Comment' as reopen issue 2" do
120
- @args = ["-o2", "-m", "Comment"]
121
- @action, @number, @body = :reopen, 2, "Comment"
122
- end
123
-
124
- it "should parse -ol as list open" do
125
- @args = ["-ol"]
126
- @action, @state = :list, :open
127
- end
128
-
129
- it "should parse -ou as return open issues url" do
130
- @args = ["-ou"]
131
- @action = :url # Should state be :open?
132
- end
133
-
134
- it "should parse -cl as list closed" do
135
- @args = ["-cl"]
136
- @action, @state = :list, :closed
137
- end
138
-
139
- it "should parse -c2 as close issue 2" do
140
- @args = ["-c2"]
141
- @action, @number = :close, 2
142
- end
143
-
144
- it "should parse -c2 -m as close issue 2 with a comment" do
145
- @args = ["-c2", "-m"]
146
- @action, @number, @commenting = :close, 2, true
147
- end
148
-
149
- it "should parse -c2 -m 'Fixed' as close issue 2 with 'Fixed'" do
150
- @args = ["-c2", "-m", "Fixed"]
151
- @action, @number, @body = :close, 2, "Fixed"
152
- end
153
-
154
- it "should parse -m2 -c as close issue 2 with a comment" do
155
- @args = ["-m2", "-c"]
156
- @action, @number, @commenting = :close, 2, true
157
- end
158
-
159
- it "should parse -cu as return closed issues url" do
160
- @args = ["-cu"]
161
- @action, @state = :url, :closed
162
- end
163
-
164
- it "should parse -e2 as edit issue 2" do
165
- @args = ["-e2"]
166
- @action, @number = :edit, 2
167
- end
168
-
169
- it "should parse -rlocalrepo as localuser/localrepo" do
170
- GHI.stub!(:login).and_return "localuser"
171
- @args = ["-rlocalrepo", "-l"]
172
- @action, @state, @user, @repo = :list, :open, "localuser", "localrepo"
173
- end
174
-
175
- it "should parse -rremoteuser/remoterepo as remoteuser/remoterepo" do
176
- @args = ["-rremoteuser/remoterepo", "-l"]
177
- @action, @state, @user, @repo = :list, :open, "remoteuser", "remoterepo"
178
- end
179
-
180
- it "should parse -rremoteuser/remoterepo as a later argument" do
181
- @args = ["-1", "-rremoteuser/remoterepo"]
182
- @action, @number, @user, @repo = :show, 1, "remoteuser", "remoterepo"
183
- end
184
-
185
- it "should parse -t2 'tag' as label issue 2 with 'tag'" do
186
- @args = ["-t2", "tag"]
187
- @action, @number, @tag = :label, 2, "tag"
188
- end
189
-
190
- it "should parse -d2 'tag' as remove label 'tag' from issue 2" do
191
- @args = ["-d2", "tag"]
192
- @action, @number, @tag = :unlabel, 2, "tag"
193
- end
194
-
195
- it "should parse -m2 as comment on issue 2" do
196
- @args = ["-m2"]
197
- @action, @number, @commenting = :comment, 2, true
198
- end
199
-
200
- it "should parse -m2 'Comment' as comment 'Comment' on issue 2" do
201
- @args = ["-m2", "Comment"]
202
- @action, @number, @body = :comment, 2, "Comment"
203
- end
204
-
205
- it "should parse -u as return open issues url" do
206
- @args = ["-u"]
207
- @action = :url # Should state be :open?
208
- end
209
-
210
- it "should parse -uo as return open issues url" do
211
- @args = ["-uo"]
212
- @action = :url # Should state be :open?
213
- end
214
-
215
- it "should parse -uc as return open issues url" do
216
- @args = ["-uc"]
217
- @action, @state = :url, :closed
218
- end
219
-
220
- it "should parse -u2 as return issue 2 url" do
221
- @args = ["-u2"]
222
- @action, @number = :url, 2
223
- end
224
-
225
- it "should parse -uu as return unread issues url" do
226
- @args = ["-uu"]
227
- @action, @state = :url, :unread
228
- end
229
- end
230
- end
231
-
232
- describe "with malformed arguments" do
233
- before :each do
234
- @cli.should_receive :warn
235
- @cli.should_receive(:exit).with 1
236
- end
237
-
238
- it "should exit with -e" do
239
- @cli.should_receive :puts
240
- @cli.parse! ["-e"]
241
- end
242
-
243
- it "should exit with -e 'invalid'" do
244
- @cli.should_receive :puts
245
- @cli.parse! ["-e", "invalid"]
246
- end
247
-
248
- it "should exit with -c as list closed" do
249
- @cli.parse! ["-c"]
250
- end
251
-
252
- it "should exit with -r" do
253
- @cli.should_receive :puts
254
- @cli.parse! ["-r"]
255
- end
256
-
257
- it "should exit with -t" do
258
- @cli.should_receive :puts
259
- @cli.parse! ["-t"]
260
- end
261
-
262
- it "should exit with -t2" do
263
- @cli.parse! ["-t2"]
264
- end
265
- end
266
- end
267
- end