knapsack_pro 6.0.3 → 7.0.0
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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +375 -28
- data/.github/pull_request_template.md +22 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +95 -0
- data/Gemfile +9 -0
- data/README.md +0 -7
- data/knapsack_pro.gemspec +2 -1
- data/lib/knapsack_pro/adapters/base_adapter.rb +7 -2
- data/lib/knapsack_pro/adapters/cucumber_adapter.rb +1 -3
- data/lib/knapsack_pro/adapters/rspec_adapter.rb +16 -9
- data/lib/knapsack_pro/config/env.rb +1 -9
- data/lib/knapsack_pro/extensions/rspec_extension.rb +137 -0
- data/lib/knapsack_pro/formatters/time_tracker.rb +10 -26
- data/lib/knapsack_pro/formatters/time_tracker_fetcher.rb +8 -0
- data/lib/knapsack_pro/presenter.rb +1 -1
- data/lib/knapsack_pro/pure/queue/rspec_pure.rb +92 -0
- data/lib/knapsack_pro/runners/queue/base_runner.rb +6 -1
- data/lib/knapsack_pro/runners/queue/cucumber_runner.rb +6 -6
- data/lib/knapsack_pro/runners/queue/minitest_runner.rb +10 -6
- data/lib/knapsack_pro/runners/queue/rspec_runner.rb +124 -173
- data/lib/knapsack_pro/urls.rb +2 -0
- data/lib/knapsack_pro/version.rb +1 -1
- data/lib/knapsack_pro.rb +1 -0
- data/spec/integration/runners/queue/rspec_runner.rb +80 -0
- data/spec/integration/runners/queue/rspec_runner_spec.rb +2232 -0
- data/spec/knapsack_pro/adapters/base_adapter_spec.rb +17 -11
- data/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb +2 -5
- data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +2 -24
- data/spec/knapsack_pro/config/env_spec.rb +1 -35
- data/spec/knapsack_pro/formatters/time_tracker_specs.rb +8 -37
- data/spec/knapsack_pro/hooks/queue_spec.rb +2 -2
- data/spec/knapsack_pro/presenter_spec.rb +1 -1
- data/spec/knapsack_pro/pure/queue/rspec_pure_spec.rb +224 -0
- data/spec/knapsack_pro/runners/queue/cucumber_runner_spec.rb +16 -16
- data/spec/knapsack_pro/runners/queue/minitest_runner_spec.rb +14 -14
- data/spec/knapsack_pro_spec.rb +3 -3
- data/spec/spec_helper.rb +0 -1
- metadata +17 -12
- data/lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb +0 -58
- data/lib/knapsack_pro/formatters/rspec_queue_summary_formatter.rb +0 -145
- data/spec/knapsack_pro/runners/queue/rspec_runner_spec.rb +0 -536
@@ -1,536 +0,0 @@
|
|
1
|
-
describe KnapsackPro::Runners::Queue::RSpecRunner do
|
2
|
-
before do
|
3
|
-
# we don't want to modify rspec formatters because we want to see tests summary at the end
|
4
|
-
# when you run this test file or whole test suite for the knapsack_pro gem
|
5
|
-
stub_const('ENV', { 'KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS' => false })
|
6
|
-
|
7
|
-
require KnapsackPro.root + '/lib/knapsack_pro/formatters/rspec_queue_summary_formatter'
|
8
|
-
require KnapsackPro.root + '/lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension'
|
9
|
-
require KnapsackPro.root + '/lib/knapsack_pro/formatters/time_tracker'
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '.run' do
|
13
|
-
let(:test_suite_token_rspec) { 'fake-token' }
|
14
|
-
let(:queue_id) { 'fake-queue-id' }
|
15
|
-
let(:test_dir) { 'fake-test-dir' }
|
16
|
-
let(:runner) do
|
17
|
-
instance_double(described_class, test_dir: test_dir)
|
18
|
-
end
|
19
|
-
|
20
|
-
subject { described_class.run(args) }
|
21
|
-
|
22
|
-
before do
|
23
|
-
expect(KnapsackPro::Config::Env).to receive(:test_suite_token_rspec).and_return(test_suite_token_rspec)
|
24
|
-
expect(KnapsackPro::Config::EnvGenerator).to receive(:set_queue_id).and_return(queue_id)
|
25
|
-
|
26
|
-
expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_TEST_SUITE_TOKEN', test_suite_token_rspec)
|
27
|
-
expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_QUEUE_RECORDING_ENABLED', 'true')
|
28
|
-
expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_QUEUE_ID', queue_id)
|
29
|
-
|
30
|
-
expect(KnapsackPro::Config::Env).to receive(:set_test_runner_adapter).with(KnapsackPro::Adapters::RSpecAdapter)
|
31
|
-
|
32
|
-
expect(described_class).to receive(:new).with(KnapsackPro::Adapters::RSpecAdapter).and_return(runner)
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when args provided' do
|
36
|
-
context 'when format option is not provided' do
|
37
|
-
let(:args) { '--example-arg example-value' }
|
38
|
-
|
39
|
-
it 'uses default formatter progress' do
|
40
|
-
expected_exitstatus = 0
|
41
|
-
expected_accumulator = {
|
42
|
-
status: :completed,
|
43
|
-
exitstatus: expected_exitstatus
|
44
|
-
}
|
45
|
-
accumulator = {
|
46
|
-
status: :next,
|
47
|
-
runner: runner,
|
48
|
-
can_initialize_queue: true,
|
49
|
-
args: [
|
50
|
-
'--example-arg', 'example-value',
|
51
|
-
'--format', 'progress',
|
52
|
-
'--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter',
|
53
|
-
'--format', 'KnapsackPro::Formatters::TimeTracker',
|
54
|
-
'--default-path', 'fake-test-dir',
|
55
|
-
],
|
56
|
-
exitstatus: 0,
|
57
|
-
all_test_file_paths: [],
|
58
|
-
}
|
59
|
-
expect(described_class).to receive(:handle_signal!)
|
60
|
-
expect(described_class).to receive(:run_tests).with(accumulator).and_return(expected_accumulator)
|
61
|
-
|
62
|
-
expect(Kernel).to receive(:exit).with(expected_exitstatus)
|
63
|
-
|
64
|
-
subject
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'when format option is provided as --format' do
|
69
|
-
let(:args) { '--format documentation' }
|
70
|
-
|
71
|
-
it 'uses provided format option instead of default formatter progress' do
|
72
|
-
expected_exitstatus = 0
|
73
|
-
expected_accumulator = {
|
74
|
-
status: :completed,
|
75
|
-
exitstatus: expected_exitstatus
|
76
|
-
}
|
77
|
-
accumulator = {
|
78
|
-
status: :next,
|
79
|
-
runner: runner,
|
80
|
-
can_initialize_queue: true,
|
81
|
-
args: [
|
82
|
-
'--format', 'documentation',
|
83
|
-
'--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter',
|
84
|
-
'--format', 'KnapsackPro::Formatters::TimeTracker',
|
85
|
-
'--default-path', 'fake-test-dir',
|
86
|
-
],
|
87
|
-
exitstatus: 0,
|
88
|
-
all_test_file_paths: [],
|
89
|
-
}
|
90
|
-
expect(described_class).to receive(:handle_signal!)
|
91
|
-
expect(described_class).to receive(:run_tests).with(accumulator).and_return(expected_accumulator)
|
92
|
-
|
93
|
-
expect(Kernel).to receive(:exit).with(expected_exitstatus)
|
94
|
-
|
95
|
-
subject
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'when format option is provided as -f' do
|
100
|
-
let(:args) { '-f d' }
|
101
|
-
|
102
|
-
it 'uses provided format option instead of default formatter progress' do
|
103
|
-
expected_exitstatus = 0
|
104
|
-
expected_accumulator = {
|
105
|
-
status: :completed,
|
106
|
-
exitstatus: expected_exitstatus
|
107
|
-
}
|
108
|
-
accumulator = {
|
109
|
-
status: :next,
|
110
|
-
runner: runner,
|
111
|
-
can_initialize_queue: true,
|
112
|
-
args: [
|
113
|
-
'-f', 'd',
|
114
|
-
'--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter',
|
115
|
-
'--format', 'KnapsackPro::Formatters::TimeTracker',
|
116
|
-
'--default-path', 'fake-test-dir',
|
117
|
-
],
|
118
|
-
exitstatus: 0,
|
119
|
-
all_test_file_paths: [],
|
120
|
-
}
|
121
|
-
expect(described_class).to receive(:handle_signal!)
|
122
|
-
expect(described_class).to receive(:run_tests).with(accumulator).and_return(expected_accumulator)
|
123
|
-
|
124
|
-
expect(Kernel).to receive(:exit).with(expected_exitstatus)
|
125
|
-
|
126
|
-
subject
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'when format option is provided without a delimiter' do
|
131
|
-
let(:args) { '-fMyCustomFormatter' }
|
132
|
-
|
133
|
-
it 'uses provided format option instead of default formatter progress' do
|
134
|
-
expected_exitstatus = 0
|
135
|
-
expected_accumulator = {
|
136
|
-
status: :completed,
|
137
|
-
exitstatus: expected_exitstatus
|
138
|
-
}
|
139
|
-
accumulator = {
|
140
|
-
status: :next,
|
141
|
-
runner: runner,
|
142
|
-
can_initialize_queue: true,
|
143
|
-
args: [
|
144
|
-
'-fMyCustomFormatter',
|
145
|
-
'--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter',
|
146
|
-
'--format', 'KnapsackPro::Formatters::TimeTracker',
|
147
|
-
'--default-path', 'fake-test-dir',
|
148
|
-
],
|
149
|
-
exitstatus: 0,
|
150
|
-
all_test_file_paths: [],
|
151
|
-
}
|
152
|
-
expect(described_class).to receive(:handle_signal!)
|
153
|
-
expect(described_class).to receive(:run_tests).with(accumulator).and_return(expected_accumulator)
|
154
|
-
|
155
|
-
expect(Kernel).to receive(:exit).with(expected_exitstatus)
|
156
|
-
|
157
|
-
subject
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'when RSpec split by test examples feature is enabled' do
|
162
|
-
before do
|
163
|
-
expect(KnapsackPro::Config::Env).to receive(:rspec_split_by_test_examples?).and_return(true)
|
164
|
-
expect(KnapsackPro::Adapters::RSpecAdapter).to receive(:ensure_no_tag_option_when_rspec_split_by_test_examples_enabled!).and_call_original
|
165
|
-
end
|
166
|
-
|
167
|
-
context 'when tag option is provided' do
|
168
|
-
let(:args) { '--tag example-value' }
|
169
|
-
|
170
|
-
it do
|
171
|
-
expect { subject }.to raise_error(/It is not allowed to use the RSpec tag option together with the RSpec split by test examples feature/)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
context 'when args not provided' do
|
178
|
-
let(:args) { nil }
|
179
|
-
|
180
|
-
it do
|
181
|
-
expected_exitstatus = 0
|
182
|
-
expected_accumulator = {
|
183
|
-
status: :completed,
|
184
|
-
exitstatus: expected_exitstatus
|
185
|
-
}
|
186
|
-
accumulator = {
|
187
|
-
status: :next,
|
188
|
-
runner: runner,
|
189
|
-
can_initialize_queue: true,
|
190
|
-
args: [
|
191
|
-
'--format', 'progress',
|
192
|
-
'--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter',
|
193
|
-
'--format', 'KnapsackPro::Formatters::TimeTracker',
|
194
|
-
'--default-path', 'fake-test-dir',
|
195
|
-
],
|
196
|
-
exitstatus: 0,
|
197
|
-
all_test_file_paths: [],
|
198
|
-
}
|
199
|
-
expect(described_class).to receive(:handle_signal!)
|
200
|
-
expect(described_class).to receive(:run_tests).with(accumulator).and_return(expected_accumulator)
|
201
|
-
|
202
|
-
expect(Kernel).to receive(:exit).with(expected_exitstatus)
|
203
|
-
|
204
|
-
subject
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe '.run_tests' do
|
210
|
-
let(:runner) { instance_double(described_class) }
|
211
|
-
let(:can_initialize_queue) { double(:can_initialize_queue) }
|
212
|
-
let(:args) { ['--no-color', '--default-path', 'fake-test-dir'] }
|
213
|
-
let(:exitstatus) { double }
|
214
|
-
let(:all_test_file_paths) { [] }
|
215
|
-
let(:accumulator) do
|
216
|
-
{
|
217
|
-
runner: runner,
|
218
|
-
can_initialize_queue: can_initialize_queue,
|
219
|
-
args: args,
|
220
|
-
exitstatus: exitstatus,
|
221
|
-
all_test_file_paths: all_test_file_paths,
|
222
|
-
}
|
223
|
-
end
|
224
|
-
|
225
|
-
subject { described_class.run_tests(accumulator) }
|
226
|
-
|
227
|
-
before do
|
228
|
-
expect(runner).to receive(:test_file_paths).with(can_initialize_queue: can_initialize_queue, executed_test_files: all_test_file_paths).and_return(test_file_paths)
|
229
|
-
end
|
230
|
-
|
231
|
-
context 'when test files exist' do
|
232
|
-
let(:test_file_paths) { ['a_spec.rb', 'b_spec.rb'] }
|
233
|
-
let(:logger) { double }
|
234
|
-
let(:rspec_seed) { 7771 }
|
235
|
-
let(:exit_code) { [0, 1].sample }
|
236
|
-
let(:rspec_wants_to_quit) { false }
|
237
|
-
let(:rspec_is_quitting) { false }
|
238
|
-
let(:rspec_core_runner) do
|
239
|
-
double(world: double(wants_to_quit: rspec_wants_to_quit, rspec_is_quitting: rspec_is_quitting))
|
240
|
-
end
|
241
|
-
|
242
|
-
context 'having no exception when running RSpec' do
|
243
|
-
before do
|
244
|
-
subset_queue_id = 'fake-subset-queue-id'
|
245
|
-
expect(KnapsackPro::Config::EnvGenerator).to receive(:set_subset_queue_id).and_return(subset_queue_id)
|
246
|
-
|
247
|
-
expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_SUBSET_QUEUE_ID', subset_queue_id)
|
248
|
-
|
249
|
-
expect(described_class).to receive(:ensure_spec_opts_have_knapsack_pro_formatters)
|
250
|
-
options = double
|
251
|
-
expect(RSpec::Core::ConfigurationOptions).to receive(:new).with([
|
252
|
-
'--no-color',
|
253
|
-
'--default-path', 'fake-test-dir',
|
254
|
-
'a_spec.rb', 'b_spec.rb',
|
255
|
-
]).and_return(options)
|
256
|
-
|
257
|
-
expect(RSpec::Core::Runner).to receive(:new).with(options).and_return(rspec_core_runner)
|
258
|
-
expect(rspec_core_runner).to receive(:run).with($stderr, $stdout).and_return(exit_code)
|
259
|
-
|
260
|
-
expect(described_class).to receive(:rspec_clear_examples)
|
261
|
-
|
262
|
-
expect(KnapsackPro::Hooks::Queue).to receive(:call_before_subset_queue)
|
263
|
-
|
264
|
-
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
|
265
|
-
|
266
|
-
configuration = double
|
267
|
-
expect(rspec_core_runner).to receive(:configuration).twice.and_return(configuration)
|
268
|
-
expect(configuration).to receive(:seed_used?).and_return(true)
|
269
|
-
expect(configuration).to receive(:seed).and_return(rspec_seed)
|
270
|
-
|
271
|
-
expect(KnapsackPro).to receive(:logger).at_least(2).and_return(logger)
|
272
|
-
expect(logger).to receive(:info)
|
273
|
-
.with("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine:")
|
274
|
-
expect(logger).to receive(:info).with(/#{args.join(' ')} --seed #{rspec_seed}/)
|
275
|
-
end
|
276
|
-
|
277
|
-
context 'when the exit code is zero' do
|
278
|
-
let(:exit_code) { 0 }
|
279
|
-
|
280
|
-
it do
|
281
|
-
expect(subject).to eq({
|
282
|
-
status: :next,
|
283
|
-
runner: runner,
|
284
|
-
can_initialize_queue: false,
|
285
|
-
args: args,
|
286
|
-
exitstatus: exitstatus,
|
287
|
-
all_test_file_paths: test_file_paths,
|
288
|
-
})
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context 'when the exit code is not zero' do
|
293
|
-
let(:exit_code) { double }
|
294
|
-
|
295
|
-
it do
|
296
|
-
expect(subject).to eq({
|
297
|
-
status: :next,
|
298
|
-
runner: runner,
|
299
|
-
can_initialize_queue: false,
|
300
|
-
args: args,
|
301
|
-
exitstatus: exit_code,
|
302
|
-
all_test_file_paths: test_file_paths,
|
303
|
-
})
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'when RSpec wants to quit' do
|
308
|
-
let(:exit_code) { 0 }
|
309
|
-
let(:rspec_wants_to_quit) { true }
|
310
|
-
|
311
|
-
after do
|
312
|
-
described_class.class_variable_set(:@@terminate_process, false)
|
313
|
-
end
|
314
|
-
|
315
|
-
it 'terminates the process' do
|
316
|
-
expect(logger).to receive(:warn).with('RSpec wants to quit.')
|
317
|
-
|
318
|
-
expect(described_class.class_variable_get(:@@terminate_process)).to be false
|
319
|
-
|
320
|
-
expect(subject).to eq({
|
321
|
-
status: :next,
|
322
|
-
runner: runner,
|
323
|
-
can_initialize_queue: false,
|
324
|
-
args: args,
|
325
|
-
exitstatus: exitstatus,
|
326
|
-
all_test_file_paths: test_file_paths,
|
327
|
-
})
|
328
|
-
|
329
|
-
expect(described_class.class_variable_get(:@@terminate_process)).to be true
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
context 'when RSpec is quitting' do
|
334
|
-
let(:exit_code) { 0 }
|
335
|
-
let(:rspec_is_quitting) { true }
|
336
|
-
|
337
|
-
after do
|
338
|
-
described_class.class_variable_set(:@@terminate_process, false)
|
339
|
-
end
|
340
|
-
|
341
|
-
it 'terminates the process' do
|
342
|
-
expect(logger).to receive(:warn).with('RSpec is quitting.')
|
343
|
-
|
344
|
-
expect(described_class.class_variable_get(:@@terminate_process)).to be false
|
345
|
-
|
346
|
-
expect(subject).to eq({
|
347
|
-
status: :next,
|
348
|
-
runner: runner,
|
349
|
-
can_initialize_queue: false,
|
350
|
-
args: args,
|
351
|
-
exitstatus: exitstatus,
|
352
|
-
all_test_file_paths: test_file_paths,
|
353
|
-
})
|
354
|
-
|
355
|
-
expect(described_class.class_variable_get(:@@terminate_process)).to be true
|
356
|
-
end
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
context 'having exception when running RSpec' do
|
361
|
-
before do
|
362
|
-
subset_queue_id = 'fake-subset-queue-id'
|
363
|
-
expect(KnapsackPro::Config::EnvGenerator).to receive(:set_subset_queue_id).and_return(subset_queue_id)
|
364
|
-
|
365
|
-
expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_SUBSET_QUEUE_ID', subset_queue_id)
|
366
|
-
|
367
|
-
expect(described_class).to receive(:ensure_spec_opts_have_knapsack_pro_formatters)
|
368
|
-
options = double
|
369
|
-
expect(RSpec::Core::ConfigurationOptions).to receive(:new).with([
|
370
|
-
'--no-color',
|
371
|
-
'--default-path', 'fake-test-dir',
|
372
|
-
'a_spec.rb', 'b_spec.rb',
|
373
|
-
]).and_return(options)
|
374
|
-
|
375
|
-
rspec_core_runner = double
|
376
|
-
expect(RSpec::Core::Runner).to receive(:new).with(options).and_return(rspec_core_runner)
|
377
|
-
expect(rspec_core_runner).to receive(:run).with($stderr, $stdout).and_raise SystemExit
|
378
|
-
expect(KnapsackPro::Hooks::Queue).to receive(:call_before_subset_queue)
|
379
|
-
allow(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
|
380
|
-
allow(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
381
|
-
allow(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_exit_summary)
|
382
|
-
expect(Kernel).to receive(:exit).with(1)
|
383
|
-
end
|
384
|
-
|
385
|
-
it 'does not call #rspec_clear_examples' do
|
386
|
-
expect(described_class).not_to receive(:rspec_clear_examples)
|
387
|
-
expect { subject }.to raise_error SystemExit
|
388
|
-
end
|
389
|
-
|
390
|
-
it 'logs the exception' do
|
391
|
-
expect(KnapsackPro).to receive(:logger).once.and_return(logger)
|
392
|
-
expect(logger).to receive(:error).with("Having exception when running RSpec: #<SystemExit: SystemExit>")
|
393
|
-
expect { subject }.to raise_error SystemExit
|
394
|
-
end
|
395
|
-
|
396
|
-
it 'calls #print_exit_summary' do
|
397
|
-
expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_exit_summary)
|
398
|
-
expect { subject }.to raise_error SystemExit
|
399
|
-
end
|
400
|
-
|
401
|
-
it 'calls #call_after_subset_queue and #call_after_queue' do
|
402
|
-
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
|
403
|
-
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
404
|
-
expect { subject }.to raise_error SystemExit
|
405
|
-
end
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
context "when test files don't exist" do
|
410
|
-
let(:test_file_paths) { [] }
|
411
|
-
|
412
|
-
context 'when all_test_file_paths exist' do
|
413
|
-
let(:all_test_file_paths) { ['a_spec.rb'] }
|
414
|
-
let(:logger) { double }
|
415
|
-
|
416
|
-
before do
|
417
|
-
described_class.class_variable_set(:@@used_seed, used_seed)
|
418
|
-
|
419
|
-
expect(KnapsackPro).to receive(:logger).twice.and_return(logger)
|
420
|
-
|
421
|
-
expect(KnapsackPro::Adapters::RSpecAdapter).to receive(:verify_bind_method_called)
|
422
|
-
|
423
|
-
expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_summary)
|
424
|
-
expect(KnapsackPro::Formatters::RSpecQueueProfileFormatterExtension).to receive(:print_summary)
|
425
|
-
|
426
|
-
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
427
|
-
|
428
|
-
time_tracker = instance_double(KnapsackPro::Formatters::TimeTracker)
|
429
|
-
times = all_test_file_paths.map do |path|
|
430
|
-
[{ path: path, time_execution: 1.0 }]
|
431
|
-
end
|
432
|
-
expect(time_tracker).to receive(:queue).and_return(times)
|
433
|
-
expect(KnapsackPro::Formatters::TimeTrackerFetcher).to receive(:call).and_return(time_tracker)
|
434
|
-
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api).with(times)
|
435
|
-
|
436
|
-
expect(logger).to receive(:info)
|
437
|
-
.with('To retry all the tests assigned to this CI node, please run the following command on your machine:')
|
438
|
-
expect(logger).to receive(:info).with(logged_rspec_command_matcher)
|
439
|
-
end
|
440
|
-
|
441
|
-
context 'when @@used_seed has been set' do
|
442
|
-
let(:used_seed) { '8333' }
|
443
|
-
let(:logged_rspec_command_matcher) { /#{args.join(' ')} --seed #{used_seed} \"a_spec.rb"/ }
|
444
|
-
|
445
|
-
it do
|
446
|
-
expect(subject).to eq({
|
447
|
-
status: :completed,
|
448
|
-
exitstatus: exitstatus,
|
449
|
-
})
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
context 'when @@used_seed has not been set' do
|
454
|
-
let(:used_seed) { nil }
|
455
|
-
let(:logged_rspec_command_matcher) { /#{args.join(' ')} \"a_spec.rb"/ }
|
456
|
-
|
457
|
-
it do
|
458
|
-
expect(subject).to eq({
|
459
|
-
status: :completed,
|
460
|
-
exitstatus: exitstatus,
|
461
|
-
})
|
462
|
-
end
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
|
-
context "when all_test_file_paths don't exist" do
|
467
|
-
let(:all_test_file_paths) { [] }
|
468
|
-
|
469
|
-
it do
|
470
|
-
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
471
|
-
|
472
|
-
time_tracker = instance_double(KnapsackPro::Formatters::TimeTracker)
|
473
|
-
times = all_test_file_paths.map do |path|
|
474
|
-
[{ path: path, time_execution: 0.0 }]
|
475
|
-
end
|
476
|
-
expect(time_tracker).to receive(:queue).and_return(times)
|
477
|
-
expect(KnapsackPro::Formatters::TimeTrackerFetcher).to receive(:call).and_return(time_tracker)
|
478
|
-
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api).with(times)
|
479
|
-
|
480
|
-
expect(KnapsackPro).to_not receive(:logger)
|
481
|
-
|
482
|
-
expect(subject).to eq({
|
483
|
-
status: :completed,
|
484
|
-
exitstatus: exitstatus,
|
485
|
-
})
|
486
|
-
end
|
487
|
-
end
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
|
-
describe '.ensure_spec_opts_have_knapsack_pro_formatters' do
|
492
|
-
subject { described_class.ensure_spec_opts_have_knapsack_pro_formatters }
|
493
|
-
|
494
|
-
context 'when `SPEC_OPTS` is set' do
|
495
|
-
context 'when `SPEC_OPTS` has RSpecQueueSummaryFormatter' do
|
496
|
-
before do
|
497
|
-
stub_const('ENV', { 'SPEC_OPTS' => '--format json --format KnapsackPro::Formatters::RSpecQueueSummaryFormatter' })
|
498
|
-
end
|
499
|
-
|
500
|
-
it 'adds TimeTracker' do
|
501
|
-
subject
|
502
|
-
expect(ENV['SPEC_OPTS']).to eq '--format json --format KnapsackPro::Formatters::RSpecQueueSummaryFormatter --format KnapsackPro::Formatters::TimeTracker'
|
503
|
-
end
|
504
|
-
end
|
505
|
-
|
506
|
-
context 'when `SPEC_OPTS` has TimeTracker' do
|
507
|
-
before do
|
508
|
-
stub_const('ENV', { 'SPEC_OPTS' => '--format json --format KnapsackPro::Formatters::TimeTracker' })
|
509
|
-
end
|
510
|
-
|
511
|
-
it 'adds RSpecQueueSummaryFormatter' do
|
512
|
-
subject
|
513
|
-
expect(ENV['SPEC_OPTS']).to eq '--format json --format KnapsackPro::Formatters::TimeTracker --format KnapsackPro::Formatters::RSpecQueueSummaryFormatter'
|
514
|
-
end
|
515
|
-
end
|
516
|
-
|
517
|
-
context 'when `SPEC_OPTS` has no Knapsack Pro formatters' do
|
518
|
-
before do
|
519
|
-
stub_const('ENV', { 'SPEC_OPTS' => '--format json' })
|
520
|
-
end
|
521
|
-
|
522
|
-
it 'adds RSpecQueueSummaryFormatter and TimeTracker to `SPEC_OPTS`' do
|
523
|
-
subject
|
524
|
-
expect(ENV['SPEC_OPTS']).to eq '--format json --format KnapsackPro::Formatters::RSpecQueueSummaryFormatter --format KnapsackPro::Formatters::TimeTracker'
|
525
|
-
end
|
526
|
-
end
|
527
|
-
end
|
528
|
-
|
529
|
-
context 'when `SPEC_OPTS` is not set' do
|
530
|
-
it 'does nothing' do
|
531
|
-
subject
|
532
|
-
expect(ENV['SPEC_OPTS']).to be_nil
|
533
|
-
end
|
534
|
-
end
|
535
|
-
end
|
536
|
-
end
|