git_reflow 0.7.4 → 0.7.5

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.
@@ -42,6 +42,7 @@ describe GitReflow::GitServer::GitHub::PullRequest do
42
42
 
43
43
  github.class.stub(:remote_user).and_return(user)
44
44
  github.class.stub(:remote_repo_name).and_return(repo)
45
+ allow(GitReflow::GitServer::PullRequest).to receive(:approval_regex).and_return(/(?i-mx:lgtm|looks good to me|:\+1:|:thumbsup:|:shipit:)/)
45
46
  end
46
47
 
47
48
  describe '#initialize(options)' do
@@ -64,21 +65,43 @@ describe GitReflow::GitServer::GitHub::PullRequest do
64
65
  end
65
66
 
66
67
  describe '#comments' do
67
- before do
68
- FakeGitHub.new(
69
- repo_owner: user,
70
- repo_name: repo,
71
- pull_request: {
72
- number: existing_pull_request.number,
73
- comments: [{author: comment_author}]
74
- },
75
- issue: {
76
- number: existing_pull_request.number,
77
- comments: [{author: comment_author}]
78
- })
68
+ context "Testing Appending of Comments" do
69
+ before do
70
+ FakeGitHub.new(
71
+ repo_owner: user,
72
+ repo_name: repo,
73
+ pull_request: {
74
+ number: existing_pull_request.number,
75
+ comments: [{author: comment_author}]
76
+ },
77
+ issue: {
78
+ number: existing_pull_request.number,
79
+ comments: [{author: comment_author}]
80
+ })
81
+ end
82
+ specify { expect(subject.comments).to eql(existing_pull_comments.to_a + existing_issue_comments.to_a) }
79
83
  end
80
84
 
81
- specify { expect(subject.comments).to eql(existing_pull_comments.to_a + existing_issue_comments.to_a) }
85
+ context "Testing Nil Comments" do
86
+ before do
87
+ stub_request(:get, "https://api.github.com/repos/reenhanced/repo/pulls/2/comments?access_token=a1b2c3d4e5f6g7h8i9j0").
88
+ with(:headers => {'Accept'=>'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', 'Accept-Charset'=>'utf-8', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'token a1b2c3d4e5f6g7h8i9j0', 'User-Agent'=>'Github API Ruby Gem 0.12.4'}).
89
+ to_return(:status => 200, :body => "", :headers => {})
90
+
91
+ FakeGitHub.new(
92
+ repo_owner: user,
93
+ repo_name: repo,
94
+ pull_request: {
95
+ number: existing_pull_request.number,
96
+ comments: nil
97
+ },
98
+ issue: {
99
+ number: existing_pull_request.number,
100
+ comments: nil
101
+ })
102
+ end
103
+ specify { expect(subject.comments).to eql([]) }
104
+ end
82
105
  end
83
106
 
84
107
  describe '#reviewers' do
@@ -99,7 +122,131 @@ describe GitReflow::GitServer::GitHub::PullRequest do
99
122
  })
100
123
  end
101
124
 
