knapsack_pro 8.3.3 → 9.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 +1 -2
- data/.gitignore +0 -1
- data/CHANGELOG.md +23 -2
- data/README.md +1 -1
- data/knapsack_pro.gemspec +1 -1
- data/lib/knapsack_pro/client/api/v1/queues.rb +1 -0
- data/lib/knapsack_pro/client/connection.rb +97 -52
- data/lib/knapsack_pro/config/ci/github_actions.rb +6 -4
- data/lib/knapsack_pro/queue_allocator.rb +13 -12
- data/lib/knapsack_pro/version.rb +1 -1
- data/lib/knapsack_pro.rb +9 -3
- data/spec/integration/runners/fallback_spec.rb +4 -4
- data/spec/integration/runners/queue/cucumber_runner_fallback_spec.rb +4 -4
- data/spec/integration/runners/queue/minitest_runner_fallback_spec.rb +4 -4
- data/spec/integration/runners/queue/rspec_runner_fallback_spec.rb +4 -4
- data/spec/integration/runners/queue/rspec_runner_spec.rb +20 -20
- data/spec/knapsack_pro/client/api/v1/queues_spec.rb +3 -1
- data/spec/knapsack_pro/client/connection_spec.rb +19 -15
- data/spec/knapsack_pro/config/ci/github_actions_spec.rb +40 -18
- data/spec/knapsack_pro/config/env_spec.rb +330 -352
- data/spec/knapsack_pro/formatters/time_tracker_spec.rb +448 -0
- data/spec/knapsack_pro/pure/queue/rspec_pure_spec.rb +5 -5
- data/spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb +1 -1
- data/spec/knapsack_pro_spec.rb +63 -39
- data/spec_time_tracker/spec_helper.rb +29 -0
- metadata +6 -9
- data/bin/test +0 -15
- data/lib/knapsack_pro/logger_wrapper.rb +0 -22
- data/spec/knapsack_pro/formatters/time_tracker_specs.rb +0 -545
- data/spec/knapsack_pro/logger_wrapper_spec.rb +0 -21
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
require 'open3'
|
|
2
|
+
require 'tmpdir'
|
|
3
|
+
|
|
4
|
+
describe 'TimeTracker' do
|
|
5
|
+
around(:each) do |example|
|
|
6
|
+
Dir.mktmpdir(nil, 'spec_time_tracker') do |dir|
|
|
7
|
+
@dir = dir
|
|
8
|
+
example.run
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe '#queue' do
|
|
13
|
+
it 'single example' do
|
|
14
|
+
spec = <<~SPEC
|
|
15
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
16
|
+
it do
|
|
17
|
+
sleep 0.1
|
|
18
|
+
expect(1).to eq 1
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
SPEC
|
|
22
|
+
|
|
23
|
+
run_specs(spec, 'queue') do |spec_paths, queue|
|
|
24
|
+
expect(queue.size).to eq(1)
|
|
25
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
26
|
+
expect(queue[0]['time_execution']).to be_between(0.10, 0.15)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'two files' do
|
|
31
|
+
spec0 = <<~SPEC
|
|
32
|
+
describe 'KnapsackPro::Formatters::TimeTracker 1' do
|
|
33
|
+
it do
|
|
34
|
+
sleep 0.1
|
|
35
|
+
expect(1).to eq 1
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
SPEC
|
|
39
|
+
|
|
40
|
+
spec1 = <<~SPEC
|
|
41
|
+
describe 'KnapsackPro::Formatters::TimeTracker 2' do
|
|
42
|
+
it do
|
|
43
|
+
sleep 0.2
|
|
44
|
+
expect(1).to eq 1
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
SPEC
|
|
48
|
+
|
|
49
|
+
run_specs([spec0, spec1], 'queue') do |spec_paths, queue|
|
|
50
|
+
expect(queue.size).to eq(2)
|
|
51
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
52
|
+
expect(queue[0]['time_execution']).to be_between(0.10, 0.15)
|
|
53
|
+
expect(queue[1]['path']).to eq(spec_paths[1])
|
|
54
|
+
expect(queue[1]['time_execution']).to be_between(0.20, 0.25)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'failing example' do
|
|
59
|
+
spec = <<~SPEC
|
|
60
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
61
|
+
it do
|
|
62
|
+
sleep 0.1
|
|
63
|
+
expect(1).to eq 2
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
SPEC
|
|
67
|
+
|
|
68
|
+
run_specs(spec, 'queue') do |spec_paths, queue|
|
|
69
|
+
expect(queue.size).to eq(1)
|
|
70
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
71
|
+
expect(queue[0]['time_execution']).to be_between(0.10, 0.15)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'pending example' do
|
|
76
|
+
spec = <<~SPEC
|
|
77
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
78
|
+
xit do
|
|
79
|
+
sleep 0.1
|
|
80
|
+
expect(1).to eq 2
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
SPEC
|
|
84
|
+
|
|
85
|
+
run_specs(spec, 'queue') do |spec_paths, queue|
|
|
86
|
+
expect(queue.size).to eq(1)
|
|
87
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
88
|
+
expect(queue[0]['time_execution']).to eq(0.0)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'multiple top level groups' do
|
|
93
|
+
spec = <<~SPEC
|
|
94
|
+
describe 'KnapsackPro::Formatters::TimeTracker 1' do
|
|
95
|
+
it do
|
|
96
|
+
sleep 0.1
|
|
97
|
+
expect(1).to eq 1
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe 'KnapsackPro::Formatters::TimeTracker 2' do
|
|
102
|
+
it do
|
|
103
|
+
sleep 0.2
|
|
104
|
+
expect(1).to eq 1
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
SPEC
|
|
108
|
+
|
|
109
|
+
run_specs(spec, 'queue') do |spec_paths, queue|
|
|
110
|
+
expect(queue.size).to eq(1)
|
|
111
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
112
|
+
expect(queue[0]['time_execution']).to be_between(0.30, 0.35)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'rspec split by test example' do
|
|
117
|
+
spec = <<~SPEC
|
|
118
|
+
describe 'KnapsackPro::Formatters::TimeTracker 1' do
|
|
119
|
+
it do
|
|
120
|
+
expect(1).to eq 1
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it do
|
|
124
|
+
sleep 0.1
|
|
125
|
+
expect(1).to eq 1
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe 'KnapsackPro::Formatters::TimeTracker 2' do
|
|
130
|
+
it do
|
|
131
|
+
sleep 0.2
|
|
132
|
+
expect(1).to eq 1
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it do
|
|
136
|
+
sleep 0.3
|
|
137
|
+
expect(1).to eq 1
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
SPEC
|
|
141
|
+
|
|
142
|
+
run_specs(spec, 'queue', env: 'TEST__SBTE=1') do |spec_paths, queue|
|
|
143
|
+
expect(queue.size).to eq(4)
|
|
144
|
+
|
|
145
|
+
spec_path = spec_paths[0]
|
|
146
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[1:1]" }['time_execution']).to be_between(0.00, 0.05).exclusive
|
|
147
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[1:2]" }['time_execution']).to be_between(0.10, 0.15)
|
|
148
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[2:1]" }['time_execution']).to be_between(0.20, 0.25)
|
|
149
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[2:2]" }['time_execution']).to be_between(0.30, 0.35)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'hooks' do
|
|
154
|
+
spec = <<~SPEC
|
|
155
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
156
|
+
before(:all) do
|
|
157
|
+
sleep 0.1
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
before(:each) do
|
|
161
|
+
sleep 0.1
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
after(:each) do
|
|
165
|
+
sleep 0.1
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it do
|
|
169
|
+
expect(1).to eq 1
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it do
|
|
173
|
+
expect(1).to eq 1
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
after(:all) do
|
|
177
|
+
sleep 0.1
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
SPEC
|
|
181
|
+
|
|
182
|
+
run_specs(spec, 'queue') do |spec_paths, queue|
|
|
183
|
+
expect(queue.size).to eq(1)
|
|
184
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
185
|
+
expect(queue[0]['time_execution']).to be_between(0.60, 0.65)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it 'nested hooks' do
|
|
190
|
+
spec = <<~SPEC
|
|
191
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
192
|
+
before(:all) do
|
|
193
|
+
sleep 0.1
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
after(:all) do
|
|
197
|
+
sleep 0.1
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it do
|
|
201
|
+
expect(1).to eq 1
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
describe do
|
|
205
|
+
before(:all) do
|
|
206
|
+
sleep 0.1
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
after(:all) do
|
|
210
|
+
sleep 0.1
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it do
|
|
214
|
+
expect(1).to eq 1
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe do
|
|
219
|
+
before(:all) do
|
|
220
|
+
sleep 0.1
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
after(:all) do
|
|
224
|
+
sleep 0.1
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
it do
|
|
228
|
+
expect(1).to eq 1
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
SPEC
|
|
233
|
+
|
|
234
|
+
run_specs(spec, 'queue') do |spec_paths, queue|
|
|
235
|
+
expect(queue.size).to eq(1)
|
|
236
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
237
|
+
expect(queue[0]['time_execution']).to be_between(0.60, 0.65)
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it 'hooks with rspec split by test example' do
|
|
242
|
+
spec = <<~SPEC
|
|
243
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
244
|
+
before(:all) do
|
|
245
|
+
sleep 0.1
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
before(:each) do
|
|
249
|
+
sleep 0.1
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
after(:each) do
|
|
253
|
+
sleep 0.1
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
it do
|
|
257
|
+
expect(1).to eq 1
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
it do
|
|
261
|
+
expect(1).to eq 1
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
after(:all) do
|
|
265
|
+
sleep 0.1
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
SPEC
|
|
269
|
+
|
|
270
|
+
run_specs(spec, 'queue', env: 'TEST__SBTE=1') do |spec_paths, queue|
|
|
271
|
+
expect(queue.size).to eq(2)
|
|
272
|
+
|
|
273
|
+
spec_path = spec_paths[0]
|
|
274
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[1:1]" }['time_execution']).to be_between(0.40, 0.45)
|
|
275
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[1:2]" }['time_execution']).to be_between(0.40, 0.45)
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
it 'nested hooks with rspec split by test example' do
|
|
280
|
+
spec = <<~SPEC
|
|
281
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
282
|
+
before(:all) do
|
|
283
|
+
sleep 0.1
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
after(:all) do
|
|
287
|
+
sleep 0.1
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
it do
|
|
291
|
+
expect(1).to eq 1
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
describe do
|
|
295
|
+
before(:all) do
|
|
296
|
+
sleep 0.1
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
after(:all) do
|
|
300
|
+
sleep 0.1
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
it do
|
|
304
|
+
expect(1).to eq 1
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
describe do
|
|
309
|
+
before(:all) do
|
|
310
|
+
sleep 0.1
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
after(:all) do
|
|
314
|
+
sleep 0.1
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
it do
|
|
318
|
+
expect(1).to eq 1
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
SPEC
|
|
323
|
+
|
|
324
|
+
run_specs(spec, 'queue', env: 'TEST__SBTE=1') do |spec_paths, queue|
|
|
325
|
+
expect(queue.size).to eq(3)
|
|
326
|
+
|
|
327
|
+
spec_path = spec_paths[0]
|
|
328
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[1:1]" }['time_execution']).to be_between(0.20, 0.25)
|
|
329
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[1:2:1]" }['time_execution']).to be_between(0.40, 0.45)
|
|
330
|
+
expect(queue.find { |time| time['path'] == "#{spec_path}[1:3:1]" }['time_execution']).to be_between(0.40, 0.45)
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
it 'unknown path' do
|
|
335
|
+
spec = <<~SPEC
|
|
336
|
+
RSpec.configure do |config|
|
|
337
|
+
config.before(:all) do
|
|
338
|
+
time_tracker = ::RSpec.configuration.formatters.find { |f| f.class.to_s == 'TestableTimeTracker' }
|
|
339
|
+
time_tracker.scheduled_paths = ['#{@dir}/0_spec.rb']
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
344
|
+
it do
|
|
345
|
+
expect(1).to eq 1
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
SPEC
|
|
349
|
+
|
|
350
|
+
run_specs(spec, 'queue', env: 'TEST__EMPTY_FILE_PATH=1') do |spec_paths, queue|
|
|
351
|
+
expect(queue.size).to eq(1)
|
|
352
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
353
|
+
expect(queue[0]['time_execution']).to eq(0.0)
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
it 'empty group' do
|
|
358
|
+
spec = <<~SPEC
|
|
359
|
+
RSpec.configure do |config|
|
|
360
|
+
config.before(:suite) do
|
|
361
|
+
time_tracker = ::RSpec.configuration.formatters.find { |f| f.class.to_s == 'TestableTimeTracker' }
|
|
362
|
+
time_tracker.scheduled_paths = ['#{@dir}/0_spec.rb']
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
367
|
+
end
|
|
368
|
+
SPEC
|
|
369
|
+
|
|
370
|
+
run_specs(spec, 'queue') do |spec_paths, queue|
|
|
371
|
+
expect(queue.size).to eq(1)
|
|
372
|
+
expect(queue[0]['path']).to eq(spec_paths[0])
|
|
373
|
+
expect(queue[0]['time_execution']).to eq(0.0)
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
describe '#duration' do
|
|
379
|
+
it do
|
|
380
|
+
spec = <<~SPEC
|
|
381
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
382
|
+
it do
|
|
383
|
+
expect(1).to eq 1
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
SPEC
|
|
387
|
+
|
|
388
|
+
run_specs(spec, 'duration') do |_, duration|
|
|
389
|
+
expect(duration).to be_between(0.00, 0.05).exclusive
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
describe '#unexecuted_test_files' do
|
|
395
|
+
it do
|
|
396
|
+
spec = <<~SPEC
|
|
397
|
+
RSpec.configure do |config|
|
|
398
|
+
config.before(:all) do
|
|
399
|
+
time_tracker = ::RSpec.configuration.formatters.find { |f| f.class.to_s == 'TestableTimeTracker' }
|
|
400
|
+
time_tracker.scheduled_paths = ['#{@dir}/0_spec.rb', 'foo_spec.rb[1:1]']
|
|
401
|
+
end
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
405
|
+
xit do
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
SPEC
|
|
409
|
+
|
|
410
|
+
run_specs(spec, 'unexecuted_test_files') do |spec_paths, unexecuted_test_files|
|
|
411
|
+
expect(unexecuted_test_files).to eq(["#{@dir}/0_spec.rb", 'foo_spec.rb[1:1]'])
|
|
412
|
+
end
|
|
413
|
+
end
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
describe '#batch' do
|
|
417
|
+
it do
|
|
418
|
+
spec = <<~SPEC
|
|
419
|
+
describe 'KnapsackPro::Formatters::TimeTracker' do
|
|
420
|
+
it do
|
|
421
|
+
sleep 0.1
|
|
422
|
+
expect(1).to eq 1
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
SPEC
|
|
426
|
+
|
|
427
|
+
run_specs(spec, 'batch') do |spec_paths, batch|
|
|
428
|
+
expect(batch.size).to eq(1)
|
|
429
|
+
expect(batch[0]['path']).to eq(spec_paths[0])
|
|
430
|
+
expect(batch[0]['time_execution']).to be_between(0.10, 0.15)
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
def run_specs(specs, method, env: '')
|
|
436
|
+
paths = Array(specs).map.with_index do |spec, i|
|
|
437
|
+
path = "#{@dir}/#{i}_spec.rb"
|
|
438
|
+
File.write(path, spec)
|
|
439
|
+
path
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
out, err, _status = Open3.capture3("#{env} TEST__METHOD=#{method} bundle exec rspec --default-path spec_time_tracker -f TestableTimeTracker spec_time_tracker")
|
|
443
|
+
puts err if ENV['TEST__DEBUG']
|
|
444
|
+
result = Marshal.load(out.lines.last)
|
|
445
|
+
|
|
446
|
+
yield(paths, result)
|
|
447
|
+
end
|
|
448
|
+
end
|
|
@@ -59,7 +59,7 @@ describe KnapsackPro::Pure::Queue::RSpecPure do
|
|
|
59
59
|
|
|
60
60
|
context 'when the order option is not random' do
|
|
61
61
|
let(:args) { ['--order', 'defined'] }
|
|
62
|
-
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new(
|
|
62
|
+
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new(nil, false) }
|
|
63
63
|
|
|
64
64
|
it 'does not add the seed option to args' do
|
|
65
65
|
expect(subject).to eq ['--order', 'defined']
|
|
@@ -71,7 +71,7 @@ describe KnapsackPro::Pure::Queue::RSpecPure do
|
|
|
71
71
|
let(:args) { ['--order', random_option_value] }
|
|
72
72
|
|
|
73
73
|
context 'when the seed is not used' do
|
|
74
|
-
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new(
|
|
74
|
+
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new('123', false) }
|
|
75
75
|
|
|
76
76
|
it 'does not add the seed option to args' do
|
|
77
77
|
expect(subject).to eq ['--order', random_option_value]
|
|
@@ -79,7 +79,7 @@ describe KnapsackPro::Pure::Queue::RSpecPure do
|
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
context 'when the seed is used' do
|
|
82
|
-
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new(
|
|
82
|
+
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new('123', true) }
|
|
83
83
|
|
|
84
84
|
it 'adds the seed option to args' do
|
|
85
85
|
expect(subject).to eq ['--order', random_option_value, '--seed', '123']
|
|
@@ -90,7 +90,7 @@ describe KnapsackPro::Pure::Queue::RSpecPure do
|
|
|
90
90
|
|
|
91
91
|
context 'when the order option is `rand:123`' do
|
|
92
92
|
let(:args) { ['--order', 'rand:123'] }
|
|
93
|
-
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new(
|
|
93
|
+
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new('123', true) }
|
|
94
94
|
|
|
95
95
|
it 'does not add the seed option to args' do
|
|
96
96
|
expect(subject).to eq ['--order', 'rand:123']
|
|
@@ -99,7 +99,7 @@ describe KnapsackPro::Pure::Queue::RSpecPure do
|
|
|
99
99
|
|
|
100
100
|
context 'when the order option is not set in args AND seed is used' do
|
|
101
101
|
let(:args) { ['--format', 'documentation'] }
|
|
102
|
-
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new(
|
|
102
|
+
let(:seed) { KnapsackPro::Extensions::RSpecExtension::Seed.new('123', true) }
|
|
103
103
|
|
|
104
104
|
it 'adds the seed option to args' do
|
|
105
105
|
expect(subject).to eq ['--format', 'documentation', '--seed', '123']
|
|
@@ -148,7 +148,7 @@ describe KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector do
|
|
|
148
148
|
subject_class.new.generate_json_report(rspec_args)
|
|
149
149
|
end
|
|
150
150
|
.to output(/Please only use one of `--force-color` and `--no-color`/).to_stderr
|
|
151
|
-
.and output(%r{ERROR -- :
|
|
151
|
+
.and output(%r{ERROR -- knapsack_pro: Failed to generate the slow test files report: bundle exec rspec --no-color --force-color --format json --dry-run --out .knapsack_pro/test_case_detectors/rspec/rspec_dry_run_json_report_node_0.json --default-path spec spec/a_spec.rb}).to_stdout
|
|
152
152
|
.and raise_error(SystemExit) { |error| expect(error.status).to eq 1 }
|
|
153
153
|
end
|
|
154
154
|
end
|
data/spec/knapsack_pro_spec.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'tmpdir'
|
|
2
|
+
|
|
1
3
|
describe KnapsackPro do
|
|
2
4
|
describe '.root' do
|
|
3
5
|
subject { described_class.root }
|
|
@@ -6,70 +8,92 @@ describe KnapsackPro do
|
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
describe '.logger' do
|
|
9
|
-
let(:logger_wrapper) { double }
|
|
10
|
-
|
|
11
11
|
subject { described_class.logger }
|
|
12
12
|
|
|
13
13
|
before(:each) do
|
|
14
14
|
described_class.reset_logger!
|
|
15
15
|
KnapsackPro::Config::Env.remove_instance_variable(:@ci_node_index) if KnapsackPro::Config::Env.instance_variable_defined?(:@ci_node_index)
|
|
16
16
|
end
|
|
17
|
+
|
|
17
18
|
after { described_class.reset_logger! }
|
|
18
19
|
|
|
19
20
|
context 'when KNAPSACK_PRO_LOG_DIR is set' do
|
|
20
|
-
let(:logger) { instance_double(Logger) }
|
|
21
|
-
|
|
22
21
|
context 'when KNAPSACK_PRO_CI_NODE_INDEX is set' do
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
'KNAPSACK_PRO_LOG_DIR' => '
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
it 'logs to a file in that dir named after the node index' do
|
|
23
|
+
Dir.mktmpdir do |dir|
|
|
24
|
+
stub_const('ENV', 'KNAPSACK_PRO_LOG_DIR' => dir, 'KNAPSACK_PRO_CI_NODE_INDEX' => 1)
|
|
25
|
+
|
|
26
|
+
KnapsackPro.logger.debug 'debug'
|
|
27
|
+
KnapsackPro.logger.info 'info'
|
|
28
|
+
KnapsackPro.logger.warn 'warn'
|
|
29
|
+
|
|
30
|
+
log = File.read "#{dir}/knapsack_pro_node_1.log"
|
|
31
|
+
expect(log).not_to include('DEBUG -- knapsack_pro: debug')
|
|
32
|
+
expect(log).to include('INFO -- knapsack_pro: info')
|
|
33
|
+
expect(log).to include('WARN -- knapsack_pro: warn')
|
|
34
|
+
end
|
|
32
35
|
end
|
|
33
|
-
|
|
34
|
-
it { should eql logger_wrapper }
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
context 'when KNAPSACK_PRO_CI_NODE_INDEX is not set' do
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
'KNAPSACK_PRO_LOG_DIR' =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
it 'logs to a file in that dir named after node index 0' do
|
|
40
|
+
Dir.mktmpdir do |dir|
|
|
41
|
+
stub_const('ENV', 'KNAPSACK_PRO_LOG_DIR' => dir)
|
|
42
|
+
|
|
43
|
+
KnapsackPro.logger.debug 'debug'
|
|
44
|
+
KnapsackPro.logger.info 'info'
|
|
45
|
+
KnapsackPro.logger.warn 'warn'
|
|
46
|
+
|
|
47
|
+
log = File.read "#{dir}/knapsack_pro_node_0.log"
|
|
48
|
+
expect(log).not_to include('DEBUG -- knapsack_pro: debug')
|
|
49
|
+
expect(log).to include('INFO -- knapsack_pro: info')
|
|
50
|
+
expect(log).to include('WARN -- knapsack_pro: warn')
|
|
51
|
+
end
|
|
46
52
|
end
|
|
47
|
-
|
|
48
|
-
it { should eql logger_wrapper }
|
|
49
53
|
end
|
|
50
54
|
end
|
|
51
55
|
|
|
52
|
-
context '
|
|
53
|
-
|
|
56
|
+
context 'with the default logger' do
|
|
57
|
+
it 'ignores debug to stdout' do
|
|
58
|
+
expect do
|
|
59
|
+
KnapsackPro.stdout = $stdout
|
|
60
|
+
KnapsackPro.logger.debug 'debug'
|
|
61
|
+
end
|
|
62
|
+
.not_to output.to_stdout
|
|
63
|
+
end
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
expect
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
it 'logs info to stdout' do
|
|
66
|
+
expect do
|
|
67
|
+
KnapsackPro.stdout = $stdout
|
|
68
|
+
KnapsackPro.logger.info 'info'
|
|
69
|
+
end
|
|
70
|
+
.to output(/INFO -- knapsack_pro: info/)
|
|
71
|
+
.to_stdout
|
|
59
72
|
end
|
|
60
73
|
|
|
61
|
-
it
|
|
74
|
+
it 'logs warn to stdout' do
|
|
75
|
+
expect do
|
|
76
|
+
KnapsackPro.stdout = $stdout
|
|
77
|
+
KnapsackPro.logger.warn 'warn'
|
|
78
|
+
end
|
|
79
|
+
.to output(/WARN -- knapsack_pro: warn/)
|
|
80
|
+
.to_stdout
|
|
81
|
+
end
|
|
62
82
|
end
|
|
63
83
|
|
|
64
|
-
context '
|
|
65
|
-
|
|
84
|
+
context 'with a custom logger' do
|
|
85
|
+
it 'logs using it' do
|
|
86
|
+
stream = StringIO.new
|
|
87
|
+
KnapsackPro.logger = ::Logger.new(stream)
|
|
66
88
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
end
|
|
89
|
+
KnapsackPro.logger.debug 'debug'
|
|
90
|
+
KnapsackPro.logger.info 'info'
|
|
91
|
+
KnapsackPro.logger.warn 'warn'
|
|
71
92
|
|
|
72
|
-
|
|
93
|
+
expect(stream.string).to include('DEBUG -- knapsack_pro: debug')
|
|
94
|
+
expect(stream.string).to include('INFO -- knapsack_pro: info')
|
|
95
|
+
expect(stream.string).to include('WARN -- knapsack_pro: warn')
|
|
96
|
+
end
|
|
73
97
|
end
|
|
74
98
|
end
|
|
75
99
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'knapsack_pro'
|
|
2
|
+
require_relative '../lib/knapsack_pro/formatters/time_tracker'
|
|
3
|
+
|
|
4
|
+
class TestableTimeTracker < KnapsackPro::Formatters::TimeTracker
|
|
5
|
+
::RSpec::Core::Formatters.register self, :dump_summary
|
|
6
|
+
|
|
7
|
+
if ENV['TEST__SBTE']
|
|
8
|
+
def rspec_split_by_test_example?(_file)
|
|
9
|
+
true
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
if ENV['TEST__EMPTY_FILE_PATH']
|
|
14
|
+
def file_path_for(_example)
|
|
15
|
+
''
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def dump_summary(_)
|
|
20
|
+
method = ENV['TEST__METHOD']
|
|
21
|
+
result = send(method)
|
|
22
|
+
puts Marshal.dump(result)
|
|
23
|
+
return if ENV['TEST__DEBUG'].nil?
|
|
24
|
+
|
|
25
|
+
warn 'DEBUG'
|
|
26
|
+
warn result
|
|
27
|
+
warn 'GUBED'
|
|
28
|
+
end
|
|
29
|
+
end
|