git_helper 3.1.2 → 3.3.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 +24 -22
- data/Guardfile +1 -1
- data/README.md +11 -6
- data/bin/git-helper +8 -1
- data/lib/git_helper/change_remote.rb +1 -1
- data/lib/git_helper/code_request.rb +6 -5
- data/lib/git_helper/git_config_reader.rb +4 -4
- data/lib/git_helper/highline_cli.rb +12 -68
- data/lib/git_helper/local_code.rb +1 -1
- data/lib/git_helper/merge_request.rb +5 -5
- data/lib/git_helper/new_branch.rb +1 -1
- data/lib/git_helper/pull_request.rb +4 -4
- data/lib/git_helper/setup.rb +87 -0
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +3 -2
- data/spec/git_helper/code_request_spec.rb +26 -24
- data/spec/git_helper/highline_cli_spec.rb +18 -184
- data/spec/git_helper/local_code_spec.rb +1 -0
- data/spec/git_helper/merge_request_spec.rb +29 -19
- data/spec/git_helper/new_branch_spec.rb +3 -2
- data/spec/git_helper/pull_request_spec.rb +17 -16
- data/spec/git_helper/setup_spec.rb +170 -0
- metadata +21 -19
data/lib/git_helper/version.rb
CHANGED
data/plugins.zip
CHANGED
Binary file
|
@@ -4,7 +4,7 @@ require 'git_helper'
|
|
4
4
|
describe GitHelper::ChangeRemote do
|
5
5
|
let(:remote1) { "git@github.com:#{old_owner}/#{project}.git" }
|
6
6
|
let(:project) { Faker::Lorem.word }
|
7
|
-
let(:cli) { double(:highline_cli,
|
7
|
+
let(:cli) { double(:highline_cli, ask_yes_no: true) }
|
8
8
|
let(:old_owner) { Faker::Internet.username }
|
9
9
|
let(:new_owner) { Faker::Internet.username }
|
10
10
|
let(:directory_entries) { [ '.', '..', project, Faker::Lorem.word, Faker::Lorem.word ] }
|
@@ -26,6 +26,7 @@ describe GitHelper::ChangeRemote do
|
|
26
26
|
before do
|
27
27
|
allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
|
28
28
|
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
29
|
+
allow(subject).to receive(:puts)
|
29
30
|
end
|
30
31
|
|
31
32
|
describe '#execute' do
|
@@ -72,7 +73,7 @@ describe GitHelper::ChangeRemote do
|
|
72
73
|
end
|
73
74
|
|
74
75
|
context 'when the user says not to process the directory' do
|
75
|
-
let(:cli) { double(:highline_cli,
|
76
|
+
let(:cli) { double(:highline_cli, ask_yes_no: false) }
|
76
77
|
|
77
78
|
it 'should not call to process the directory' do
|
78
79
|
expect(subject).not_to receive(:process_git_repository)
|
@@ -13,6 +13,7 @@ describe GitHelper::CodeRequest do
|
|
13
13
|
before do
|
14
14
|
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
15
15
|
allow(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
|
16
|
+
allow(subject).to receive(:puts)
|
16
17
|
end
|
17
18
|
|
18
19
|
describe '#create' do
|
@@ -100,19 +101,19 @@ describe GitHelper::CodeRequest do
|
|
100
101
|
|
101
102
|
describe '#ask_for_clarification' do
|
102
103
|
it 'should ask the CLI' do
|
103
|
-
expect(highline_cli).to receive(:
|
104
|
+
expect(highline_cli).to receive(:ask).and_return('github')
|
104
105
|
subject.send(:ask_for_clarification)
|
105
106
|
end
|
106
107
|
|
107
108
|
context 'when response is github' do
|
108
109
|
it 'should return github_pull_request' do
|
109
|
-
allow(highline_cli).to receive(:
|
110
|
+
allow(highline_cli).to receive(:ask).and_return('github')
|
110
111
|
expect(subject).to receive(:github_pull_request)
|
111
112
|
subject.send(:ask_for_clarification)
|
112
113
|
end
|
113
114
|
|
114
115
|
it 'should return github_pull_request' do
|
115
|
-
allow(highline_cli).to receive(:
|
116
|
+
allow(highline_cli).to receive(:ask).and_return('Github')
|
116
117
|
expect(subject).to receive(:github_pull_request)
|
117
118
|
subject.send(:ask_for_clarification)
|
118
119
|
end
|
@@ -120,21 +121,22 @@ describe GitHelper::CodeRequest do
|
|
120
121
|
|
121
122
|
context 'when response is gitlab' do
|
122
123
|
it 'should return gitlab_merge_request' do
|
123
|
-
allow(highline_cli).to receive(:
|
124
|
+
allow(highline_cli).to receive(:ask).and_return('gitlab')
|
124
125
|
expect(subject).to receive(:gitlab_merge_request)
|
125
126
|
subject.send(:ask_for_clarification)
|
126
127
|
end
|
127
128
|
|
128
129
|
it 'should return gitlab_merge_request' do
|
129
|
-
allow(highline_cli).to receive(:
|
130
|
+
allow(highline_cli).to receive(:ask).and_return('Gitlab')
|
130
131
|
expect(subject).to receive(:gitlab_merge_request)
|
131
132
|
subject.send(:ask_for_clarification)
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
136
|
+
# Unfortunately this test sometimes fails... just rerun the tests if it does
|
135
137
|
context 'when response is neither' do
|
136
138
|
it 'should raise an error' do
|
137
|
-
allow(highline_cli).to receive(:
|
139
|
+
allow(highline_cli).to receive(:ask).and_return(Faker::Lorem.word)
|
138
140
|
expect(subject).to receive(:exit)
|
139
141
|
subject.send(:ask_for_clarification)
|
140
142
|
end
|
@@ -172,23 +174,23 @@ describe GitHelper::CodeRequest do
|
|
172
174
|
describe '#base_branch' do
|
173
175
|
it 'should call the default branch' do
|
174
176
|
expect(subject).to receive(:default_branch)
|
175
|
-
allow(highline_cli).to receive(:
|
176
|
-
allow(highline_cli).to receive(:
|
177
|
+
allow(highline_cli).to receive(:ask_yes_no).at_least(:once)
|
178
|
+
allow(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
|
177
179
|
subject.send(:base_branch)
|
178
180
|
end
|
179
181
|
|
180
182
|
it 'should ask the CLI to ask the user' do
|
181
183
|
allow(subject).to receive(:default_branch)
|
182
|
-
expect(highline_cli).to receive(:
|
183
|
-
allow(highline_cli).to receive(:
|
184
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once)
|
185
|
+
allow(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
|
184
186
|
subject.send(:base_branch)
|
185
187
|
end
|
186
188
|
|
187
189
|
context 'if the user says no' do
|
188
190
|
it 'definitely asks for the users base branch' do
|
189
191
|
allow(subject).to receive(:default_branch)
|
190
|
-
expect(highline_cli).to receive(:
|
191
|
-
expect(highline_cli).to receive(:
|
192
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(false)
|
193
|
+
expect(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
|
192
194
|
subject.send(:base_branch)
|
193
195
|
end
|
194
196
|
end
|
@@ -196,7 +198,7 @@ describe GitHelper::CodeRequest do
|
|
196
198
|
context 'if the user says yes' do
|
197
199
|
it 'does not ask for the users base branch' do
|
198
200
|
allow(subject).to receive(:default_branch)
|
199
|
-
expect(highline_cli).to receive(:
|
201
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(true)
|
200
202
|
expect(highline_cli).not_to receive(:base_branch)
|
201
203
|
subject.send(:base_branch)
|
202
204
|
end
|
@@ -214,32 +216,32 @@ describe GitHelper::CodeRequest do
|
|
214
216
|
describe '#new_code_request_title' do
|
215
217
|
it 'should call autogenerated title method' do
|
216
218
|
expect(subject).to receive(:autogenerated_title)
|
217
|
-
allow(highline_cli).to receive(:
|
218
|
-
allow(highline_cli).to receive(:
|
219
|
+
allow(highline_cli).to receive(:ask_yes_no).at_least(:once)
|
220
|
+
allow(highline_cli).to receive(:ask).at_least(:once).and_return(title)
|
219
221
|
subject.send(:new_code_request_title)
|
220
222
|
end
|
221
223
|
|
222
224
|
it 'should ask the CLI to ask the user' do
|
223
|
-
allow(subject).to receive(:autogenerated_title)
|
224
|
-
expect(highline_cli).to receive(:
|
225
|
-
allow(highline_cli).to receive(:
|
225
|
+
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
226
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once)
|
227
|
+
allow(highline_cli).to receive(:ask).at_least(:once).and_return(title)
|
226
228
|
subject.send(:new_code_request_title)
|
227
229
|
end
|
228
230
|
|
229
231
|
context 'if the user says no' do
|
230
232
|
it 'definitely asks for the users title' do
|
231
|
-
allow(subject).to receive(:autogenerated_title)
|
232
|
-
expect(highline_cli).to receive(:
|
233
|
-
expect(highline_cli).to receive(:
|
233
|
+
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
234
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(false)
|
235
|
+
expect(highline_cli).to receive(:ask).at_least(:once).and_return(title)
|
234
236
|
subject.send(:new_code_request_title)
|
235
237
|
end
|
236
238
|
end
|
237
239
|
|
238
240
|
context 'if the user says yes to original title' do
|
239
241
|
it 'does not ask for the users chosen title' do
|
240
|
-
allow(subject).to receive(:autogenerated_title)
|
241
|
-
expect(highline_cli).to receive(:
|
242
|
-
expect(highline_cli).not_to receive(:
|
242
|
+
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
243
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(true)
|
244
|
+
expect(highline_cli).not_to receive(:ask)
|
243
245
|
subject.send(:new_code_request_title)
|
244
246
|
end
|
245
247
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'git_helper'
|
3
3
|
|
4
4
|
describe GitHelper::HighlineCli do
|
5
|
-
let(:response) { double(:response, readline: true, to_i:
|
5
|
+
let(:response) { double(:response, readline: true, to_i: 3) }
|
6
6
|
let(:highline_client) { double(:highline_cli, ask: response) }
|
7
7
|
|
8
8
|
subject { GitHelper::HighlineCli.new }
|
@@ -11,207 +11,41 @@ describe GitHelper::HighlineCli do
|
|
11
11
|
allow(HighLine).to receive(:new).and_return(highline_client)
|
12
12
|
end
|
13
13
|
|
14
|
-
describe '#
|
15
|
-
it 'should ask the
|
16
|
-
expect(
|
17
|
-
subject.
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should come out a string' do
|
21
|
-
expect(subject.new_branch_name).to be_a(String)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#process_directory_remotes' do
|
26
|
-
it 'should ask the subjects ask method' do
|
27
|
-
expect(subject).to receive(:ask).and_return('y')
|
28
|
-
subject.process_directory_remotes?(Faker::Lorem.word)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should be a boolean at the end' do
|
32
|
-
allow(subject).to receive(:ask).and_return('y')
|
33
|
-
expect([true, false]).to include(subject.process_directory_remotes?(Faker::Lorem.word))
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should come out as a true boolean if somebody responds y' do
|
37
|
-
allow(subject).to receive(:ask).and_return('y')
|
38
|
-
expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(true)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should come out as a false boolean if somebody responds n' do
|
42
|
-
allow(subject).to receive(:ask).and_return('n')
|
43
|
-
expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(false)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should come out as true if somebody presses enter' do
|
47
|
-
allow(subject).to receive(:ask).and_return('')
|
48
|
-
expect(subject.accept_autogenerated_title?(Faker::Lorem.word)).to eq(true)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#conflicting_remote_clarification' do
|
53
|
-
it 'should ask the subjects ask method' do
|
54
|
-
expect(subject).to receive(:ask).with('Found git remotes for both GitHub and GitLab. Would you like to proceed with GitLab or GitHub? (github/gitlab)').and_return('gitlab')
|
55
|
-
subject.conflicting_remote_clarification
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should come out a string' do
|
59
|
-
expect(subject.conflicting_remote_clarification).to be_a(String)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '#title' do
|
64
|
-
it 'should ask the subjects ask method' do
|
65
|
-
expect(subject).to receive(:ask).with('Title?')
|
66
|
-
subject.title
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should come out a string' do
|
70
|
-
expect(subject.title).to be_a(String)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe '#base_branch' do
|
75
|
-
it 'should ask the subjects ask method' do
|
76
|
-
expect(subject).to receive(:ask).with('Base branch?')
|
77
|
-
subject.base_branch
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'should come out a string' do
|
81
|
-
expect(subject.base_branch).to be_a(String)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#code_request_id' do
|
86
|
-
let(:phrase) { Faker::Lorem.sentence }
|
87
|
-
|
88
|
-
it 'should ask the subjects ask method' do
|
89
|
-
expect(subject).to receive(:ask).with("#{phrase} Request ID?")
|
90
|
-
subject.code_request_id(phrase)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should come out a string' do
|
94
|
-
expect(subject.code_request_id(phrase)).to be_a(String)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe '#accept_autogenerated_title' do
|
99
|
-
it 'should ask the subjects ask method' do
|
100
|
-
expect(subject).to receive(:ask).and_return('y')
|
101
|
-
subject.accept_autogenerated_title?(Faker::Lorem.sentence)
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'should be a boolean at the end' do
|
105
|
-
allow(subject).to receive(:ask).and_return('y')
|
106
|
-
expect([true, false]).to include(subject.accept_autogenerated_title?(Faker::Lorem.sentence))
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should come out as a true boolean if somebody responds y' do
|
110
|
-
allow(subject).to receive(:ask).and_return('y')
|
111
|
-
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'should come out as a true boolean if somebody responds n' do
|
115
|
-
allow(subject).to receive(:ask).and_return('n')
|
116
|
-
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'should come out as a true boolean if somebody responds yes' do
|
120
|
-
allow(subject).to receive(:ask).and_return('yes')
|
121
|
-
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should come out as a false boolean if somebody responds no' do
|
125
|
-
allow(subject).to receive(:ask).and_return('no')
|
126
|
-
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should come out as true if somebody presses enter' do
|
130
|
-
allow(subject).to receive(:ask).and_return('')
|
131
|
-
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe '#base_branch_default' do
|
136
|
-
it 'should ask the subjects ask method' do
|
137
|
-
expect(subject).to receive(:ask).and_return('y')
|
138
|
-
subject.base_branch_default?(Faker::Lorem.word)
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'should be a boolean at the end' do
|
142
|
-
allow(subject).to receive(:ask).and_return('y')
|
143
|
-
expect([true, false]).to include(subject.base_branch_default?(Faker::Lorem.word))
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'should come out as a true boolean if somebody responds y' do
|
147
|
-
allow(subject).to receive(:ask).and_return('y')
|
148
|
-
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should come out as a true boolean if somebody responds n' do
|
152
|
-
allow(subject).to receive(:ask).and_return('n')
|
153
|
-
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'should come out as a true boolean if somebody responds yes' do
|
157
|
-
allow(subject).to receive(:ask).and_return('yes')
|
158
|
-
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'should come out as a false boolean if somebody responds no' do
|
162
|
-
allow(subject).to receive(:ask).and_return('no')
|
163
|
-
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should come out as true if somebody presses enter' do
|
167
|
-
allow(subject).to receive(:ask).and_return('')
|
168
|
-
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe '#merge_method' do
|
173
|
-
it 'should ask the subjects ask_options method' do
|
174
|
-
expect(subject).to receive(:ask_options).and_return(3)
|
175
|
-
subject.merge_method(['1', '2', '3'])
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should return a string' do
|
179
|
-
allow(subject).to receive(:ask_options).and_return(2)
|
180
|
-
expect(subject.merge_method(['1', '2', '3'])).to be_a(String)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe '#template_to_apply' do
|
185
|
-
it 'should ask the subjects ask_options method' do
|
186
|
-
expect(subject).to receive(:ask_options).and_return(3)
|
187
|
-
subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')
|
14
|
+
describe '#ask' do
|
15
|
+
it 'should ask the highline client ask'do
|
16
|
+
expect(highline_client).to receive(:ask)
|
17
|
+
subject.ask(Faker::Lorem.sentence)
|
188
18
|
end
|
189
19
|
|
190
20
|
it 'should return a string' do
|
191
|
-
|
192
|
-
expect(subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')).to eq('None')
|
21
|
+
expect(subject.ask(Faker::Lorem.sentence)).to be_a(String)
|
193
22
|
end
|
194
23
|
end
|
195
24
|
|
196
|
-
describe '#
|
25
|
+
describe '#ask_yes_no' do
|
197
26
|
it 'should ask the highline client ask'do
|
198
27
|
expect(highline_client).to receive(:ask)
|
199
|
-
subject.
|
28
|
+
subject.ask_yes_no(Faker::Lorem.sentence)
|
200
29
|
end
|
201
30
|
|
202
|
-
it 'should return a
|
203
|
-
expect(subject.
|
31
|
+
it 'should return a boolean' do
|
32
|
+
expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_falsey
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return true if we say yes' do
|
36
|
+
allow(response).to receive(:to_s).and_return('y')
|
37
|
+
expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_truthy
|
204
38
|
end
|
205
39
|
end
|
206
40
|
|
207
41
|
describe '#ask_options' do
|
208
42
|
it 'should ask the highline client ask'do
|
209
43
|
expect(highline_client).to receive(:ask)
|
210
|
-
subject.
|
44
|
+
subject.ask_options(Faker::Lorem.sentence, ['one', 'two', 'three'])
|
211
45
|
end
|
212
46
|
|
213
|
-
it 'should return
|
214
|
-
expect(subject.
|
47
|
+
it 'should return a string from the options' do
|
48
|
+
expect(subject.ask_options(Faker::Lorem.sentence, ['one', 'two', 'three'])).to be_a(String)
|
215
49
|
end
|
216
50
|
end
|
217
51
|
end
|
@@ -70,6 +70,7 @@ describe GitHelper::LocalCode do
|
|
70
70
|
|
71
71
|
describe '#change_remote' do
|
72
72
|
it 'should return a string' do
|
73
|
+
allow(subject).to receive(:`).and_return(Faker::Lorem.word)
|
73
74
|
expect(subject.change_remote(Faker::Lorem.word, Faker::Internet.url)).to be_a(String)
|
74
75
|
end
|
75
76
|
end
|
@@ -6,6 +6,15 @@ describe GitHelper::GitLabMergeRequest do
|
|
6
6
|
let(:highline_cli) { double(:highline_cli) }
|
7
7
|
let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
8
8
|
let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
|
9
|
+
let(:diff_refs) { double(:diff_refs, base_sha: :base, head_sha: :head) }
|
10
|
+
|
11
|
+
let(:merge_request) do
|
12
|
+
double(:merge_request,
|
13
|
+
diff_refs: diff_refs,
|
14
|
+
web_url: Faker::Internet.url,
|
15
|
+
merge_commit_sha: Faker::Internet.password
|
16
|
+
)
|
17
|
+
end
|
9
18
|
|
10
19
|
let(:options) do
|
11
20
|
{
|
@@ -20,6 +29,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
20
29
|
|
21
30
|
before do
|
22
31
|
allow(GitHelper::GitLabClient).to receive(:new).and_return(gitlab_client)
|
32
|
+
allow(subject).to receive(:puts)
|
23
33
|
end
|
24
34
|
|
25
35
|
describe '#create' do
|
@@ -27,7 +37,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
27
37
|
allow(subject).to receive(:squash_merge_request).and_return(true)
|
28
38
|
allow(subject).to receive(:remove_source_branch).and_return(false)
|
29
39
|
allow(subject).to receive(:new_mr_body).and_return('')
|
30
|
-
expect(gitlab_client_client).to receive(:create_merge_request)
|
40
|
+
expect(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
|
31
41
|
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
32
42
|
end
|
33
43
|
|
@@ -35,7 +45,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
35
45
|
expect(subject).to receive(:squash_merge_request).and_return(true)
|
36
46
|
expect(subject).to receive(:remove_source_branch).and_return(false)
|
37
47
|
expect(subject).to receive(:new_mr_body).and_return('')
|
38
|
-
allow(gitlab_client_client).to receive(:create_merge_request)
|
48
|
+
allow(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
|
39
49
|
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
40
50
|
end
|
41
51
|
|
@@ -52,14 +62,14 @@ describe GitHelper::GitLabMergeRequest do
|
|
52
62
|
it 'should call the gitlab client to merge' do
|
53
63
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
54
64
|
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
55
|
-
expect(gitlab_client_client).to receive(:accept_merge_request)
|
65
|
+
expect(gitlab_client_client).to receive(:accept_merge_request).and_return(merge_request)
|
56
66
|
subject.merge
|
57
67
|
end
|
58
68
|
|
59
69
|
it 'should call various other methods' do
|
60
70
|
expect(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title')).at_least(:once)
|
61
71
|
expect(subject).to receive(:mr_id).and_return(Faker::Number.number).at_least(:once)
|
62
|
-
allow(gitlab_client_client).to receive(:accept_merge_request)
|
72
|
+
allow(gitlab_client_client).to receive(:accept_merge_request).and_return(merge_request)
|
63
73
|
subject.merge
|
64
74
|
end
|
65
75
|
|
@@ -73,7 +83,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
73
83
|
it 'should try to merge multiple times if the first merge errors' do
|
74
84
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
75
85
|
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
76
|
-
expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil)).exactly(2).times
|
86
|
+
expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil, merge_error: Faker::Lorem.word)).exactly(2).times
|
77
87
|
expect(subject.merge).to eq(nil)
|
78
88
|
end
|
79
89
|
end
|
@@ -110,19 +120,19 @@ describe GitHelper::GitLabMergeRequest do
|
|
110
120
|
|
111
121
|
it 'should call the CLI to ask about a single template' do
|
112
122
|
allow(subject).to receive(:mr_template_options).and_return([template])
|
113
|
-
expect(highline_cli).to receive(:
|
123
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
114
124
|
subject.send(:template_name_to_apply)
|
115
125
|
end
|
116
126
|
|
117
127
|
it 'should return the single template if the user says yes' do
|
118
128
|
allow(subject).to receive(:mr_template_options).and_return([template])
|
119
|
-
allow(highline_cli).to receive(:
|
129
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(true)
|
120
130
|
expect(subject.send(:template_name_to_apply)).to eq(template)
|
121
131
|
end
|
122
132
|
|
123
133
|
it 'should return nil if the user says no' do
|
124
134
|
allow(subject).to receive(:mr_template_options).and_return([template])
|
125
|
-
allow(highline_cli).to receive(:
|
135
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(false)
|
126
136
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
127
137
|
end
|
128
138
|
end
|
@@ -133,19 +143,19 @@ describe GitHelper::GitLabMergeRequest do
|
|
133
143
|
|
134
144
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
135
145
|
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
136
|
-
expect(highline_cli).to receive(:
|
146
|
+
expect(highline_cli).to receive(:ask_options).and_return(template1)
|
137
147
|
subject.send(:template_name_to_apply)
|
138
148
|
end
|
139
149
|
|
140
150
|
it 'should return the answer template if the user says yes' do
|
141
151
|
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
142
|
-
allow(highline_cli).to receive(:
|
152
|
+
allow(highline_cli).to receive(:ask_options).and_return(template1)
|
143
153
|
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
144
154
|
end
|
145
155
|
|
146
156
|
it 'should return nil if the user says no' do
|
147
157
|
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
148
|
-
allow(highline_cli).to receive(:
|
158
|
+
allow(highline_cli).to receive(:ask_options).and_return('None')
|
149
159
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
150
160
|
end
|
151
161
|
end
|
@@ -160,25 +170,25 @@ describe GitHelper::GitLabMergeRequest do
|
|
160
170
|
|
161
171
|
describe '#mr_id' do
|
162
172
|
it 'should ask the CLI for the code request ID' do
|
163
|
-
expect(highline_cli).to receive(:
|
173
|
+
expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
|
164
174
|
subject.send(:mr_id)
|
165
175
|
end
|
166
176
|
|
167
177
|
it 'should equal an integer' do
|
168
178
|
pr_id = Faker::Number.number
|
169
|
-
expect(highline_cli).to receive(:
|
179
|
+
expect(highline_cli).to receive(:ask).and_return(pr_id)
|
170
180
|
expect(subject.send(:mr_id)).to eq(pr_id)
|
171
181
|
end
|
172
182
|
end
|
173
183
|
|
174
184
|
describe '#squash_merge_request' do
|
175
185
|
it 'should ask the CLI for the code request ID' do
|
176
|
-
expect(highline_cli).to receive(:
|
186
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
177
187
|
subject.send(:squash_merge_request)
|
178
188
|
end
|
179
189
|
|
180
190
|
it 'should be a boolean' do
|
181
|
-
expect(highline_cli).to receive(:
|
191
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(false)
|
182
192
|
expect([true, false]).to include(subject.send(:squash_merge_request))
|
183
193
|
end
|
184
194
|
end
|
@@ -190,12 +200,12 @@ describe GitHelper::GitLabMergeRequest do
|
|
190
200
|
|
191
201
|
context 'when the existing project has no setting' do
|
192
202
|
it 'should ask the CLI for the code request ID' do
|
193
|
-
expect(highline_cli).to receive(:
|
203
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
194
204
|
subject.send(:remove_source_branch)
|
195
205
|
end
|
196
206
|
|
197
207
|
it 'should be a boolean' do
|
198
|
-
allow(highline_cli).to receive(:
|
208
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(false)
|
199
209
|
expect([true, false]).to include(subject.send(:remove_source_branch))
|
200
210
|
end
|
201
211
|
end
|
@@ -212,7 +222,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
212
222
|
|
213
223
|
it 'should return the existing projects setting if it exists' do
|
214
224
|
allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
|
215
|
-
allow(highline_cli).to receive(:
|
225
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(true)
|
216
226
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
217
227
|
end
|
218
228
|
end
|
@@ -226,7 +236,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
226
236
|
|
227
237
|
describe '#existing_mr' do
|
228
238
|
it 'should call the gitlab client' do
|
229
|
-
allow(highline_cli).to receive(:
|
239
|
+
allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
|
230
240
|
expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
|
231
241
|
subject.send(:existing_mr)
|
232
242
|
end
|