102
- specify { expect(subject.reviewers).to eql(['tito', 'bobby', 'randy']) }
125
+ specify { expect(subject.reviewers).to eq(['tito', 'bobby', 'randy']) }
126
+ end
127
+
128
+
129
+ describe "#approved?" do
130
+
131
+ context "no approvals and build success" do
132
+ before do
133
+ FakeGitHub.new(
134
+ repo_owner: user,
135
+ repo_name: repo,
136
+ pull_request: {
137
+ number: existing_pull_request.number,
138
+ owner: existing_pull_request.head.user.login,
139
+ comments: []
140
+ })
141
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("0")
142
+ end
143
+ specify { expect(subject.approved?).to be_truthy }
144
+ end
145
+
146
+ context "all commenters must approve and minimum_approvals is nil" do
147
+ before do
148
+ FakeGitHub.new(
149
+ repo_owner: user,
150
+ repo_name: repo,
151
+ pull_request: {
152
+ number: existing_pull_request.number,
153
+ owner: existing_pull_request.head.user.login,
154
+ comments: []
155
+ })
156
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return(nil)
157
+ allow(subject).to receive(:has_comments?).and_return(true)
158
+ allow(subject).to receive(:approvals).and_return(["Simon"])
159
+ allow(subject).to receive(:reviewers_pending_response).and_return([])
160
+ end
161
+ specify { expect(subject.approved?).to be_truthy }
162
+ end
163
+
164
+ context "all commenters must approve but we have no pending reviewers" do
165
+ before do
166
+ FakeGitHub.new(
167
+ repo_owner: user,
168
+ repo_name: repo,
169
+ pull_request: {
170
+ number: existing_pull_request.number,
171
+ owner: existing_pull_request.head.user.login,
172
+ comments: []
173
+ })
174
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("")
175
+ allow(subject).to receive(:has_comments?).and_return(true)
176
+ allow(subject).to receive(:approvals).and_return(["Simon"])
177
+ allow(subject).to receive(:reviewers_pending_response).and_return([])
178
+ end
179
+ specify { expect(subject.approved?).to be_truthy }
180
+ end
181
+
182
+ context "all commenters must approve but we have 1 pending reviewer" do
183
+ before do
184
+ FakeGitHub.new(
185
+ repo_owner: user,
186
+ repo_name: repo,
187
+ pull_request: {
188
+ number: existing_pull_request.number,
189
+ owner: existing_pull_request.head.user.login,
190
+ comments: []
191
+ })
192
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("")
193
+ allow(subject).to receive(:has_comments?).and_return(true)
194
+ allow(subject).to receive(:approvals).and_return(["Simon"])
195
+ allow(subject).to receive(:reviewers_pending_response).and_return(["Simon"])
196
+ end
197
+ specify { expect(subject.approved?).to be_falsy }
198
+ end
199
+
200
+ context "2 approvals required but we only have 1 approval" do
201
+ before do
202
+ FakeGitHub.new(
203
+ repo_owner: user,
204
+ repo_name: repo,
205
+ pull_request: {
206
+ number: existing_pull_request.number,
207
+ owner: existing_pull_request.head.user.login,
208
+ comments: []
209
+ })
210
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
211
+ allow(subject).to receive(:approvals).and_return(["Simon"])
212
+ allow(subject).to receive(:last_comment).and_return("LGTM")
213
+ end
214
+ specify { expect(subject.approved?).to be_falsy }
215
+ end
216
+
217
+ context "2 approvals required and we have 2 approvals but last comment is not approval" do
218
+ before do
219
+ FakeGitHub.new(
220
+ repo_owner: user,
221
+ repo_name: repo,
222
+ pull_request: {
223
+ number: existing_pull_request.number,
224
+ owner: existing_pull_request.head.user.login,
225
+ comments: []
226
+ })
227
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
228
+ allow(subject).to receive(:approvals).and_return(["Simon", "Peter"])
229
+ allow(subject).to receive(:last_comment).and_return("Boo")
230
+ end
231
+ specify { expect(subject.approved?).to be_falsy }
232
+ end
233
+
234
+ context "2 approvals required and we have 2 approvals and last comment is approval" do
235
+ before do
236
+ FakeGitHub.new(
237
+ repo_owner: user,
238
+ repo_name: repo,
239
+ pull_request: {
240
+ number: existing_pull_request.number,
241
+ owner: existing_pull_request.head.user.login,
242
+ comments: []
243
+ })
244
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
245
+ allow(subject).to receive(:approvals).and_return(["Simon", "Peter"])
246
+ allow(subject).to receive(:last_comment).and_return("LGTM")
247
+ end
248
+ specify { expect(subject.approved?).to be_truthy }
249
+ end
103
250
  end
104
251
 
105
252
  describe '#approvals' do
@@ -195,9 +342,13 @@ describe GitReflow::GitServer::GitHub::PullRequest do
195
342
  owner: existing_pull_request.head.user.login,
196
343
  comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
197
344
  })
345
+
346
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:approval_regex).and_return(/(?i-mx:lgtm|looks good to me|:\+1:|:thumbsup:|:shipit:)/)
198
347
  end
199
348
 
200
- specify { expect(subject.approvals).to eq(['tito', 'ringo']) }
349
+ context "2 approvals" do
350
+ specify { expect(subject.approvals).to eq(['tito', 'ringo']) }
351
+ end
201
352
 
