git_helper 2.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +23 -15
- data/Guardfile +1 -1
- data/README.md +21 -12
- data/Rakefile +1 -37
- data/bin/git-helper +3 -10
- data/lib/git_helper.rb +5 -2
- data/lib/git_helper/change_remote.rb +0 -3
- data/lib/git_helper/checkout_default.rb +0 -2
- data/lib/git_helper/clean_branches.rb +0 -2
- data/lib/git_helper/code_request.rb +0 -5
- data/lib/git_helper/empty_commit.rb +0 -2
- data/lib/git_helper/forget_local_commits.rb +0 -2
- data/lib/git_helper/git_config_reader.rb +1 -3
- data/lib/git_helper/gitlab_client.rb +0 -3
- data/lib/git_helper/highline_cli.rb +0 -2
- data/lib/git_helper/local_code.rb +17 -13
- data/lib/git_helper/merge_request.rb +1 -4
- data/lib/git_helper/new_branch.rb +0 -3
- data/lib/git_helper/octokit_client.rb +0 -3
- data/lib/git_helper/pull_request.rb +1 -4
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +19 -16
- data/spec/git_helper/checkout_default_spec.rb +2 -1
- data/spec/git_helper/clean_branches_spec.rb +2 -1
- data/spec/git_helper/code_request_spec.rb +21 -18
- data/spec/git_helper/empty_commit_spec.rb +2 -1
- data/spec/git_helper/forget_local_commits_spec.rb +2 -1
- data/spec/git_helper/git_config_reader_spec.rb +11 -8
- data/spec/git_helper/gitlab_client_spec.rb +2 -1
- data/spec/git_helper/highline_cli_spec.rb +40 -37
- data/spec/git_helper/local_code_spec.rb +64 -27
- data/spec/git_helper/merge_request_spec.rb +36 -28
- data/spec/git_helper/new_branch_spec.rb +2 -1
- data/spec/git_helper/octokit_client_spec.rb +2 -1
- data/spec/git_helper/pull_request_spec.rb +36 -28
- data/spec/spec_helper.rb +2 -1
- metadata +21 -6
@@ -1,13 +1,27 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
2
3
|
|
3
4
|
describe GitHelper::LocalCode do
|
4
5
|
let(:response) { double(:response, readline: true, to_i: 5) }
|
5
6
|
let(:local_codeent) { double(:local_code, ask: response) }
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:
|
7
|
+
let(:project_name) { Faker::Lorem.word }
|
8
|
+
let(:owner) { Faker::Name.first_name }
|
9
|
+
let(:ssh_remote) { "origin\tgit@github.com:#{owner}/#{project_name}.git (fetch)" }
|
10
|
+
let(:https_remote) { "origin\thttps://github.com/#{owner}/#{project_name}.git (fetch)" }
|
11
|
+
|
12
|
+
let(:github_remotes) do
|
13
|
+
[
|
14
|
+
"origin\tgit@github.com:#{owner}/#{project_name}.git (fetch)",
|
15
|
+
"origin\thttps://github.com/#{owner}/#{project_name}.git (fetch)"
|
16
|
+
]
|
17
|
+
end
|
10
18
|
|
19
|
+
let(:gitlab_remotes) do
|
20
|
+
[
|
21
|
+
"origin\tgit@gitlab.com:#{owner}/#{project_name}.git (fetch)",
|
22
|
+
"origin\thttps://gitlab.com/#{owner}/#{project_name}.git (fetch)"
|
23
|
+
]
|
24
|
+
end
|
11
25
|
|
12
26
|
subject { GitHelper::LocalCode.new }
|
13
27
|
|
@@ -50,13 +64,13 @@ describe GitHelper::LocalCode do
|
|
50
64
|
describe '#new_branch' do
|
51
65
|
it 'should make a system call' do
|
52
66
|
expect(subject).to receive(:system).exactly(4).times
|
53
|
-
subject.new_branch(
|
67
|
+
subject.new_branch(Faker::Lorem.word)
|
54
68
|
end
|
55
69
|
end
|
56
70
|
|
57
71
|
describe '#change_remote' do
|
58
72
|
it 'should return a string' do
|
59
|
-
expect(subject.change_remote(
|
73
|
+
expect(subject.change_remote(Faker::Lorem.word, Faker::Internet.url)).to be_a(String)
|
60
74
|
end
|
61
75
|
end
|
62
76
|
|
@@ -95,11 +109,11 @@ describe GitHelper::LocalCode do
|
|
95
109
|
|
96
110
|
describe '#remote_project' do
|
97
111
|
it 'should return just the plain project if ssh' do
|
98
|
-
expect(subject.remote_project(ssh_remote)).to eq(
|
112
|
+
expect(subject.remote_project(ssh_remote)).to eq(project_name)
|
99
113
|
end
|
100
114
|
|
101
115
|
it 'should return just the plain project if https' do
|
102
|
-
expect(subject.remote_project(https_remote)).to eq(
|
116
|
+
expect(subject.remote_project(https_remote)).to eq(project_name)
|
103
117
|
end
|
104
118
|
end
|
105
119
|
|
@@ -143,8 +157,8 @@ describe GitHelper::LocalCode do
|
|
143
157
|
end
|
144
158
|
|
145
159
|
it 'should equal this project name' do
|
146
|
-
allow_any_instance_of(String).to receive(:scan).and_return([[
|
147
|
-
expect(subject.project_name).to eq(
|
160
|
+
allow_any_instance_of(String).to receive(:scan).and_return([["#{owner}/#{project_name}"]])
|
161
|
+
expect(subject.project_name).to eq("#{owner}/#{project_name}")
|
148
162
|
end
|
149
163
|
end
|
150
164
|
|
@@ -163,6 +177,7 @@ describe GitHelper::LocalCode do
|
|
163
177
|
describe '#template_options' do
|
164
178
|
let(:template_identifiers) do
|
165
179
|
{
|
180
|
+
template_directory: '.github',
|
166
181
|
nested_directory_name: 'PULL_REQUEST_TEMPLATE',
|
167
182
|
non_nested_file_name: 'pull_request_template'
|
168
183
|
}
|
@@ -188,43 +203,65 @@ describe GitHelper::LocalCode do
|
|
188
203
|
|
189
204
|
describe '#generate_title' do
|
190
205
|
it 'should return a title based on the branch' do
|
191
|
-
|
192
|
-
|
206
|
+
prefix = Faker::Lorem.word
|
207
|
+
word1 = Faker::Lorem.word
|
208
|
+
word2 = Faker::Lorem.word
|
209
|
+
description = [word1, word2].join('-')
|
210
|
+
branch = "#{prefix}-123-#{description}"
|
211
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
193
212
|
end
|
194
213
|
|
195
214
|
it 'should return a title based on the branch' do
|
196
|
-
|
197
|
-
|
215
|
+
prefix = Faker::Lorem.word
|
216
|
+
word1 = Faker::Lorem.word
|
217
|
+
word2 = Faker::Lorem.word
|
218
|
+
description = [word1, word2].join('_')
|
219
|
+
branch = "#{prefix}_123_#{description}"
|
220
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
198
221
|
end
|
199
222
|
|
200
223
|
it 'should return a title based on the branch' do
|
201
|
-
|
202
|
-
|
224
|
+
prefix = Faker::Lorem.word
|
225
|
+
word1 = Faker::Lorem.word
|
226
|
+
word2 = Faker::Lorem.word
|
227
|
+
description = [word1, word2].join('_')
|
228
|
+
branch = "#{prefix}-123_#{description}"
|
229
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
203
230
|
end
|
204
231
|
|
205
232
|
it 'should return a title based on the branch' do
|
206
|
-
|
207
|
-
|
233
|
+
word1 = Faker::Lorem.word
|
234
|
+
word2 = Faker::Lorem.word
|
235
|
+
branch = [word1, word2].join('_')
|
236
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2].join(' '))
|
208
237
|
end
|
209
238
|
|
210
239
|
it 'should return a title based on the branch' do
|
211
|
-
|
212
|
-
|
240
|
+
word1 = Faker::Lorem.word
|
241
|
+
word2 = Faker::Lorem.word
|
242
|
+
branch = [word1, word2].join('-')
|
243
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2].join(' '))
|
213
244
|
end
|
214
245
|
|
215
246
|
it 'should return a title based on the branch' do
|
216
|
-
branch =
|
217
|
-
expect(subject.generate_title(branch)).to eq(
|
247
|
+
branch = Faker::Lorem.word
|
248
|
+
expect(subject.generate_title(branch)).to eq(branch.capitalize)
|
218
249
|
end
|
219
250
|
|
220
251
|
it 'should return a title based on the branch' do
|
221
|
-
|
222
|
-
|
252
|
+
word1 = Faker::Lorem.word
|
253
|
+
word2 = Faker::Lorem.word
|
254
|
+
word3 = Faker::Lorem.word
|
255
|
+
branch = [word1, word2, word3].join('_')
|
256
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2, word3].join(' '))
|
223
257
|
end
|
224
258
|
|
225
259
|
it 'should return a title based on the branch' do
|
226
|
-
|
227
|
-
|
260
|
+
word1 = Faker::Lorem.word
|
261
|
+
word2 = Faker::Lorem.word
|
262
|
+
word3 = Faker::Lorem.word
|
263
|
+
branch = [word1, word2, word3].join('-')
|
264
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2, word3].join(' '))
|
228
265
|
end
|
229
266
|
end
|
230
267
|
end
|
@@ -1,20 +1,22 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
2
3
|
|
3
4
|
describe GitHelper::GitLabMergeRequest do
|
4
|
-
let(:local_code) { double(:local_code, read_template:
|
5
|
+
let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
|
5
6
|
let(:highline_cli) { double(:highline_cli) }
|
6
7
|
let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
7
8
|
let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
|
9
|
+
|
8
10
|
let(:options) do
|
9
11
|
{
|
10
|
-
local_project:
|
11
|
-
local_branch:
|
12
|
+
local_project: Faker::Lorem.word,
|
13
|
+
local_branch: Faker::Lorem.word,
|
12
14
|
local_code: local_code,
|
13
15
|
cli: highline_cli
|
14
16
|
}
|
15
17
|
end
|
16
18
|
|
17
|
-
subject {
|
19
|
+
subject { described_class.new(options) }
|
18
20
|
|
19
21
|
before do
|
20
22
|
allow(GitHelper::GitLabClient).to receive(:new).and_return(gitlab_client)
|
@@ -26,7 +28,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
26
28
|
allow(subject).to receive(:remove_source_branch).and_return(false)
|
27
29
|
allow(subject).to receive(:new_mr_body).and_return('')
|
28
30
|
expect(gitlab_client_client).to receive(:create_merge_request)
|
29
|
-
subject.create({base_branch:
|
31
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
30
32
|
end
|
31
33
|
|
32
34
|
it 'should call various other methods' do
|
@@ -34,7 +36,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
34
36
|
expect(subject).to receive(:remove_source_branch).and_return(false)
|
35
37
|
expect(subject).to receive(:new_mr_body).and_return('')
|
36
38
|
allow(gitlab_client_client).to receive(:create_merge_request)
|
37
|
-
subject.create({base_branch:
|
39
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
38
40
|
end
|
39
41
|
|
40
42
|
it 'should catch the raised error if the creation does not work' do
|
@@ -42,35 +44,35 @@ describe GitHelper::GitLabMergeRequest do
|
|
42
44
|
allow(subject).to receive(:remove_source_branch).and_return(false)
|
43
45
|
allow(subject).to receive(:new_mr_body).and_return('')
|
44
46
|
allow(gitlab_client_client).to receive(:create_merge_request).and_raise(StandardError)
|
45
|
-
expect(subject.create({base_branch:
|
47
|
+
expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
51
|
describe '#merge' do
|
50
52
|
it 'should call the gitlab client to merge' do
|
51
53
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
52
|
-
allow(subject).to receive(:mr_id).and_return(
|
54
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
53
55
|
expect(gitlab_client_client).to receive(:accept_merge_request)
|
54
56
|
subject.merge
|
55
57
|
end
|
56
58
|
|
57
59
|
it 'should call various other methods' do
|
58
60
|
expect(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title')).at_least(:once)
|
59
|
-
expect(subject).to receive(:mr_id).and_return(
|
61
|
+
expect(subject).to receive(:mr_id).and_return(Faker::Number.number).at_least(:once)
|
60
62
|
allow(gitlab_client_client).to receive(:accept_merge_request)
|
61
63
|
subject.merge
|
62
64
|
end
|
63
65
|
|
64
66
|
it 'should catch the raised error if the merge does not work' do
|
65
67
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
66
|
-
allow(subject).to receive(:mr_id).and_return(
|
68
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
67
69
|
allow(gitlab_client_client).to receive(:accept_merge_request).and_raise(StandardError)
|
68
70
|
expect(subject.merge).to eq(nil)
|
69
71
|
end
|
70
72
|
|
71
73
|
it 'should try to merge multiple times if the first merge errors' do
|
72
74
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
73
|
-
allow(subject).to receive(:mr_id).and_return(
|
75
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
74
76
|
expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil)).exactly(2).times
|
75
77
|
expect(subject.merge).to eq(nil)
|
76
78
|
end
|
@@ -104,40 +106,45 @@ describe GitHelper::GitLabMergeRequest do
|
|
104
106
|
end
|
105
107
|
|
106
108
|
context 'if there is one template option' do
|
109
|
+
let(:template) { Faker::Lorem.word }
|
110
|
+
|
107
111
|
it 'should call the CLI to ask about a single template' do
|
108
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
112
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
109
113
|
expect(highline_cli).to receive(:apply_template?).and_return(true)
|
110
114
|
subject.send(:template_name_to_apply)
|
111
115
|
end
|
112
116
|
|
113
117
|
it 'should return the single template if the user says yes' do
|
114
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
118
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
115
119
|
allow(highline_cli).to receive(:apply_template?).and_return(true)
|
116
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
120
|
+
expect(subject.send(:template_name_to_apply)).to eq(template)
|
117
121
|
end
|
118
122
|
|
119
123
|
it 'should return nil if the user says no' do
|
120
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
124
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
121
125
|
allow(highline_cli).to receive(:apply_template?).and_return(false)
|
122
126
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
130
|
context 'if there are multiple template options' do
|
131
|
+
let(:template1) { Faker::Lorem.word }
|
132
|
+
let(:template2) { Faker::Lorem.word }
|
133
|
+
|
127
134
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
128
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
129
|
-
expect(highline_cli).to receive(:template_to_apply).and_return(
|
135
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
136
|
+
expect(highline_cli).to receive(:template_to_apply).and_return(template1)
|
130
137
|
subject.send(:template_name_to_apply)
|
131
138
|
end
|
132
139
|
|
133
140
|
it 'should return the answer template if the user says yes' do
|
134
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
135
|
-
allow(highline_cli).to receive(:template_to_apply).and_return(
|
136
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
141
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
142
|
+
allow(highline_cli).to receive(:template_to_apply).and_return(template1)
|
143
|
+
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
137
144
|
end
|
138
145
|
|
139
146
|
it 'should return nil if the user says no' do
|
140
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
147
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
141
148
|
allow(highline_cli).to receive(:template_to_apply).and_return('None')
|
142
149
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
143
150
|
end
|
@@ -153,13 +160,14 @@ describe GitHelper::GitLabMergeRequest do
|
|
153
160
|
|
154
161
|
describe '#mr_id' do
|
155
162
|
it 'should ask the CLI for the code request ID' do
|
156
|
-
expect(highline_cli).to receive(:code_request_id).and_return(
|
163
|
+
expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
|
157
164
|
subject.send(:mr_id)
|
158
165
|
end
|
159
166
|
|
160
167
|
it 'should equal an integer' do
|
161
|
-
|
162
|
-
expect(
|
168
|
+
pr_id = Faker::Number.number
|
169
|
+
expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
|
170
|
+
expect(subject.send(:mr_id)).to eq(pr_id)
|
163
171
|
end
|
164
172
|
end
|
165
173
|
|
@@ -197,12 +205,12 @@ describe GitHelper::GitLabMergeRequest do
|
|
197
205
|
subject.send(:remove_source_branch)
|
198
206
|
end
|
199
207
|
|
200
|
-
it
|
208
|
+
it 'should return the existing projects setting if it exists' do
|
201
209
|
allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: true))
|
202
210
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
203
211
|
end
|
204
212
|
|
205
|
-
it
|
213
|
+
it 'should return the existing projects setting if it exists' do
|
206
214
|
allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
|
207
215
|
allow(highline_cli).to receive(:remove_source_branch?).and_return(true)
|
208
216
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
@@ -218,7 +226,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
218
226
|
|
219
227
|
describe '#existing_mr' do
|
220
228
|
it 'should call the gitlab client' do
|
221
|
-
allow(highline_cli).to receive(:code_request_id).and_return(
|
229
|
+
allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
|
222
230
|
expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
|
223
231
|
subject.send(:existing_mr)
|
224
232
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
2
3
|
|
3
4
|
describe GitHelper::GitHubPullRequest do
|
4
|
-
let(:local_code) { double(:local_code, read_template:
|
5
|
+
let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
|
5
6
|
let(:highline_cli) { double(:highline_cli) }
|
6
7
|
let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
7
8
|
let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
|
9
|
+
|
8
10
|
let(:options) do
|
9
11
|
{
|
10
|
-
local_project:
|
11
|
-
local_branch:
|
12
|
+
local_project: Faker::Lorem.word,
|
13
|
+
local_branch: Faker::Lorem.word,
|
12
14
|
local_code: local_code,
|
13
15
|
cli: highline_cli
|
14
16
|
}
|
@@ -24,43 +26,43 @@ describe GitHelper::GitHubPullRequest do
|
|
24
26
|
it 'should call the octokit client to create' do
|
25
27
|
allow(subject).to receive(:new_pr_body).and_return('')
|
26
28
|
expect(octokit_client_client).to receive(:create_pull_request)
|
27
|
-
subject.create({base_branch:
|
29
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'should call various other methods' do
|
31
33
|
expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
|
32
34
|
allow(octokit_client_client).to receive(:create_pull_request)
|
33
|
-
subject.create({base_branch:
|
35
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
34
36
|
end
|
35
37
|
|
36
38
|
it 'should catch the raised error if the creation does not work' do
|
37
39
|
allow(subject).to receive(:new_pr_body).and_return('')
|
38
40
|
allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
|
39
|
-
expect(subject.create({base_branch:
|
41
|
+
expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
describe '#merge' do
|
44
46
|
it 'should call the octokit client to merge' do
|
45
|
-
allow(subject).to receive(:existing_pr).and_return(double(title:
|
47
|
+
allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
|
46
48
|
allow(subject).to receive(:merge_method).and_return('rebase')
|
47
|
-
allow(subject).to receive(:pr_id).and_return(
|
49
|
+
allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
|
48
50
|
expect(octokit_client_client).to receive(:merge_pull_request)
|
49
51
|
subject.merge
|
50
52
|
end
|
51
53
|
|
52
54
|
it 'should call various other methods' do
|
53
|
-
expect(subject).to receive(:existing_pr).and_return(double(title:
|
55
|
+
expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
|
54
56
|
expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
|
55
|
-
expect(subject).to receive(:pr_id).and_return(
|
57
|
+
expect(subject).to receive(:pr_id).and_return(Faker::Number.number).at_least(:once)
|
56
58
|
allow(octokit_client_client).to receive(:merge_pull_request)
|
57
59
|
subject.merge
|
58
60
|
end
|
59
61
|
|
60
62
|
it 'should catch the raised error if the merge does not work' do
|
61
|
-
allow(subject).to receive(:existing_pr).and_return(double(title:
|
63
|
+
allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
|
62
64
|
allow(subject).to receive(:merge_method).and_return('rebase')
|
63
|
-
allow(subject).to receive(:pr_id).and_return(
|
65
|
+
allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
|
64
66
|
allow(octokit_client_client).to receive(:merge_pull_request).and_raise(StandardError)
|
65
67
|
expect(subject.merge).to eq(nil)
|
66
68
|
end
|
@@ -94,40 +96,45 @@ describe GitHelper::GitHubPullRequest do
|
|
94
96
|
end
|
95
97
|
|
96
98
|
context 'if there is one template option' do
|
99
|
+
let(:template) { Faker::Lorem.word }
|
100
|
+
|
97
101
|
it 'should call the CLI to ask about a single template' do
|
98
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
102
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
99
103
|
expect(highline_cli).to receive(:apply_template?).and_return(true)
|
100
104
|
subject.send(:template_name_to_apply)
|
101
105
|
end
|
102
106
|
|
103
107
|
it 'should return the single template if the user says yes' do
|
104
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
108
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
105
109
|
allow(highline_cli).to receive(:apply_template?).and_return(true)
|
106
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
110
|
+
expect(subject.send(:template_name_to_apply)).to eq(template)
|
107
111
|
end
|
108
112
|
|
109
113
|
it 'should return nil if the user says no' do
|
110
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
114
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
111
115
|
allow(highline_cli).to receive(:apply_template?).and_return(false)
|
112
116
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
113
117
|
end
|
114
118
|
end
|
115
119
|
|
116
120
|
context 'if there are multiple template options' do
|
121
|
+
let(:template1) { Faker::Lorem.word }
|
122
|
+
let(:template2) { Faker::Lorem.word }
|
123
|
+
|
117
124
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
118
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
119
|
-
expect(highline_cli).to receive(:template_to_apply).and_return(
|
125
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
126
|
+
expect(highline_cli).to receive(:template_to_apply).and_return(template1)
|
120
127
|
subject.send(:template_name_to_apply)
|
121
128
|
end
|
122
129
|
|
123
130
|
it 'should return the answer template if the user says yes' do
|
124
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
125
|
-
allow(highline_cli).to receive(:template_to_apply).and_return(
|
126
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
131
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
132
|
+
allow(highline_cli).to receive(:template_to_apply).and_return(template1)
|
133
|
+
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
127
134
|
end
|
128
135
|
|
129
136
|
it 'should return nil if the user says no' do
|
130
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
137
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
131
138
|
allow(highline_cli).to receive(:template_to_apply).and_return('None')
|
132
139
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
133
140
|
end
|
@@ -143,13 +150,14 @@ describe GitHelper::GitHubPullRequest do
|
|
143
150
|
|
144
151
|
describe '#pr_id' do
|
145
152
|
it 'should ask the CLI for the code request ID' do
|
146
|
-
expect(highline_cli).to receive(:code_request_id).and_return(
|
153
|
+
expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
|
147
154
|
subject.send(:pr_id)
|
148
155
|
end
|
149
156
|
|
150
157
|
it 'should equal an integer' do
|
151
|
-
|
152
|
-
expect(
|
158
|
+
pr_id = Faker::Number.number
|
159
|
+
expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
|
160
|
+
expect(subject.send(:pr_id)).to eq(pr_id)
|
153
161
|
end
|
154
162
|
end
|
155
163
|
|
@@ -171,7 +179,7 @@ describe GitHelper::GitHubPullRequest do
|
|
171
179
|
expect(subject.send(:merge_method)).to be_a(String)
|
172
180
|
end
|
173
181
|
|
174
|
-
context
|
182
|
+
context 'if theres only one item' do
|
175
183
|
let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
|
176
184
|
|
177
185
|
it 'should not ask the CLI anything' do
|
@@ -230,7 +238,7 @@ describe GitHelper::GitHubPullRequest do
|
|
230
238
|
|
231
239
|
describe '#existing_pr' do
|
232
240
|
it 'should call the octokit client' do
|
233
|
-
allow(highline_cli).to receive(:code_request_id).and_return(
|
241
|
+
allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
|
234
242
|
expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
|
235
243
|
subject.send(:existing_pr)
|
236
244
|
end
|