|
10 | 10 |
|
11 | 11 | before do |
12 | 12 | described_class.config.client = Octokit::Client.new |
| 13 | + described_class.config.client.access_token = '_' |
| 14 | + described_class.config.ref = '_' |
13 | 15 | described_class.config.allowed_conclusions = %w[success skipped] |
14 | 16 | end |
15 | 17 |
|
16 | 18 | describe '#inputs' do |
| 19 | + before { allow(service).to receive(:exit) } |
| 20 | + |
17 | 21 | it 'raises an error when the ref input is empty' do |
18 | 22 | service.config.ref = '' |
19 | 23 | expected_msg = 'The ref parameter is required but was not provided.' |
20 | | - expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 24 | + expect { service.call }.to output(/#{expected_msg}/).to_stdout |
| 25 | + expect(service).to have_received(:exit).with(1) |
21 | 26 | end |
22 | 27 |
|
23 | 28 | it 'raises an error when the repo-token input is empty' do |
24 | | - service.config.ref = '_' |
25 | 29 | service.config.client.access_token = '' |
26 | 30 | expected_msg = 'The repo-token parameter is required but was not provided.' |
27 | | - expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 31 | + expect { service.call }.to output(/#{expected_msg}/).to_stdout |
| 32 | + expect(service).to have_received(:exit).with(1) |
28 | 33 | end |
29 | 34 | end |
30 | 35 |
|
31 | 36 | describe '#call' do |
32 | | - before { allow(service).to receive(:wait_for_checks).and_raise(CheckNeverRunError) } |
| 37 | + before do |
| 38 | + allow(service).to receive(:wait_for_checks).and_raise(CheckNeverRunError) |
| 39 | + allow(service).to receive(:exit) |
| 40 | + end |
33 | 41 |
|
34 | 42 | it 'exit with status false if wait_for_checks fails' do |
35 | | - service.config.ref = '_' |
36 | | - service.config.client.access_token = '_' |
37 | 43 | expected_msg = 'The requested check was never run against this ref, exiting...' |
38 | | - expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 44 | + expect { service.call }.to output(/#{expected_msg}/).to_stdout |
| 45 | + expect(service).to have_received(:exit).with(1) |
39 | 46 | end |
40 | 47 | end |
41 | 48 |
|
|
110 | 117 |
|
111 | 118 | all_checks = [] |
112 | 119 | allow(service).to receive(:query_check_status).and_return all_checks |
| 120 | + allow(service).to receive(:exit) |
113 | 121 |
|
114 | 122 | expected_msg = 'The requested check was never run against this ref, exiting...' |
115 | | - expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 123 | + expect { service.call }.to output(/#{expected_msg}/).to_stdout |
| 124 | + expect(service).to have_received(:exit).with(1) |
116 | 125 | end |
117 | 126 |
|
118 | 127 | context 'when fail_on_no_checks is false' do |
|
147 | 156 | end |
148 | 157 |
|
149 | 158 | context 'when fail_on_no_checks is true (default)' do |
| 159 | + before { allow(service).to receive(:exit) } |
| 160 | + |
150 | 161 | it 'raises an exception when check_regexp is set and no checks match' do |
151 | 162 | service.config.check_regexp = 'non-matching-regexp' |
152 | 163 | service.config.fail_on_no_checks = true |
|
156 | 167 | allow(service).to receive(:query_check_status).and_return all_checks |
157 | 168 |
|
158 | 169 | expected_msg = 'The requested check was never run against this ref, exiting...' |
159 | | - expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 170 | + expect { service.call }.to output(/#{expected_msg}/).to_stdout |
| 171 | + expect(service).to have_received(:exit).with(1) |
160 | 172 | end |
161 | 173 |
|
162 | 174 | it 'raises an exception when check_name is set and no checks match' do |
|
168 | 180 | allow(service).to receive(:query_check_status).and_return all_checks |
169 | 181 |
|
170 | 182 | expected_msg = 'The requested check was never run against this ref, exiting...' |
171 | | - expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 183 | + expect { service.call }.to output(/#{expected_msg}/).to_stdout |
| 184 | + expect(service).to have_received(:exit).with(1) |
172 | 185 | end |
173 | 186 | end |
174 | 187 | end |
175 | 188 |
|
176 | 189 | describe '#wait_for_check_discovery' do |
177 | | - before do |
178 | | - service.config.ref = '_' |
179 | | - service.config.client.access_token = '_' |
180 | | - end |
181 | | - |
182 | 190 | it 'polls until checks are found within the timeout' do |
183 | 191 | service.config.check_name = 'delayed-check' |
184 | 192 | service.config.fail_on_no_checks = true |
|
225 | 233 | service.wait = 0 |
226 | 234 |
|
227 | 235 | allow(service).to receive(:query_check_status).and_return [] |
| 236 | + allow(service).to receive(:exit) |
228 | 237 |
|
229 | 238 | expected_msg = 'The requested check was never run against this ref, exiting...' |
230 | | - expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 239 | + expect { service.call }.to output(/#{expected_msg}/).to_stdout |
| 240 | + expect(service).to have_received(:exit).with(1) |
231 | 241 | end |
232 | 242 | end |
233 | 243 |
|
234 | 244 | describe '#fail_unless_all_conclusions_allowed' do |
235 | | - it 'raises an exception if some check conclusion is not allowed' do |
| 245 | + it 'prints an error message when a check conclusion is not allowed' do |
236 | 246 | all_checks = [ |
237 | 247 | Helpers::CheckRun.new(name: 'test', status: 'completed', conclusion: 'success'), |
238 | 248 | Helpers::CheckRun.new(name: 'test', status: 'completed', conclusion: 'failure') |
239 | 249 | ] |
240 | 250 |
|
241 | 251 | allow(service).to receive(:query_check_status).and_return all_checks |
| 252 | + allow(service).to receive(:exit) |
242 | 253 |
|
243 | 254 | expected_msg = 'The conclusion of one or more checks were not allowed. Allowed conclusions are: ' \ |
244 | 255 | "success, skipped. This can be configured with the 'allowed-conclusions' param." |
245 | 256 |
|
246 | | - expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout |
| 257 | + expect { service.call }.to output(/#{expected_msg}/).to_stdout |
| 258 | + expect(service).to have_received(:exit).with(1) |
247 | 259 | end |
248 | 260 |
|
249 | 261 | it 'does not raise an exception if all checks conclusions are allowed' do |
|
0 commit comments