202
353
  context "but a new commit has been introduced" do
203
354
  before do
@@ -4,6 +4,7 @@ describe GitReflow::GitServer::PullRequest do
4
4
  let(:pull_request) { Fixture.new('pull_requests/external_pull_request.json').to_json_hashie }
5
5
  let(:github) { stub_github_with({ user: 'reenhanced', repo: 'repo', pull: pull_request }) }
6
6
  let!(:github_api) { github.connection }
7
+ let(:git_server) { GitReflow::GitServer::GitHub.new {} }
7
8
 
8
9
  describe "#good_to_merge?(options)" do
9
10
  subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
@@ -20,9 +21,17 @@ describe GitReflow::GitServer::PullRequest do
20
21
  # setup initial valid state
21
22
  allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
22
23
  GitReflow.git_server.stub(:find_open_pull_request).with({from: 'new-feature', to: 'master'}).and_return(pull_request)
23
- end
24
+
25
+ # stubs approvals and last_comment conditions to default to true
26
+ pull_request.stub(:approvals).and_return(["Simon", "John"])
27
+ pull_request.stub_chain(:last_comment, :match).and_return(true)
28
+ allow(GitReflow::GitServer::PullRequest).to receive(:minimum_approvals).and_return("2")
29
+ allow(GitReflow::GitServer::PullRequest).to receive(:approval_regex).and_return(/(?i-mx:lgtm|looks good to me|:\+1:|:thumbsup:|:shipit:)/)
24
30
 
25
- specify { expect(subject.good_to_merge?).to eq(true) }
31
+ end
32
+ context "with no status" do
33
+ specify { expect(subject.good_to_merge?).to eq(true) }
34
+ end
26
35
 
27
36
  context "with build status" do
28
37
  context "of 'success'" do
@@ -36,13 +45,45 @@ describe GitReflow::GitServer::PullRequest do
36
45
  end
37
46
  end
38
47
 
48
+ # Need at least 1 comment for you to merge
39
49
  context "with no comments" do
40
- before { allow(subject).to receive(:has_comments?).and_return(false) }
50
+ before {
51
+ allow(subject).to receive(:has_comments?).and_return(false)
52
+ allow(subject).to receive(:build_status).and_return('success')
53
+ allow(subject).to receive(:approvals).and_return(["Simon", "John"])
54
+ }
41
55
  specify { expect(subject.good_to_merge?).to eq(true) }
42
56
  context "and no approvals" do
43
- before { allow(subject).to receive(:approvals?).and_return([]) }
44
- specify { expect(subject.good_to_merge?).to eq(true) }
57
+ before { allow(subject).to receive(:approvals).and_return([]) }
58
+ specify { expect(subject.good_to_merge?).to eq(false) }
59
+ end
60
+ end
61
+
62
+ context "with 1 approval" do
63
+ before do
64
+ allow(subject).to receive(:reviewers).and_return(['bob'])
65
+ allow(subject).to receive(:approvals).and_return(['joe'])
66
+ end
67
+ specify { expect(subject.good_to_merge?).to eq(false) }
68
+ end
69
+
70
+ context "with 2 approvals" do
71
+ before do
72
+ allow(subject).to receive(:reviewers).and_return(['bob'])
73
+ allow(subject).to receive(:approvals).and_return(['joe', 'bob'])
74
+ allow(subject).to receive(:last_comment).and_return('hi')
75
+ allow(subject).to receive(:build_status).and_return('success')
76
+ end
77
+ specify { expect(subject.good_to_merge?).to eq(false) }
78
+ end
79
+
80
+ context "with 2 approvals and last comment LGTM" do
81
+ before do
82
+ allow(subject).to receive(:reviewers).and_return(['bob'])
83
+ allow(subject).to receive(:approvals).and_return(['joe', 'bob'])
84
+ allow(subject).to receive(:last_comment).and_return('LGTM')
45
85
  end
86
+ specify { expect(subject.good_to_merge?).to eq(true) }
46
87
  end
47
88
 
48
89
  context "with comments" do
