knapsack_pro 5.7.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +2 -0
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/bin/test +15 -0
- data/knapsack_pro.gemspec +5 -5
- data/lib/knapsack_pro/adapters/rspec_adapter.rb +45 -44
- data/lib/knapsack_pro/formatters/rspec_queue_summary_formatter.rb +6 -3
- data/lib/knapsack_pro/formatters/time_tracker.rb +161 -0
- data/lib/knapsack_pro/formatters/time_tracker_fetcher.rb +12 -0
- data/lib/knapsack_pro/presenter.rb +3 -2
- data/lib/knapsack_pro/report.rb +13 -9
- data/lib/knapsack_pro/runners/queue/rspec_runner.rb +25 -14
- data/lib/knapsack_pro/runners/rspec_runner.rb +19 -3
- data/lib/knapsack_pro/tracker.rb +1 -9
- data/lib/knapsack_pro/version.rb +1 -1
- data/lib/knapsack_pro.rb +0 -1
- data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +68 -158
- data/spec/knapsack_pro/formatters/time_tracker_specs.rb +453 -0
- data/spec/knapsack_pro/runners/queue/rspec_runner_spec.rb +71 -32
- data/spec/knapsack_pro/runners/rspec_runner_spec.rb +2 -5
- data/spec/knapsack_pro/tracker_spec.rb +0 -21
- metadata +9 -7
- data/lib/knapsack_pro/extensions/time.rb +0 -9
- data/spec/knapsack_pro/extensions/time_spec.rb +0 -5
data/lib/knapsack_pro.rb
CHANGED
@@ -11,7 +11,6 @@ require 'securerandom'
|
|
11
11
|
require 'timeout'
|
12
12
|
require_relative 'knapsack_pro/urls'
|
13
13
|
require_relative 'knapsack_pro/version'
|
14
|
-
require_relative 'knapsack_pro/extensions/time'
|
15
14
|
require_relative 'knapsack_pro/hooks/queue'
|
16
15
|
require_relative 'knapsack_pro/utils'
|
17
16
|
require_relative 'knapsack_pro/config/ci/base'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative '../../../lib/knapsack_pro/formatters/time_tracker'
|
2
|
+
|
1
3
|
describe KnapsackPro::Adapters::RSpecAdapter do
|
2
4
|
it 'backwards compatibility with knapsack gem old rspec adapter name' do
|
3
5
|
expect(KnapsackPro::Adapters::RspecAdapter.new).to be_kind_of(described_class)
|
@@ -8,7 +10,7 @@ describe KnapsackPro::Adapters::RSpecAdapter do
|
|
8
10
|
end
|
9
11
|
|
10
12
|
context do
|
11
|
-
before { expect(::RSpec).to receive(:configure) }
|
13
|
+
before { expect(::RSpec).to receive(:configure).at_least(:once) }
|
12
14
|
it_behaves_like 'adapter'
|
13
15
|
end
|
14
16
|
|
@@ -237,59 +239,70 @@ describe KnapsackPro::Adapters::RSpecAdapter do
|
|
237
239
|
end
|
238
240
|
end
|
239
241
|
|
240
|
-
describe '.
|
241
|
-
let(:
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
242
|
+
describe '.file_path_for' do
|
243
|
+
let(:current_example) { ::RSpec.describe.example }
|
244
|
+
|
245
|
+
subject { described_class.file_path_for(current_example) }
|
246
|
+
|
247
|
+
context "when id ends in _spec.rb" do
|
248
|
+
it "returns the first part of the id" do
|
249
|
+
allow(current_example).to receive(:id).and_return("./foo_spec.rb[1:1]")
|
250
|
+
|
251
|
+
expect(subject).to eq('./foo_spec.rb')
|
252
|
+
end
|
251
253
|
end
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
254
|
+
|
255
|
+
context "when id does not end in _spec.rb" do
|
256
|
+
it "returns the file_path" do
|
257
|
+
allow(current_example).to receive(:id).and_return("./foo.rb")
|
258
|
+
allow(current_example).to receive(:metadata).and_return(file_path: "./foo_spec.rb")
|
259
|
+
|
260
|
+
expect(subject).to eq('./foo_spec.rb')
|
261
|
+
end
|
256
262
|
end
|
257
263
|
|
258
|
-
|
264
|
+
context "when id and file_path do not end in _spec.rb" do
|
265
|
+
it "returns the example_group's file_path" do
|
266
|
+
allow(current_example).to receive(:id).and_return("./foo.rb")
|
267
|
+
allow(current_example).to receive(:metadata).and_return(
|
268
|
+
file_path: "./foo.rb", example_group: { file_path: "./foo_spec.rb" }
|
269
|
+
)
|
259
270
|
|
260
|
-
|
271
|
+
expect(subject).to eq('./foo_spec.rb')
|
272
|
+
end
|
273
|
+
end
|
261
274
|
|
262
|
-
context
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
275
|
+
context "when id, file_path, and example_group's file_path do not end in _spec.rb" do
|
276
|
+
it "returns the top_level_group's file_path" do
|
277
|
+
allow(current_example).to receive(:id).and_return("./foo.rb")
|
278
|
+
allow(current_example).to receive(:metadata).and_return(
|
279
|
+
file_path: "./foo.rb",
|
280
|
+
example_group: {
|
281
|
+
file_path: "./foo.rb",
|
268
282
|
parent_example_group: {
|
269
|
-
file_path: "
|
283
|
+
file_path: "./foo_spec.rb",
|
270
284
|
}
|
271
285
|
}
|
272
|
-
|
286
|
+
)
|
273
287
|
|
274
|
-
|
275
|
-
|
276
|
-
it { should eql './spec/features/logging_in.feature' }
|
288
|
+
expect(subject).to eq('./foo_spec.rb')
|
277
289
|
end
|
290
|
+
end
|
278
291
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
292
|
+
context "when id, file_path, example_group's, and top_level_group's file_path do not end in _spec.rb" do
|
293
|
+
it "returns empty string" do
|
294
|
+
allow(current_example).to receive(:id).and_return("./foo.rb")
|
295
|
+
allow(current_example).to receive(:metadata).and_return(
|
296
|
+
file_path: "./foo.rb",
|
297
|
+
example_group: {
|
298
|
+
file_path: "./foo.rb",
|
284
299
|
parent_example_group: {
|
285
|
-
file_path: "./
|
300
|
+
file_path: "./foo.rb",
|
286
301
|
}
|
287
302
|
}
|
288
|
-
|
289
|
-
|
290
|
-
before { stub_const("Turnip::VERSION", '2.0.0') }
|
303
|
+
)
|
291
304
|
|
292
|
-
|
305
|
+
expect(subject).to eq('')
|
293
306
|
end
|
294
307
|
end
|
295
308
|
end
|
@@ -298,155 +311,48 @@ describe KnapsackPro::Adapters::RSpecAdapter do
|
|
298
311
|
let(:config) { double }
|
299
312
|
|
300
313
|
describe '#bind_time_tracker' do
|
301
|
-
let(:tracker) { instance_double(KnapsackPro::Tracker) }
|
302
|
-
let(:logger) { instance_double(Logger) }
|
303
|
-
let(:global_time) { 'Global time: 01m 05s' }
|
304
|
-
let(:test_path) { 'spec/a_spec.rb' }
|
305
314
|
let(:current_example) { double(metadata: {}) }
|
306
315
|
|
307
316
|
context "when the example's metadata has :focus tag AND RSpec inclusion rule includes :focus" do
|
308
317
|
let(:current_example) { double(metadata: { focus: true }) }
|
318
|
+
let(:test_path) { 'spec/a_spec.rb' }
|
309
319
|
|
310
320
|
it do
|
311
|
-
expect(KnapsackPro::Config::Env).to receive(:rspec_split_by_test_examples?).and_return(false)
|
312
|
-
|
313
|
-
expect(config).to receive(:prepend_before).with(:context).and_yield
|
314
|
-
|
315
|
-
allow(KnapsackPro).to receive(:tracker).and_return(tracker)
|
316
|
-
expect(tracker).to receive(:start_timer).ordered
|
317
|
-
|
318
321
|
expect(config).to receive(:around).with(:each).and_yield(current_example)
|
319
322
|
expect(::RSpec).to receive(:configure).and_yield(config)
|
320
323
|
|
321
|
-
expect(
|
322
|
-
expect(tracker).to receive(:stop_timer).ordered
|
323
|
-
|
324
|
-
expect(described_class).to receive(:test_path).with(current_example).and_return(test_path)
|
325
|
-
|
326
|
-
expect(tracker).to receive(:current_test_path=).with(test_path).ordered
|
324
|
+
expect(described_class).to receive(:file_path_for).with(current_example).and_return(test_path)
|
327
325
|
|
328
326
|
expect(described_class).to receive_message_chain(:rspec_configuration, :filter, :rules, :[]).with(:focus).and_return(true)
|
329
327
|
|
330
328
|
expect {
|
331
329
|
subject.bind_time_tracker
|
332
|
-
}.to raise_error /
|
330
|
+
}.to raise_error /Knapsack Pro found an example tagged with focus in spec\/a_spec\.rb/i
|
333
331
|
end
|
334
332
|
end
|
335
333
|
|
336
|
-
context '
|
337
|
-
|
338
|
-
|
339
|
-
|
334
|
+
context 'with no focus' do
|
335
|
+
let(:logger) { instance_double(Logger) }
|
336
|
+
let(:duration) { 65 }
|
337
|
+
let(:global_time) { 'Global time execution for tests: 01m 05s' }
|
338
|
+
let(:time_tracker) { instance_double(KnapsackPro::Formatters::TimeTracker) }
|
340
339
|
|
341
340
|
it 'records time for current test path' do
|
342
|
-
expect(config).to receive(:prepend_before).with(:context).and_yield
|
343
|
-
|
344
|
-
allow(KnapsackPro).to receive(:tracker).and_return(tracker)
|
345
|
-
expect(tracker).to receive(:start_timer).ordered
|
346
|
-
|
347
341
|
expect(config).to receive(:around).with(:each).and_yield(current_example)
|
348
|
-
expect(config).to receive(:append_after).with(:context).and_yield
|
349
342
|
expect(config).to receive(:after).with(:suite).and_yield
|
350
|
-
expect(::RSpec).to receive(:configure).and_yield(config)
|
351
|
-
|
352
|
-
expect(tracker).to receive(:current_test_path).ordered.and_return(test_path)
|
353
|
-
expect(tracker).to receive(:stop_timer).ordered
|
354
|
-
|
355
|
-
expect(described_class).to receive(:test_path).with(current_example).and_return(test_path)
|
356
|
-
|
357
|
-
expect(tracker).to receive(:current_test_path=).with(test_path).ordered
|
343
|
+
expect(::RSpec).to receive(:configure).twice.and_yield(config)
|
358
344
|
|
359
345
|
expect(current_example).to receive(:run)
|
360
346
|
|
361
|
-
expect(
|
347
|
+
expect(time_tracker).to receive(:batch_duration).and_return(duration)
|
348
|
+
expect(KnapsackPro::Formatters::TimeTrackerFetcher).to receive(:call).and_return(time_tracker)
|
362
349
|
|
363
|
-
expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time)
|
364
350
|
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
365
351
|
expect(logger).to receive(:debug).with(global_time)
|
366
352
|
|
367
353
|
subject.bind_time_tracker
|
368
354
|
end
|
369
355
|
end
|
370
|
-
|
371
|
-
context 'when rspec split by test examples is enabled' do
|
372
|
-
let(:test_example_path) { 'spec/a_spec.rb[1:1]' }
|
373
|
-
|
374
|
-
before do
|
375
|
-
expect(KnapsackPro::Config::Env).to receive(:rspec_split_by_test_examples?).and_return(true)
|
376
|
-
end
|
377
|
-
|
378
|
-
context 'when current test_path is a slow test file' do
|
379
|
-
before do
|
380
|
-
expect(described_class).to receive(:slow_test_file?).with(described_class, test_path).and_return(true)
|
381
|
-
end
|
382
|
-
|
383
|
-
it 'records time for example.id' do
|
384
|
-
expect(current_example).to receive(:id).and_return(test_example_path)
|
385
|
-
|
386
|
-
expect(config).to receive(:prepend_before).with(:context).and_yield
|
387
|
-
|
388
|
-
allow(KnapsackPro).to receive(:tracker).and_return(tracker)
|
389
|
-
expect(tracker).to receive(:start_timer).ordered
|
390
|
-
|
391
|
-
expect(config).to receive(:around).with(:each).and_yield(current_example)
|
392
|
-
expect(config).to receive(:append_after).with(:context).and_yield
|
393
|
-
expect(config).to receive(:after).with(:suite).and_yield
|
394
|
-
expect(::RSpec).to receive(:configure).and_yield(config)
|
395
|
-
|
396
|
-
expect(tracker).to receive(:current_test_path).ordered.and_return(test_path)
|
397
|
-
expect(tracker).to receive(:stop_timer).ordered
|
398
|
-
|
399
|
-
expect(described_class).to receive(:test_path).with(current_example).and_return(test_path)
|
400
|
-
|
401
|
-
expect(tracker).to receive(:current_test_path=).with(test_example_path).ordered
|
402
|
-
|
403
|
-
expect(current_example).to receive(:run)
|
404
|
-
|
405
|
-
expect(tracker).to receive(:stop_timer).ordered
|
406
|
-
|
407
|
-
expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time)
|
408
|
-
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
409
|
-
expect(logger).to receive(:debug).with(global_time)
|
410
|
-
|
411
|
-
subject.bind_time_tracker
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
context 'when current test_path is not a slow test file' do
|
416
|
-
before do
|
417
|
-
expect(described_class).to receive(:slow_test_file?).with(described_class, test_path).and_return(false)
|
418
|
-
end
|
419
|
-
|
420
|
-
it 'records time for current test path' do
|
421
|
-
expect(config).to receive(:prepend_before).with(:context).and_yield
|
422
|
-
|
423
|
-
allow(KnapsackPro).to receive(:tracker).and_return(tracker)
|
424
|
-
expect(tracker).to receive(:start_timer).ordered
|
425
|
-
|
426
|
-
expect(config).to receive(:around).with(:each).and_yield(current_example)
|
427
|
-
expect(config).to receive(:append_after).with(:context).and_yield
|
428
|
-
expect(config).to receive(:after).with(:suite).and_yield
|
429
|
-
expect(::RSpec).to receive(:configure).and_yield(config)
|
430
|
-
|
431
|
-
expect(described_class).to receive(:test_path).with(current_example).and_return(test_path)
|
432
|
-
|
433
|
-
expect(tracker).to receive(:current_test_path).ordered.and_return(test_path)
|
434
|
-
expect(tracker).to receive(:stop_timer).ordered
|
435
|
-
|
436
|
-
expect(tracker).to receive(:current_test_path=).with(test_path).ordered
|
437
|
-
|
438
|
-
expect(current_example).to receive(:run)
|
439
|
-
|
440
|
-
expect(tracker).to receive(:stop_timer).ordered
|
441
|
-
|
442
|
-
expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time)
|
443
|
-
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
444
|
-
expect(logger).to receive(:debug).with(global_time)
|
445
|
-
|
446
|
-
subject.bind_time_tracker
|
447
|
-
end
|
448
|
-
end
|
449
|
-
end
|
450
356
|
end
|
451
357
|
|
452
358
|
describe '#bind_save_report' do
|
@@ -454,7 +360,11 @@ describe KnapsackPro::Adapters::RSpecAdapter do
|
|
454
360
|
expect(config).to receive(:after).with(:suite).and_yield
|
455
361
|
expect(::RSpec).to receive(:configure).and_yield(config)
|
456
362
|
|
457
|
-
|
363
|
+
time_tracker = instance_double(KnapsackPro::Formatters::TimeTracker)
|
364
|
+
times = [{ path: "foo_spec.rb", time_execution: 1.0 }]
|
365
|
+
expect(time_tracker).to receive(:batch).and_return(times)
|
366
|
+
expect(KnapsackPro::Formatters::TimeTrackerFetcher).to receive(:call).and_return(time_tracker)
|
367
|
+
expect(KnapsackPro::Report).to receive(:save).with(times)
|
458
368
|
|
459
369
|
subject.bind_save_report
|
460
370
|
end
|