git-pr-release-roadrunner 0.0.1

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.
@@ -0,0 +1,514 @@
1
+ RSpec.describe Git::Pr::Release::CLI do
2
+ let(:configured_cli) {
3
+ cli = Git::Pr::Release::CLI.new
4
+ allow(cli).to receive(:host_and_repository_and_scheme) {
5
+ [nil, "motemen/git-pr-release", "https"]
6
+ }
7
+ allow(cli).to receive(:git_config).with(anything) { nil }
8
+ cli.configure
9
+ cli
10
+ }
11
+
12
+ describe "#start" do
13
+ subject { @cli.start }
14
+
15
+ before {
16
+ @cli = Git::Pr::Release::CLI.new
17
+
18
+ allow(@cli).to receive(:configure)
19
+ allow(@cli).to receive(:fetch_merged_prs) { merged_prs }
20
+ allow(@cli).to receive(:create_release_pr)
21
+ }
22
+
23
+ context "When merged_prs is empty" do
24
+ let(:merged_prs) { [] }
25
+ it {
26
+ is_expected.to eq 1
27
+ expect(@cli).to have_received(:configure)
28
+ expect(@cli).to have_received(:fetch_merged_prs)
29
+ expect(@cli).not_to have_received(:create_release_pr)
30
+ }
31
+ end
32
+
33
+ context "When merged_prs exists" do
34
+ let(:merged_prs) {
35
+ agent = Sawyer::Agent.new("http://example.com/") do |conn|
36
+ conn.builder.handlers.delete(Faraday::Adapter::NetHttp)
37
+ conn.adapter(:test, Faraday::Adapter::Test::Stubs.new)
38
+ end
39
+ pr_3 = Sawyer::Resource.new(agent, load_yaml("pr_3.yml"))
40
+ pr_4 = Sawyer::Resource.new(agent, load_yaml("pr_4.yml"))
41
+ [pr_3, pr_4]
42
+ }
43
+ it {
44
+ is_expected.to eq 0
45
+ expect(@cli).to have_received(:configure)
46
+ expect(@cli).to have_received(:fetch_merged_prs)
47
+ expect(@cli).to have_received(:create_release_pr).with(merged_prs)
48
+ }
49
+ end
50
+ end
51
+
52
+ describe "#configure" do
53
+ subject { @cli.configure }
54
+
55
+ before {
56
+ @cli = Git::Pr::Release::CLI.new
57
+
58
+ allow(@cli).to receive(:git_config).with(anything) { nil }
59
+ }
60
+
61
+ context "When default" do
62
+ before {
63
+ allow(@cli).to receive(:host_and_repository_and_scheme) {
64
+ [nil, "motemen/git-pr-release", "https"]
65
+ }
66
+ }
67
+
68
+ it "configured as default" do
69
+ subject
70
+
71
+ expect(Octokit.api_endpoint).to eq "https://api.github.com/"
72
+ expect(Octokit.web_endpoint).to eq "https://github.com/"
73
+
74
+ expect(@cli.repository).to eq "motemen/git-pr-release"
75
+ expect(@cli.production_branch).to eq "master"
76
+ expect(@cli.staging_branch).to eq "staging"
77
+ expect(@cli.template_path).to eq nil
78
+ expect(@cli.labels).to eq []
79
+ end
80
+ end
81
+
82
+ context "When GitHub Enterprise Server" do
83
+ before {
84
+ allow(@cli).to receive(:host_and_repository_and_scheme) {
85
+ ["example.com", "motemen/git-pr-release", "https"]
86
+ }
87
+ }
88
+ after {
89
+ Octokit.reset!
90
+ }
91
+
92
+ it "octokit is configured" do
93
+ subject
94
+
95
+ expect(Octokit.api_endpoint).to eq "https://example.com/api/v3/"
96
+ expect(Octokit.web_endpoint).to eq "https://example.com/"
97
+ end
98
+ end
99
+
100
+ describe "branches" do
101
+ context "When branches are set by ENV" do
102
+ around do |example|
103
+ original = ENV.to_hash
104
+ begin
105
+ ENV["GIT_PR_RELEASE_BRANCH_PRODUCTION"] = "prod"
106
+ ENV["GIT_PR_RELEASE_BRANCH_STAGING"] = "dev"
107
+ example.run
108
+ ensure
109
+ ENV.replace(original)
110
+ end
111
+ end
112
+
113
+ it "branches are configured" do
114
+ subject
115
+
116
+ expect(@cli.production_branch).to eq "prod"
117
+ expect(@cli.staging_branch).to eq "dev"
118
+ end
119
+ end
120
+
121
+ context "When branches are set by git_config" do
122
+ before {
123
+ allow(@cli).to receive(:git_config).with("branch.production") { "production" }
124
+ allow(@cli).to receive(:git_config).with("branch.staging") { "develop" }
125
+ }
126
+
127
+ it "branches are configured" do
128
+ subject
129
+
130
+ expect(@cli.production_branch).to eq "production"
131
+ expect(@cli.staging_branch).to eq "develop"
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "labels" do
137
+ context "With ENV" do
138
+ around do |example|
139
+ original = ENV.to_hash
140
+ begin
141
+ ENV["GIT_PR_RELEASE_LABELS"] = env_labels
142
+ example.run
143
+ ensure
144
+ ENV.replace(original)
145
+ end
146
+ end
147
+
148
+ context "string" do
149
+ let(:env_labels) { "release" }
150
+ it "set labels" do
151
+ subject
152
+ expect(@cli.labels).to eq ["release"]
153
+ end
154
+ end
155
+
156
+ context "comma separated string" do
157
+ let(:env_labels) { "release,release2" }
158
+ it "set labels" do
159
+ subject
160
+ expect(@cli.labels).to eq ["release", "release2"]
161
+ end
162
+ end
163
+
164
+ context "empty string" do
165
+ let(:env_labels) { "" }
166
+ it "set labels as default" do
167
+ subject
168
+ expect(@cli.labels).to eq []
169
+ end
170
+ end
171
+ end
172
+
173
+ context "With git_config" do
174
+ before {
175
+ allow(@cli).to receive(:git_config).with("labels") { "release" }
176
+ }
177
+
178
+ it "set labels" do
179
+ subject
180
+ expect(@cli.labels).to eq ["release"]
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ describe "#fetch_merged_prs" do
187
+ subject { @cli.fetch_merged_prs }
188
+
189
+ before {
190
+ @cli = configured_cli
191
+
192
+ agent = Sawyer::Agent.new("http://example.com/") do |conn|
193
+ conn.builder.handlers.delete(Faraday::Adapter::NetHttp)
194
+ conn.adapter(:test, Faraday::Adapter::Test::Stubs.new)
195
+ end
196
+
197
+ expect(@cli).to receive(:git).with(:'rev-parse', "--is-shallow-repository") { ["false\n"] }
198
+ expect(@cli).to receive(:git).with(:remote, "update", "origin") {
199
+ []
200
+ }
201
+
202
+ expect(@cli).to receive(:git).with(:log, "--merges", "--pretty=format:%P", "origin/master..origin/staging") {
203
+ <<~GIT_LOG.each_line
204
+ ad694b9c2b868e8801f9209f0ad5dd5458c49854 42bd43b80c973c8f348df3521745201be05bf194
205
+ b620bead10831d2e4e15be392e0a435d3470a0ad 5c977a1827387ac7b7a85c7b827ee119165f1823
206
+ GIT_LOG
207
+ }
208
+ expect(@cli).to receive(:git).with("ls-remote", "origin", "refs/pull/*/head") {
209
+ <<~GIT_LS_REMOTE.each_line
210
+ bbcd2a04ef394e91be44c24e93e52fdbca944060 refs/pull/1/head
211
+ 5c977a1827387ac7b7a85c7b827ee119165f1823 refs/pull/3/head
212
+ 42bd43b80c973c8f348df3521745201be05bf194 refs/pull/4/head
213
+ GIT_LS_REMOTE
214
+ }
215
+ expect(@cli).to receive(:git).with("merge-base", "5c977a1827387ac7b7a85c7b827ee119165f1823", "origin/master") {
216
+ "b620bead10831d2e4e15be392e0a435d3470a0ad".each_line
217
+ }
218
+ expect(@cli).to receive(:git).with("merge-base", "42bd43b80c973c8f348df3521745201be05bf194", "origin/master") {
219
+ "b620bead10831d2e4e15be392e0a435d3470a0ad".each_line
220
+ }
221
+
222
+ client = double(Octokit::Client)
223
+ @pr_3 = Sawyer::Resource.new(agent, load_yaml("pr_3.yml"))
224
+ @pr_4 = Sawyer::Resource.new(agent, load_yaml("pr_4.yml"))
225
+ expect(client).to receive(:pull_request).with("motemen/git-pr-release", 3) { @pr_3 }
226
+ expect(client).to receive(:pull_request).with("motemen/git-pr-release", 4) { @pr_4 }
227
+ allow(@cli).to receive(:client).with(no_args) { client }
228
+ }
229
+
230
+ it { is_expected.to eq [@pr_3, @pr_4] }
231
+ end
232
+
233
+ describe "#create_release_pr" do
234
+ subject { @cli.create_release_pr(@merged_prs) }
235
+
236
+ before {
237
+ @cli = configured_cli
238
+
239
+ @agent = Sawyer::Agent.new("http://example.com/") do |conn|
240
+ conn.builder.handlers.delete(Faraday::Adapter::NetHttp)
241
+ conn.adapter(:test, Faraday::Adapter::Test::Stubs.new)
242
+ end
243
+
244
+ @merged_prs = [
245
+ Sawyer::Resource.new(@agent, load_yaml("pr_3.yml")),
246
+ Sawyer::Resource.new(@agent, load_yaml("pr_4.yml")),
247
+ ]
248
+
249
+ allow(@cli).to receive(:detect_existing_release_pr) { existing_release_pr }
250
+ @pr_title = "Release 2020-01-04 16:51:09 +0900"
251
+ @pr_body = <<~BODY.chomp
252
+ - [ ] #3 Provides a creating release pull-request object for template @hakobe
253
+ - [ ] #4 use user who create PR if there is no assignee @motemen
254
+ BODY
255
+ allow(@cli).to receive(:build_and_merge_pr_title_and_body) {
256
+ [@pr_title, @pr_body]
257
+ }
258
+ allow(@cli).to receive(:update_release_pr)
259
+ @changed_files = [double(Sawyer::Resource)]
260
+ allow(@cli).to receive(:pull_request_files) { @changed_files }
261
+ }
262
+
263
+ context "When create_mode" do
264
+ before {
265
+ @created_pr = Sawyer::Resource.new(@agent, load_yaml("pr_1.yml"))
266
+ allow(@cli).to receive(:prepare_release_pr) { @created_pr }
267
+ }
268
+
269
+ let(:existing_release_pr) { nil }
270
+
271
+ it {
272
+ subject
273
+
274
+ expect(@cli).to have_received(:detect_existing_release_pr)
275
+ expect(@cli).to have_received(:prepare_release_pr)
276
+ expect(@cli).to have_received(:pull_request_files)
277
+ expect(@cli).to have_received(:build_and_merge_pr_title_and_body).with(@created_pr, @merged_prs, @changed_files)
278
+ expect(@cli).to have_received(:update_release_pr).with(@created_pr, @pr_title, @pr_body)
279
+ }
280
+ end
281
+
282
+ context "When not create_mode" do
283
+ before {
284
+ allow(@cli).to receive(:prepare_release_pr)
285
+ }
286
+
287
+ let(:existing_release_pr) { double(
288
+ number: 1023,
289
+ rels: { html: double(href: "https://github.com/motemen/git-pr-release/pull/1023") },
290
+ )}
291
+
292
+ it {
293
+ subject
294
+
295
+ expect(@cli).to have_received(:detect_existing_release_pr)
296
+ expect(@cli).to have_received(:pull_request_files).with(existing_release_pr)
297
+ expect(@cli).not_to have_received(:prepare_release_pr)
298
+ expect(@cli).to have_received(:build_and_merge_pr_title_and_body).with(existing_release_pr, @merged_prs, @changed_files)
299
+ expect(@cli).to have_received(:update_release_pr).with(existing_release_pr, @pr_title, @pr_body)
300
+ }
301
+ end
302
+
303
+ context "When dry_run with create_mode" do
304
+ before {
305
+ @created_pr = Sawyer::Resource.new(@agent, load_yaml("pr_1.yml"))
306
+ allow(@cli).to receive(:prepare_release_pr) { @created_pr }
307
+
308
+ @cli.instance_variable_set(:@dry_run, true)
309
+ }
310
+
311
+ let(:existing_release_pr) { nil }
312
+
313
+ it {
314
+ subject
315
+
316
+ expect(@cli).to have_received(:detect_existing_release_pr)
317
+ expect(@cli).not_to have_received(:prepare_release_pr)
318
+ expect(@cli).not_to have_received(:pull_request_files)
319
+ expect(@cli).to have_received(:build_and_merge_pr_title_and_body).with(nil, @merged_prs, [])
320
+ expect(@cli).not_to have_received(:update_release_pr).with(@created_pr, @pr_title, @pr_body)
321
+ }
322
+ end
323
+
324
+ context "When overwrite_description" do
325
+ before {
326
+ @cli.instance_variable_set(:@overwrite_description, true)
327
+ @new_pr_title = "2022-08-17 12:34:58 +0900"
328
+ @new_pr_body = <<~BODY.chomp
329
+ - [ ] #3 @hakobe
330
+ - [ ] #4 @hakobe
331
+ BODY
332
+ allow(@cli).to receive(:build_pr_title_and_body) {
333
+ [@new_pr_title, @new_pr_body]
334
+ }
335
+ }
336
+
337
+ let(:existing_release_pr) { double(
338
+ number: 1023,
339
+ rels: { html: double(href: "https://github.com/motemen/git-pr-release/pull/1023") },
340
+ )}
341
+
342
+ it {
343
+ subject
344
+
345
+ expect(@cli).not_to have_received(:build_and_merge_pr_title_and_body)
346
+ expect(@cli).to have_received(:update_release_pr).with(existing_release_pr, @new_pr_title, @new_pr_body)
347
+ }
348
+ end
349
+ end
350
+
351
+ describe "#prepare_release_pr" do
352
+ subject { @cli.prepare_release_pr }
353
+
354
+ before {
355
+ @cli = configured_cli
356
+
357
+ @client = double(Octokit::Client)
358
+ allow(@client).to receive(:create_pull_request)
359
+ allow(@cli).to receive(:client) { @client }
360
+ }
361
+
362
+ it {
363
+ subject
364
+
365
+ expect(@client).to have_received(:create_pull_request).with(
366
+ "motemen/git-pr-release",
367
+ "master",
368
+ "staging",
369
+ "Preparing release pull request...",
370
+ "", # empby body
371
+ )
372
+ }
373
+ end
374
+
375
+ describe "#build_and_merge_pr_title_and_body" do
376
+ subject { @cli.build_and_merge_pr_title_and_body(release_pr, @merged_prs, changed_files) }
377
+
378
+ before {
379
+ @cli = configured_cli
380
+
381
+ @merged_prs = [double(Sawyer::Resource)]
382
+ allow(@cli).to receive(:build_pr_title_and_body) { ["PR Title", "PR Body"] }
383
+ allow(@cli).to receive(:merge_pr_body) { "Merged Body" }
384
+ }
385
+
386
+ context "When release_pr exists" do
387
+ let(:release_pr) { double(body: "Old Body") }
388
+ let(:changed_files) { [double(Sawyer::Resource)] }
389
+
390
+ it {
391
+ is_expected.to eq ["PR Title", "Merged Body"]
392
+
393
+ expect(@cli).to have_received(:build_pr_title_and_body).with(release_pr, @merged_prs, changed_files, nil)
394
+ expect(@cli).to have_received(:merge_pr_body).with("Old Body", "PR Body")
395
+ }
396
+ end
397
+
398
+ context "When release_pr is nil" do
399
+ # = When dry_run with create_mode
400
+ let(:release_pr) { nil }
401
+ let(:changed_files) { [] }
402
+
403
+ it {
404
+ is_expected.to eq ["PR Title", "Merged Body"]
405
+
406
+ expect(@cli).to have_received(:build_pr_title_and_body).with(release_pr, @merged_prs, changed_files, nil)
407
+ expect(@cli).to have_received(:merge_pr_body).with("", "PR Body")
408
+ }
409
+ end
410
+ end
411
+
412
+ describe "#update_release_pr" do
413
+ subject { @cli.update_release_pr(@release_pr, "PR Title", "PR Body") }
414
+
415
+ before {
416
+ @cli = configured_cli
417
+
418
+ @release_pr = double(number: 1023)
419
+
420
+ @client = double(Octokit::Client)
421
+ allow(@client).to receive(:update_pull_request) { @release_pr }
422
+ allow(@client).to receive(:add_labels_to_an_issue)
423
+ allow(@cli).to receive(:client) { @client }
424
+ }
425
+
426
+ context "Without labels" do
427
+ it {
428
+ subject
429
+
430
+ expect(@client).to have_received(:update_pull_request).with(
431
+ "motemen/git-pr-release",
432
+ 1023,
433
+ {
434
+ title: "PR Title",
435
+ body: "PR Body",
436
+ }
437
+ )
438
+ expect(@client).not_to have_received(:add_labels_to_an_issue)
439
+ }
440
+ end
441
+
442
+ context "With labels" do
443
+ before {
444
+ allow(@cli).to receive(:labels) { ["release"] }
445
+ }
446
+ it {
447
+ subject
448
+
449
+ expect(@client).to have_received(:update_pull_request).with(
450
+ "motemen/git-pr-release",
451
+ 1023,
452
+ {
453
+ title: "PR Title",
454
+ body: "PR Body",
455
+ }
456
+ )
457
+ expect(@client).to have_received(:add_labels_to_an_issue).with(
458
+ "motemen/git-pr-release", 1023, ["release"]
459
+ )
460
+ }
461
+ end
462
+ end
463
+
464
+ describe "#detect_existing_release_pr" do
465
+ subject { @cli.detect_existing_release_pr }
466
+
467
+ before {
468
+ @cli = configured_cli
469
+
470
+ @client = double(Octokit::Client)
471
+ allow(@cli).to receive(:client).with(no_args) { @client }
472
+ }
473
+
474
+ context "When exists" do
475
+ before {
476
+ @release_pr = double(head: double(ref: "staging"), base: double(ref: "master"))
477
+ allow(@client).to receive(:pull_requests) { [@release_pr] }
478
+ }
479
+
480
+ it { is_expected.to eq @release_pr }
481
+ end
482
+
483
+ context "When not exists" do
484
+ before {
485
+ allow(@client).to receive(:pull_requests) { [] }
486
+ }
487
+
488
+ it { is_expected.to be_nil }
489
+ end
490
+ end
491
+
492
+ describe "#pull_request_files" do
493
+ subject { @cli.pull_request_files(@release_pr) }
494
+
495
+ before {
496
+ @cli = configured_cli
497
+
498
+ @release_pr = double(number: 1023)
499
+ @client = double(Octokit::Client)
500
+ @changed_files = [double(Sawyer::Resource)]
501
+ allow(@client).to receive(:pull_request_files) { @changed_files }
502
+ allow(@client).to receive(:auto_paginate=)
503
+ allow(@cli).to receive(:client) { @client }
504
+ }
505
+
506
+ it {
507
+ is_expected.to eq @changed_files
508
+
509
+ expect(@client).to have_received(:auto_paginate=).with(true)
510
+ expect(@client).to have_received(:pull_request_files).with("motemen/git-pr-release", 1023)
511
+ expect(@client).to have_received(:auto_paginate=).with(false)
512
+ }
513
+ end
514
+ end
@@ -0,0 +1,113 @@
1
+ RSpec.describe Git::Pr::Release do
2
+ include Git::Pr::Release::Util
3
+ before do
4
+ Timecop.freeze(Time.parse("2019-02-20 22:58:35"))
5
+
6
+ @stubs = Faraday::Adapter::Test::Stubs.new
7
+ @agent = Sawyer::Agent.new "http://foo.com/a/" do |conn|
8
+ conn.builder.handlers.delete(Faraday::Adapter::NetHttp)
9
+ conn.adapter :test, @stubs
10
+ end
11
+ @release_pr = Sawyer::Resource.new(@agent, load_yaml("pr_1.yml"))
12
+ @merged_prs = [
13
+ Sawyer::Resource.new(@agent, load_yaml("pr_3.yml")),
14
+ Sawyer::Resource.new(@agent, load_yaml("pr_6.yml")),
15
+ ]
16
+ @changed_files = [
17
+ Sawyer::Resource.new(@agent, load_yaml("pr_1_files.yml")),
18
+ ]
19
+ end
20
+
21
+ describe "#build_pr_title_and_body" do
22
+ context "without template_path" do
23
+ it {
24
+ pr_title, new_body = build_pr_title_and_body(@release_pr, @merged_prs, @changed_files, nil)
25
+ expect(pr_title).to eq "Release 2019-02-20 22:58:35 +0900"
26
+ expect(new_body).to eq <<~MARKDOWN
27
+ - [ ] #3 @hakobe
28
+ - [ ] #6 @ninjinkun
29
+ MARKDOWN
30
+ }
31
+ end
32
+
33
+ context "with template_path" do
34
+ it {
35
+ pr_title, new_body = build_pr_title_and_body(@release_pr, @merged_prs, @changed_files, "spec/fixtures/file/template_1.erb")
36
+ expect(pr_title).to eq "a"
37
+ expect(new_body).to eq <<~MARKDOWN
38
+ b
39
+ MARKDOWN
40
+ }
41
+ end
42
+ end
43
+
44
+ describe "#dump_result_as_json" do
45
+ it {
46
+ output = capture(:stdout) { dump_result_as_json(@release_pr, @merged_prs, @changed_files) }
47
+ parsed_output = JSON.parse(output)
48
+
49
+ expect(parsed_output.keys).to eq %w[release_pull_request merged_pull_requests changed_files]
50
+ expect(parsed_output["release_pull_request"]).to eq({ "data" => JSON.parse(@release_pr.to_hash.to_json) })
51
+ expect(parsed_output["merged_pull_requests"]).to eq @merged_prs.map {|e| JSON.parse(Git::Pr::Release::PullRequest.new(e).to_hash.to_json) }
52
+ expect(parsed_output["changed_files"]).to eq @changed_files.map {|e| JSON.parse(e.to_hash.to_json) }
53
+ }
54
+ end
55
+
56
+ describe "#merge_pr_body" do
57
+ context "new pr added" do
58
+ it {
59
+ actual = merge_pr_body(<<~OLD_BODY, <<~NEW_BODY)
60
+ - [x] #3 Provides a creating release pull-request object for template @hakobe
61
+ - [ ] #6 Support two factor auth @ninjinkun
62
+ OLD_BODY
63
+ - [ ] #3 Provides a creating release pull-request object for template @hakobe
64
+ - [ ] #4 use user who create PR if there is no assignee @hakobe
65
+ - [ ] #6 Support two factor auth @ninjinkun
66
+ NEW_BODY
67
+
68
+ expect(actual).to eq <<~MARKDOWN.chomp
69
+ - [x] #3 Provides a creating release pull-request object for template @hakobe
70
+ - [ ] #4 use user who create PR if there is no assignee @hakobe
71
+ - [ ] #6 Support two factor auth @ninjinkun
72
+ MARKDOWN
73
+ }
74
+ end
75
+ context "new pr added and keeping task status" do
76
+ it {
77
+ actual = merge_pr_body(<<~OLD_BODY, <<~NEW_BODY)
78
+ - [x] #4 use user who create PR if there is no assignee @hakobe
79
+ - [x] #6 Support two factor auth @ninjinkun
80
+ OLD_BODY
81
+ - [ ] #3 Provides a creating release pull-request object for template @hakobe
82
+ - [ ] #4 use user who create PR if there is no assignee @hakobe
83
+ - [ ] #6 Support two factor auth @ninjinkun
84
+ NEW_BODY
85
+
86
+ expect(actual).to eq <<~MARKDOWN.chomp
87
+ - [ ] #3 Provides a creating release pull-request object for template @hakobe
88
+ - [x] #4 use user who create PR if there is no assignee @hakobe
89
+ - [x] #6 Support two factor auth @ninjinkun
90
+ MARKDOWN
91
+ }
92
+ end
93
+ end
94
+
95
+ describe "#host_and_repository_and_scheme" do
96
+ it {
97
+ expect(self).to receive(:git).with(:config, "remote.origin.url") { ["https://github.com/motemen/git-pr-release\n"] }
98
+ expect(host_and_repository_and_scheme).to eq [nil, "motemen/git-pr-release", "https"]
99
+ }
100
+ it {
101
+ expect(self).to receive(:git).with(:config, "remote.origin.url") { ["ssh://git@github.com/motemen/git-pr-release.git\n"] }
102
+ expect(host_and_repository_and_scheme).to eq [nil, "motemen/git-pr-release", "https"]
103
+ }
104
+ it {
105
+ expect(self).to receive(:git).with(:config, "remote.origin.url") { ["http://ghe.example.com/motemen/git-pr-release\n"] }
106
+ expect(host_and_repository_and_scheme).to eq ["ghe.example.com", "motemen/git-pr-release", "http"]
107
+ }
108
+ it {
109
+ expect(self).to receive(:git).with(:config, "remote.origin.url") { ["ssh://git@ghe.example.com/motemen/git-pr-release.git\n"] }
110
+ expect(host_and_repository_and_scheme).to eq ["ghe.example.com", "motemen/git-pr-release", "https"]
111
+ }
112
+ end
113
+ end
@@ -0,0 +1,39 @@
1
+ require "timecop"
2
+ require "yaml"
3
+ require "git/pr/release"
4
+ require "webmock/rspec"
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+ config.shared_context_metadata_behavior = :apply_to_host_groups
14
+
15
+ config.filter_run_when_matching :focus
16
+ config.example_status_persistence_file_path = ".rspec_status"
17
+ config.disable_monkey_patching!
18
+ config.warnings = true
19
+ config.order = :random
20
+ Kernel.srand config.seed
21
+
22
+ config.around(:each) do |example|
23
+ begin
24
+ ENV['TZ'], old = 'Asia/Tokyo', ENV['TZ']
25
+ example.run
26
+ ensure
27
+ ENV['TZ'] = old
28
+ end
29
+ end
30
+
31
+ config.after do
32
+ Timecop.return
33
+ end
34
+
35
+ # Trigger Autoload
36
+ Octokit::Client
37
+ end
38
+
39
+ Dir[File.expand_path("support/**/*.rb", __dir__)].each {|f| require f }
@@ -0,0 +1,17 @@
1
+ module CaptureSupport
2
+ def capture(stream)
3
+ begin
4
+ eval "$#{stream} = StringIO.new"
5
+ yield
6
+ result = eval("$#{stream}").string
7
+ ensure
8
+ eval("$#{stream} = #{stream.upcase}")
9
+ end
10
+
11
+ result
12
+ end
13
+ end
14
+
15
+ RSpec.configure do |config|
16
+ config.include CaptureSupport
17
+ end