@@ -66,28 +107,286 @@ describe GitReflow::GitServer::PullRequest do
66
107
  end
67
108
  end
68
109
 
69
- describe "#display_pull_request_summary" do
70
- subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request).display_pull_request_summary }
110
+ describe "#approved?" do
111
+ subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
71
112
 
72
- before do
73
- FakeGitHub.new(
113
+ context "no approvals and build success" do
114
+ before do
115
+ FakeGitHub.new(
74
116
  repo_owner: 'reenhanced',
75
117
  repo_name: 'repo',
76
- pull_request: {
77
- number: pull_request.number,
78
- owner: pull_request.head.user.login,
79
- comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
80
- })
81
- allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
82
- GitReflow.git_server.stub(:find_open_pull_request).with({from: 'new-external-feature', to: 'master'}).and_return(pull_request)
118
+ pull_request: {
119
+ number: pull_request.number,
120
+ owner: pull_request.head.user.login,
121
+ comments: []
122
+ })
123
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
124
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("0")
125
+ end
126
+ specify { expect(subject.approved?).to be_truthy }
127
+ end
128
+
129
+ context "all commenters must approve and minimum_approvals is nil" do
130
+ before do
131
+ FakeGitHub.new(
132
+ repo_owner: 'reenhanced',
133
+ repo_name: 'repo',
134
+ pull_request: {
135
+ number: pull_request.number,
136
+ owner: pull_request.head.user.login,
137
+ comments: []
138
+ })
139
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
140
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return(nil)
141
+ allow(subject).to receive(:approvals).and_return(["Simon"])
142
+ allow(subject).to receive(:has_comments?).and_return(true)
143
+ allow(subject).to receive(:reviewers_pending_response).and_return([])
144
+ end
145
+ specify { expect(subject.approved?).to be_truthy }
146
+ end
147
+
148
+ context "all commenters must approve but we have no pending reviewers" do
149
+ before do
150
+ FakeGitHub.new(
151
+ repo_owner: 'reenhanced',
152
+ repo_name: 'repo',
153
+ pull_request: {
154
+ number: pull_request.number,
155
+ owner: pull_request.head.user.login,
156
+ comments: []
157
+ })
158
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
159
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("")
160
+ allow(subject).to receive(:has_comments?).and_return(true)
161
+ allow(subject).to receive(:approvals).and_return(["Simon"])
162
+ allow(subject).to receive(:reviewers_pending_response).and_return([])
163
+ end
164
+ specify { expect(subject.approved?).to be_truthy }
165
+ end
166
+
167
+ context "all commenters must approve but we have 1 pending reviewer" do
168
+ before do
169
+ FakeGitHub.new(
170
+ repo_owner: 'reenhanced',
171
+ repo_name: 'repo',
172
+ pull_request: {
173
+ number: pull_request.number,
174
+ owner: pull_request.head.user.login,
175
+ comments: []
176
+ })
177
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
178
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("")
179
+ allow(subject).to receive(:has_comments?).and_return(true)
180
+ allow(subject).to receive(:approvals).and_return(["Simon"])
181
+ allow(subject).to receive(:reviewers_pending_response).and_return(["Simon"])
182
+ end
183
+ specify { expect(subject.approved?).to be_falsy }
184
+ end
185
+
186
+ context "2 approvals required but we only have 1 approval" do
187
+ before do
188
+ FakeGitHub.new(
189
+ repo_owner: 'reenhanced',
190
+ repo_name: 'repo',
191
+ pull_request: {
192
+ number: pull_request.number,
193
+ owner: pull_request.head.user.login,
194
+ comments: []
195
+ })
196
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
197
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
198
+ allow(subject).to receive(:approvals).and_return(["Simon"])
199
+ allow(subject).to receive(:last_comment).and_return("LGTM")
200
+ end
201
+ specify { expect(subject.approved?).to be_falsy }
202
+ end
203
+
204
+ context "2 approvals required and we have 2 approvals but last comment is not approval" do
205
+ before do
206
+ FakeGitHub.new(
207
+ repo_owner: 'reenhanced',
208
+ repo_name: 'repo',
209
+ pull_request: {
210
+ number: pull_request.number,
211
+ owner: pull_request.head.user.login,
212
+ comments: []
213
+ })
214
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
215
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
216
+ allow(subject).to receive(:approvals).and_return(["Simon", "Peter"])
217
+ allow(subject).to receive(:last_comment).and_return("Boo")
218
+ end
219
+ specify { expect(subject.approved?).to be_falsy }
220
+ end
221
+
222
+ context "2 approvals required and we have 2 approvals and last comment is approval" do
223
+ before do
224
+ FakeGitHub.new(
225
+ repo_owner: 'reenhanced',
226
+ repo_name: 'repo',
227
+ pull_request: {
228
+ number: pull_request.number,
229
+ owner: pull_request.head.user.login,
230
+ comments: []
231
+ })
232
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
233
+ allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
234
+ allow(subject).to receive(:approvals).and_return(["Simon", "Peter"])
235
+ allow(subject).to receive(:last_comment).and_return("LGTM")
236
+ end
237
+ specify { expect(subject.approved?).to be_truthy }
83
238
  end
239
+ end
240
+
241
+ describe "#rejection_message" do
242
+ subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
243
+
244
+ before do
245
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
246
+ end
247
+
248
+ context "Testing a Failure Build Status" do
249
+ before do
250
+ allow(subject).to receive(:build_status).and_return('failure')
251
+ end
252
+
253
+ specify { subject.rejection_message.should eq(": ") }
254
+ end
255
+
256
+ context "Testing Minimum Approvals Failure" do
257
+ before do
258
+ allow(subject).to receive(:build_status).and_return('success')
259
+ allow(subject).to receive(:approval_minimums_reached?).and_return(false)
260
+ allow(GitReflow::GitServer::PullRequest).to receive(:minimum_approvals).and_return("2")
261
+ end
262
+ specify { subject.rejection_message.should eq("You need approval from at least 2 users!") }
263
+ end
264
+
265
+ context "Testing Minimum Approvals Reached" do
266
+ before do
267
+ allow(subject).to receive(:build_status).and_return(nil)
268
+ allow(subject).to receive(:all_comments_addressed?).and_return(false)
269
+ allow(subject).to receive(:last_comment).and_return("Hello")
270
+ end
271
+ specify { subject.rejection_message.should eq("The last comment is holding up approval:\nHello") }
272
+ end
273
+
274
+ context "Testing All Comments Addressed" do
275
+ before do
276
+ allow(subject).to receive(:build_status).and_return('success')
277
+ allow(subject).to receive(:all_comments_addressed?).and_return(false)
278
+ allow(subject).to receive(:last_comment).and_return("Hello")
279
+ end
280
+ specify { subject.rejection_message.should eq("The last comment is holding up approval:\nHello") }
281
+ end
282
+
283
+ context "Testing All Comments Addressed" do
284
+ before do
285
+ allow(subject).to receive(:reviewers_pending_response).and_return(['Simon'])
286
+ allow(subject).to receive(:build?).and_return('success')
287
+ allow(subject).to receive(:all_comments_addressed?).and_return(true)
288
+ allow(subject).to receive(:approval_minimums_reached?).and_return(true)
289
+ end
290
+ specify { subject.rejection_message.should eq( "You still need a LGTM from: Simon") }
291
+ end
292
+
293
+ context "Testing Last Case" do
294
+ before do
295
+ allow(subject).to receive(:reviewers_pending_response).and_return([])
296
+ allow(subject).to receive(:build?).and_return('success')
297
+ allow(subject).to receive(:all_comments_addressed?).and_return(true)
298
+ allow(subject).to receive(:approval_minimums_reached?).and_return(true)
299
+ end
300
+ specify { subject.rejection_message.should eq("Your code has not been reviewed yet.") }
301
+ end
302
+ end
84
303
 
85
- it "displays relavent information about the pull request" do
86
- expect{ subject }.to have_output("branches: new-external-feature -> reenhanced:master")
87
- expect{ subject }.to have_output("number: #{pull_request.number}")
88
- expect{ subject }.to have_output("url: #{pull_request.html_url}")
89
- expect{ subject }.to have_output("reviewed by: #{"tito".colorize(:green)}, #{"ringo".colorize(:green)}")
90
- expect{ subject }.to have_output("Last comment: \":+1:\"")
304
+ describe "#all_comments_addressed" do
305
+ subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
306
+
307
+ before do
308
+ allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
309
+ end
310
+
311
+ context "Testing a Failure Case" do
312
+ before do
313
+ allow(subject).to receive(:minimum_approvals).and_return('2')
314
+ allow(subject).to receive(:approvals).and_return(['Simon'])
315
+ end
316
+ specify { subject.approval_minimums_reached?.should eq(true) }
317
+ end
318
+
319
+ context "Testing a Success Case" do
320
+ before do
321
+ allow(subject).to receive(:minimum_approvals).and_return('2')
322
+ allow(subject).to receive(:approvals).and_return(['Simon', 'John'])
323
+ end
324
+ specify { subject.approval_minimums_reached?.should eq(true) }
325
+ end
326
+
327
+ context "Testing Case with no minimum_approval" do
328
+ before do
329
+ allow(subject).to receive(:minimum_approvals).and_return('')
330
+ allow(subject).to receive(:approvals).and_return([])
331
+ end
332
+ specify { subject.approval_minimums_reached?.should eq(true) }
333
+ end
334
+ end
335
+
336
+ describe "#display_pull_request_summary" do
337
+ subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request).display_pull_request_summary }
338
+
339
+ context "Testing Pull Request Properties" do
340
+ before do
341
+ FakeGitHub.new(
342
+ repo_owner: 'reenhanced',
343
+ repo_name: 'repo',
344
+ pull_request: {
345
+ number: pull_request.number,
346
+ owner: pull_request.head.user.login,
347
+ comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
348
+ })
349
+ allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
350
+ GitReflow.git_server.stub(:find_open_pull_request).with({from: 'new-external-feature', to: 'master'}).and_return(pull_request)
351
+ end
352
+
353
+ it "displays relavent information about the pull request" do
354
+ expect{ subject }.to have_output("branches: new-external-feature -> reenhanced:master")
355
+ expect{ subject }.to have_output("number: #{pull_request.number}")
356
+ expect{ subject }.to have_output("url: #{pull_request.html_url}")
357
+ expect{ subject }.to have_output("reviewed by: #{"tito".colorize(:green)}, #{"ringo".colorize(:green)}")
358
+ expect{ subject }.to have_output("Last comment: \":+1:\"")
359
+ end
360
+ end
361
+
362
+ context "Testing Different LGTM Regex Expressions " do
363
+ before do
364
+ FakeGitHub.new(
365
+ repo_owner: 'reenhanced',
366
+ repo_name: 'repo',
367
+ pull_request: {
368
+ number: pull_request.number,
369
+ owner: pull_request.head.user.login,
370
+ comments: [
371
+ {author: 'tito', body: 'lgtm'},
372
+ {author: 'ringo', body: ':+1:'},
373
+ {author: 'Simon', body: ':shipit:'},
374
+ {author: 'Peter', body: 'looks good to me'},
375
+ {author: 'Johnny', body: 'LgTm'},
376
+ {author: 'Jacob', body: 'LOOKS GOOD TO ME'}
377
+ ]
378
+ })
379
+ allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
380
+ GitReflow.git_server.stub(:find_open_pull_request).with({from: 'new-external-feature', to: 'master'}).and_return(pull_request)
381
+ end
382
+
383
+ it "displays relavent information about the pull request" do
384
+ expect{ subject }.to have_output("branches: new-external-feature -> reenhanced:master")
385
+ expect{ subject }.to have_output("number: #{pull_request.number}")
386
+ expect{ subject }.to have_output("url: #{pull_request.html_url}")
387
+ expect{ subject }.to have_output("reviewed by: #{"tito".colorize(:green)}, #{"ringo".colorize(:green)}, #{"Simon".colorize(:green)}, #{"Peter".colorize(:green)}, #{"Johnny".colorize(:green)}, #{"Jacob".colorize(:green)}")
388
+ expect{ subject }.to have_output("Last comment: \"LOOKS GOOD TO ME\"")
389
+ end
91
390
  end
92
391
  end
93
392
  end