knapsack_pro 7.0.0 → 7.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f27ac674f611af638b9d0ea3dd1d3441a9e680e70296738ff5b93d5d18f9741
4
- data.tar.gz: 79bdc380a1c882178b4a3cde626de7e2db1d30ae64ae1a301f023a5ff5d71623
3
+ metadata.gz: cd0d61c51dbf5b1db810f1249e058149831a3e502af11158bcb112ca02f83bf8
4
+ data.tar.gz: 8c281aa9ed386c01f857f60212f469fdb1364ff3ffc3111e60cdcb0a1557dc35
5
5
  SHA512:
6
- metadata.gz: 75bf722c575fce515b8a1a79f7e05ad5ed8ce6f69c05f4ff7cff8fdd570e5eb3e170cbf83765c66b2d1a187a5c076235637188ef9e7bd9d3d703fa37d1bf989c
7
- data.tar.gz: 1a355724b69bd0d62b23dd32b6e995dbdd882d0fcb0299d5cddb42c3b4c0635a588839c7194cfb2af83504d91ba4db192a68cc393a8380713450b44971c682bf
6
+ metadata.gz: b3f306e986304db8084259385b375681b4bf7bad16351fbe15bf3c5d624ab31648a42e2efafb8cc3bdd3eef7ce2ea49df91d9fa87b1a812830aaf6d3e489cb89
7
+ data.tar.gz: 867302738082653b366f08265224463186ea19069e147d281020ef1a76c6c480398922913fdf92d3ad1971fe792be69e204b4087e589eeac66b705fabc6a7879
data/.gitignore CHANGED
@@ -36,5 +36,5 @@ Gemfile.lock
36
36
  .rvmrc
37
37
 
38
38
  # dynamically generated specs
39
- spec/knapsack_pro/formatters/time_tracker*_spec.rb
39
+ spec/knapsack_pro/formatters/tmp_time_tracker*_spec.rb
40
40
  spec_integration/
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ### 7.0.1
4
+
5
+ * fix(RSpec): conditionally adds `--require rails_helper` to cli arguments of `KnapsackPro::Runners::Queue::RSpecRunner`. Version 7.0.0 introduced some fundamental changes, namely fetching, loading and running batches of specs **after** executing suite hooks, so that such hooks are only ran once, not before every batch. As a result, if `rails_helper` is only required in spec files, which is the RSpec default, instead of e.g. in `.rspec`, then some `before(:suite)` hooks, e.g. defined by gems, are registered after suite hooks had already been executed by the test suite. By comparison, RSpec loads all the spec files **before** executing `before(:suite)` hooks.
6
+
7
+ PR with the above changes: https://github.com/KnapsackPro/knapsack_pro-ruby/pull/243
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v7.0.0...v7.0.1
10
+
3
11
  ### 7.0.0
4
12
 
5
13
  * __(breaking change)__ RSpec in Queue Mode:
data/README.md CHANGED
@@ -74,30 +74,32 @@ Scripted tests can be found in the [Rails App With Knapsack Pro repository](http
74
74
 
75
75
  ### Publishing
76
76
 
77
- Update the version in `lib/knapsack_pro/version.rb` and `CHANGELOG.md`:
77
+ 1. Update the `CHANGELOG.md` as part of your PR.
78
+
79
+ 2. After your PR has been merged, update the gem version in `lib/knapsack_pro/version.rb` directly on the `master` branch:
78
80
 
79
81
  ```bash
80
82
  git commit -m "Bump version X.X.X"
81
83
  git push origin master
82
84
  ```
83
85
 
84
- Create a git tag for the release:
86
+ 3. Create a git tag for the release:
85
87
 
86
88
  ```bash
87
89
  git tag -a vX.X.X -m "Release vX.X.X"
88
90
  git push --tags
89
91
  ```
90
92
 
91
- Build the gem and publish it to RubyGems:
93
+ 4. Build the gem and publish it to RubyGems:
92
94
 
93
95
  ```bash
94
96
  gem build knapsack_pro.gemspec
95
97
  gem push knapsack_pro-X.X.X.gem
96
98
  ```
97
99
 
98
- Update the latest available gem version in `TestSuiteClientVersionChecker` for the Knapsack Pro API repository.
100
+ 5. Update the latest available gem version in `TestSuiteClientVersionChecker` for the Knapsack Pro API repository.
99
101
 
100
- Update the `knapsack_pro` gem version in:
102
+ 6. Update the `knapsack_pro` gem version in:
101
103
 
102
104
  - [Rails App With Knapsack Pro repository](https://github.com/KnapsackPro/rails-app-with-knapsack_pro)
103
105
  - Knapsack Pro API internal repository
@@ -52,6 +52,10 @@ module KnapsackPro
52
52
  !!parsed_options(cli_args)&.[](:formatters)
53
53
  end
54
54
 
55
+ def self.has_require_rails_helper_option?(cli_args)
56
+ (parsed_options(cli_args)&.[](:requires) || []).include?("rails_helper")
57
+ end
58
+
55
59
  def self.order_option(cli_args)
56
60
  parsed_options(cli_args)&.[](:order)
57
61
  end
@@ -76,6 +80,10 @@ module KnapsackPro
76
80
  id.match(/\A(.*?)(?:\[([\d\s:,]+)\])?\z/).captures.first
77
81
  end
78
82
 
83
+ def self.rails_helper_exists?(test_dir)
84
+ File.exist?("#{test_dir}/rails_helper.rb")
85
+ end
86
+
79
87
  # private
80
88
  def self.top_level_group(example)
81
89
  group = example.metadata[:example_group]
@@ -34,9 +34,10 @@ module KnapsackPro
34
34
  args + ['--seed', seed.value]
35
35
  end
36
36
 
37
- def prepare_cli_args(args, has_format_option, test_dir)
37
+ def prepare_cli_args(args, has_format_option, has_require_rails_helper_option, rails_helper_exists, test_dir)
38
38
  (args || '').split
39
39
  .yield_self { args_with_at_least_one_formatter(_1, has_format_option) }
40
+ .yield_self { args_with_require_rails_helper_if_needed(_1, has_require_rails_helper_option, rails_helper_exists) }
40
41
  .yield_self { args_with_default_options(_1, test_dir) }
41
42
  end
42
43
 
@@ -75,6 +76,13 @@ module KnapsackPro
75
76
  cli_args + ['--format', 'progress']
76
77
  end
77
78
 
79
+ def args_with_require_rails_helper_if_needed(cli_args, has_require_rails_helper_option, rails_helper_exists)
80
+ return cli_args if has_require_rails_helper_option
81
+ return cli_args unless rails_helper_exists
82
+
83
+ cli_args + ['--require', 'rails_helper']
84
+ end
85
+
78
86
  def args_with_default_options(cli_args, test_dir)
79
87
  new_cli_args = cli_args + [
80
88
  '--default-path', test_dir,
@@ -24,8 +24,11 @@ module KnapsackPro
24
24
  super(adapter_class)
25
25
  @adapter_class = adapter_class
26
26
  @rspec_pure = rspec_pure
27
- has_format_option = @adapter_class.has_format_option?((args || '').split)
28
- @cli_args = rspec_pure.prepare_cli_args(args, has_format_option, test_dir)
27
+ args_array = (args || '').split
28
+ has_format_option = @adapter_class.has_format_option?(args_array)
29
+ has_require_rails_helper_option = @adapter_class.has_require_rails_helper_option?(args_array)
30
+ rails_helper_exists = @adapter_class.rails_helper_exists?(test_dir)
31
+ @cli_args = rspec_pure.prepare_cli_args(args, has_format_option, has_require_rails_helper_option, rails_helper_exists, test_dir)
29
32
  @stream_error = stream_error
30
33
  @stream_out = stream_out
31
34
  @node_test_file_paths = []
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KnapsackPro
4
- VERSION = '7.0.0'
4
+ VERSION = '7.0.1'
5
5
  end
@@ -26,7 +26,7 @@ module KnapsackProExtensions
26
26
  @batch_index += 1
27
27
 
28
28
  if SHOW_DEBUG_LOG
29
- IntegrationTestLogger.log("Mocked tests from the Queue API: #{tests.inspect}")
29
+ IntegrationTestLogger.log("Stubbed tests from the Queue API: #{tests.inspect}")
30
30
  end
31
31
 
32
32
  tests
@@ -41,13 +41,13 @@ module KnapsackProExtensions
41
41
  end
42
42
 
43
43
  return unless SHOW_DEBUG_LOG
44
- IntegrationTestLogger.log("Mocked the #{__method__} method")
44
+ IntegrationTestLogger.log("Stubbed the #{__method__} method")
45
45
  end
46
46
  end
47
47
 
48
48
  module RSpecAdapter
49
49
  def test_file_cases_for(slow_test_files)
50
- IntegrationTestLogger.log("Mocked test file cases for slow test files: #{slow_test_files}")
50
+ IntegrationTestLogger.log("Stubbed test file cases for slow test files: #{slow_test_files}")
51
51
 
52
52
  test_file_paths = JSON.load(ENV.fetch('TEST__TEST_FILE_CASES_FOR_SLOW_TEST_FILES'))
53
53
  test_file_paths.map do |path|
@@ -32,13 +32,18 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
32
32
  )
33
33
  end
34
34
 
35
+ def create_rails_helper_file(rails_helper)
36
+ rails_helper_path = "#{SPEC_DIRECTORY}/rails_helper.rb"
37
+ File.open(rails_helper_path, 'w') { |file| file.write(rails_helper) }
38
+ end
39
+
35
40
  def stub_spec_batches(batched_tests)
36
41
  ENV['TEST__SPEC_BATCHES'] = batched_tests.to_json
37
42
  end
38
43
 
39
44
  # @param test_file_paths Array[String]
40
45
  # Example: ['spec_integration/a_spec.rb[1:1]']
41
- def mock_test_cases_for_slow_test_files(test_file_paths)
46
+ def stub_test_cases_for_slow_test_files(test_file_paths)
42
47
  ENV['TEST__TEST_FILE_CASES_FOR_SLOW_TEST_FILES'] = test_file_paths.to_json
43
48
  end
44
49
 
@@ -327,6 +332,174 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
327
332
  end
328
333
  end
329
334
 
335
+ context 'when rails_helper file does not exist' do
336
+ it 'does not require the rails_helper file when running RSpec' do
337
+ rspec_options = ''
338
+
339
+ spec_helper = <<~SPEC
340
+ require 'knapsack_pro'
341
+ KnapsackPro::Adapters::RSpecAdapter.bind
342
+ SPEC
343
+
344
+ spec_a = Spec.new('a_spec.rb', <<~SPEC)
345
+ describe 'A_describe' do
346
+ it 'A1 test example' do
347
+ expect(1).to eq 1
348
+ end
349
+ end
350
+ SPEC
351
+
352
+ spec_b = Spec.new('b_spec.rb', <<~SPEC)
353
+ describe 'B_describe' do
354
+ it 'B1 test example' do
355
+ expect(1).to eq 1
356
+ end
357
+ end
358
+ SPEC
359
+
360
+ spec_c = Spec.new('c_spec.rb', <<~SPEC)
361
+ describe 'C_describe' do
362
+ it 'C1 test example' do
363
+ expect(1).to eq 1
364
+ end
365
+ end
366
+ SPEC
367
+
368
+ generate_specs(spec_helper, rspec_options, [
369
+ [spec_a, spec_b],
370
+ [spec_c],
371
+ ])
372
+
373
+ actual = subject
374
+
375
+ expect(actual.stdout).to_not include('--require rails_helper')
376
+
377
+ expect(actual.exit_code).to eq 0
378
+ end
379
+ end
380
+
381
+ context 'when rails_helper file exists' do
382
+ it 'requires the rails_helper file when running RSpec and runs hooks defined within it' do
383
+ rspec_options = ''
384
+
385
+ spec_helper = <<~SPEC
386
+ require 'knapsack_pro'
387
+ KnapsackPro::Adapters::RSpecAdapter.bind
388
+ SPEC
389
+
390
+ spec_a = Spec.new('a_spec.rb', <<~SPEC)
391
+ describe 'A_describe' do
392
+ it 'A1 test example' do
393
+ expect(1).to eq 1
394
+ end
395
+ end
396
+ SPEC
397
+
398
+ spec_b = Spec.new('b_spec.rb', <<~SPEC)
399
+ describe 'B_describe' do
400
+ it 'B1 test example' do
401
+ expect(1).to eq 1
402
+ end
403
+ end
404
+ SPEC
405
+
406
+ spec_c = Spec.new('c_spec.rb', <<~SPEC)
407
+ describe 'C_describe' do
408
+ it 'C1 test example' do
409
+ expect(1).to eq 1
410
+ end
411
+ end
412
+ SPEC
413
+
414
+ generate_specs(spec_helper, rspec_options, [
415
+ [spec_a, spec_b],
416
+ [spec_c],
417
+ ])
418
+
419
+ rails_helper = <<~SPEC
420
+ RSpec.configure do |config|
421
+ config.before(:suite) do
422
+ puts 'RSpec_before_suite_hook_from_rails_helper'
423
+ end
424
+ config.after(:suite) do
425
+ puts 'RSpec_after_suite_hook_from_rails_helper'
426
+ end
427
+ end
428
+ SPEC
429
+
430
+ create_rails_helper_file(rails_helper)
431
+
432
+ actual = subject
433
+
434
+ expect(actual.stdout).to include('--require rails_helper')
435
+ expect(actual.stdout.scan(/RSpec_before_suite_hook_from_rails_helper/).size).to eq 1
436
+ expect(actual.stdout.scan(/RSpec_after_suite_hook_from_rails_helper/).size).to eq 1
437
+
438
+ expect(actual.exit_code).to eq 0
439
+ end
440
+
441
+ it 'runs suite hooks defined in rails_helper only once, even if file is required multiple times' do
442
+ rspec_options = ''
443
+
444
+ spec_helper = <<~SPEC
445
+ require 'knapsack_pro'
446
+ KnapsackPro::Adapters::RSpecAdapter.bind
447
+ SPEC
448
+
449
+ spec_a = Spec.new('a_spec.rb', <<~SPEC)
450
+ require 'rails_helper'
451
+ describe 'A_describe' do
452
+ it 'A1 test example' do
453
+ expect(1).to eq 1
454
+ end
455
+ end
456
+ SPEC
457
+
458
+ spec_b = Spec.new('b_spec.rb', <<~SPEC)
459
+ require 'rails_helper'
460
+ describe 'B_describe' do
461
+ it 'B1 test example' do
462
+ expect(1).to eq 1
463
+ end
464
+ end
465
+ SPEC
466
+
467
+ spec_c = Spec.new('c_spec.rb', <<~SPEC)
468
+ require 'rails_helper'
469
+ describe 'C_describe' do
470
+ it 'C1 test example' do
471
+ expect(1).to eq 1
472
+ end
473
+ end
474
+ SPEC
475
+
476
+ generate_specs(spec_helper, rspec_options, [
477
+ [spec_a, spec_b],
478
+ [spec_c],
479
+ ])
480
+
481
+ rails_helper = <<~SPEC
482
+ RSpec.configure do |config|
483
+ config.before(:suite) do
484
+ puts 'RSpec_before_suite_hook_from_rails_helper'
485
+ end
486
+ config.after(:suite) do
487
+ puts 'RSpec_after_suite_hook_from_rails_helper'
488
+ end
489
+ end
490
+ SPEC
491
+
492
+ create_rails_helper_file(rails_helper)
493
+
494
+ actual = subject
495
+
496
+ expect(actual.stdout.scan(/RSpec_before_suite_hook_from_rails_helper/).size).to eq 1
497
+ expect(actual.stdout.scan(/RSpec_after_suite_hook_from_rails_helper/).size).to eq 1
498
+
499
+ expect(actual.exit_code).to eq 0
500
+ end
501
+ end
502
+
330
503
  context 'when hooks are defined' do
331
504
  it 'calls RSpec before/after hooks only once for multiple batches of tests' do
332
505
  rspec_options = ''
@@ -1640,7 +1813,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
1640
1813
  before do
1641
1814
  ENV['KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES'] = 'true'
1642
1815
 
1643
- # remember to mock Queue API batches to include test examples (example: a_spec.rb[1:1])
1816
+ # remember to stub Queue API batches to include test examples (example: a_spec.rb[1:1])
1644
1817
  # for the following slow test files
1645
1818
  ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN'] = "#{SPEC_DIRECTORY}/a_spec.rb"
1646
1819
  end
@@ -1688,7 +1861,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
1688
1861
  generate_specs(spec_helper_with_knapsack, rspec_options, [
1689
1862
  [spec_a, spec_b, spec_c]
1690
1863
  ])
1691
- mock_test_cases_for_slow_test_files([
1864
+ stub_test_cases_for_slow_test_files([
1692
1865
  "#{spec_a.path}[1:1]",
1693
1866
  "#{spec_a.path}[1:2]",
1694
1867
  ])
@@ -1736,7 +1909,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
1736
1909
  before do
1737
1910
  ENV['KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES'] = 'true'
1738
1911
 
1739
- # remember to mock Queue API batches to include test examples (example: a_spec.rb[1:1])
1912
+ # remember to stub Queue API batches to include test examples (example: a_spec.rb[1:1])
1740
1913
  # for the following slow test files
1741
1914
  ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN'] = "#{SPEC_DIRECTORY}/a_spec.rb"
1742
1915
  end
@@ -1784,7 +1957,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
1784
1957
  generate_specs(spec_helper_with_knapsack, rspec_options, [
1785
1958
  [spec_a, spec_b, spec_c]
1786
1959
  ])
1787
- mock_test_cases_for_slow_test_files([
1960
+ stub_test_cases_for_slow_test_files([
1788
1961
  "#{spec_a.path}[1:1]",
1789
1962
  "#{spec_a.path}[1:2]",
1790
1963
  ])
@@ -1814,7 +1987,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
1814
1987
  before do
1815
1988
  ENV['KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES'] = 'true'
1816
1989
 
1817
- # remember to mock Queue API batches to include test examples (example: a_spec.rb[1:1])
1990
+ # remember to stub Queue API batches to include test examples (example: a_spec.rb[1:1])
1818
1991
  # for the following slow test files
1819
1992
  ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN'] = "#{SPEC_DIRECTORY}/a_spec.rb"
1820
1993
  end
@@ -1862,7 +2035,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
1862
2035
  generate_specs(spec_helper_with_knapsack, rspec_options, [
1863
2036
  [spec_a, spec_b, spec_c]
1864
2037
  ])
1865
- mock_test_cases_for_slow_test_files([
2038
+ stub_test_cases_for_slow_test_files([
1866
2039
  "#{spec_a.path}[1:1]",
1867
2040
  "#{spec_a.path}[1:2]",
1868
2041
  ])
@@ -1913,7 +2086,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
1913
2086
  before do
1914
2087
  ENV['KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES'] = 'true'
1915
2088
 
1916
- # remember to mock Queue API batches to include test examples (example: a_spec.rb[1:1])
2089
+ # remember to stub Queue API batches to include test examples (example: a_spec.rb[1:1])
1917
2090
  # for the following slow test files
1918
2091
  ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN'] = "#{SPEC_DIRECTORY}/a_spec.rb"
1919
2092
  end
@@ -1961,7 +2134,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
1961
2134
  generate_specs(spec_helper_with_knapsack, rspec_options, [
1962
2135
  [spec_a, spec_b, spec_c]
1963
2136
  ])
1964
- mock_test_cases_for_slow_test_files([
2137
+ stub_test_cases_for_slow_test_files([
1965
2138
  "#{spec_a.path}[1:1]",
1966
2139
  "#{spec_a.path}[1:2]",
1967
2140
  ])
@@ -2010,7 +2183,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
2010
2183
  before do
2011
2184
  ENV['KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES'] = 'true'
2012
2185
 
2013
- # remember to mock Queue API batches to include test examples (example: a_spec.rb[1:1])
2186
+ # remember to stub Queue API batches to include test examples (example: a_spec.rb[1:1])
2014
2187
  # for the following slow test files
2015
2188
  ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN'] = "#{SPEC_DIRECTORY}/a_spec.rb"
2016
2189
  end
@@ -2068,7 +2241,7 @@ describe "#{KnapsackPro::Runners::Queue::RSpecRunner} - Integration tests", :cle
2068
2241
  generate_specs(spec_helper, rspec_options, [
2069
2242
  [spec_a, spec_b, spec_c]
2070
2243
  ])
2071
- mock_test_cases_for_slow_test_files([
2244
+ stub_test_cases_for_slow_test_files([
2072
2245
  "#{spec_a.path}[1:1]",
2073
2246
  "#{spec_a.path}[1:2]",
2074
2247
  ])
@@ -187,6 +187,60 @@ describe KnapsackPro::Adapters::RSpecAdapter do
187
187
  end
188
188
  end
189
189
 
190
+ describe '.has_require_rails_helper_option?' do
191
+ subject { described_class.has_require_rails_helper_option?(cli_args) }
192
+
193
+ context 'when require option is provided as -r' do
194
+ let(:cli_args) { ['-r', 'rails_helper'] }
195
+
196
+ it { expect(subject).to be true }
197
+ end
198
+
199
+ context 'when require option is provided as --require' do
200
+ let(:cli_args) { ['--require', 'rails_helper'] }
201
+
202
+ it { expect(subject).to be true }
203
+ end
204
+
205
+ context 'when require option is provided without delimiter' do
206
+ let(:cli_args) { ['-rrails_helper'] }
207
+
208
+ it { expect(subject).to be true }
209
+ end
210
+
211
+ context 'when require option is not provided' do
212
+ let(:cli_args) { ['--fake', 'value'] }
213
+
214
+ it { expect(subject).to be false }
215
+ end
216
+ end
217
+
218
+ describe '.rails_helper_exists?' do
219
+ subject { described_class.rails_helper_exists?(test_dir) }
220
+
221
+ let(:test_dir) { 'spec_fake' }
222
+
223
+ context 'when rails_helper exists' do
224
+ before do
225
+ File.open("#{test_dir}/rails_helper.rb", 'w')
226
+ end
227
+
228
+ after do
229
+ FileUtils.rm("#{test_dir}/rails_helper.rb")
230
+ end
231
+
232
+ it { expect(subject).to be true }
233
+ end
234
+
235
+ context 'when rails_helper does not exist' do
236
+ before do
237
+ FileUtils.rm_f("#{test_dir}/rails_helper.rb")
238
+ end
239
+
240
+ it { expect(subject).to be false }
241
+ end
242
+ end
243
+
190
244
  describe '.order_option' do
191
245
  subject { described_class.order_option(cli_args) }
192
246
 
@@ -0,0 +1,30 @@
1
+ require(KnapsackPro.root + '/lib/knapsack_pro/formatters/time_tracker')
2
+
3
+ describe KnapsackPro::Formatters::TimeTrackerFetcher do
4
+ describe '.unexecuted_test_files' do
5
+ subject { described_class.unexecuted_test_files(scheduled_paths) }
6
+
7
+ context 'when the time tracker formatter not found' do
8
+ let(:scheduled_paths) { ['a_spec.rb'] }
9
+
10
+ it do
11
+ expect(subject).to eq []
12
+ end
13
+ end
14
+
15
+ context 'when the time tracker formatter is found' do
16
+ let(:time_tracker) { instance_double(KnapsackPro::Formatters::TimeTracker) }
17
+ let(:scheduled_paths) { ['a_spec.rb', 'b_spec.rb'] }
18
+ let(:unexecuted_test_files) { double(:unexecuted_test_files) }
19
+
20
+ before do
21
+ expect(described_class).to receive(:call).and_return(time_tracker)
22
+ expect(time_tracker).to receive(:unexecuted_test_files).with(scheduled_paths).and_return(unexecuted_test_files)
23
+ end
24
+
25
+ it do
26
+ expect(subject).to eq unexecuted_test_files
27
+ end
28
+ end
29
+ end
30
+ end
@@ -382,7 +382,7 @@ class TestTimeTracker
382
382
 
383
383
  def run_specs(specs)
384
384
  files = Array(specs).map.with_index do |spec, i|
385
- file = Tempfile.new(["time_tracker_#{i}", "_spec.rb"], "./spec/knapsack_pro/formatters/")
385
+ file = Tempfile.new(["tmp_time_tracker_#{i}", "_spec.rb"], "./spec/knapsack_pro/formatters/")
386
386
  file.write(spec)
387
387
  file.rewind
388
388
  file
@@ -117,31 +117,52 @@ describe KnapsackPro::Pure::Queue::RSpecPure do
117
117
  end
118
118
 
119
119
  describe '#prepare_cli_args' do
120
- subject { rspec_pure.prepare_cli_args(args, has_format_option, test_dir) }
120
+ subject { rspec_pure.prepare_cli_args(args, has_format_option, has_require_rails_helper_option, rails_helper_exists, test_dir) }
121
121
 
122
122
  context 'when no args' do
123
123
  let(:args) { nil }
124
124
  let(:has_format_option) { false }
125
+ let(:has_require_rails_helper_option) { false }
125
126
  let(:test_dir) { 'spec' }
126
127
 
127
- it 'adds the default progress formatter and the default path and the time tracker formatter' do
128
- expect(subject).to eq [
129
- '--format', 'progress',
130
- '--default-path', 'spec',
131
- '--format', 'KnapsackPro::Formatters::TimeTracker',
132
- ]
128
+ context 'when rails_helper does not exist' do
129
+ let(:rails_helper_exists) { false }
130
+
131
+ it 'adds the default progress formatter, the default path and the time tracker formatter, does not add require rails_helper' do
132
+ expect(subject).to eq [
133
+ '--format', 'progress',
134
+ '--default-path', 'spec',
135
+ '--format', 'KnapsackPro::Formatters::TimeTracker',
136
+ ]
137
+ end
138
+ end
139
+
140
+ context 'when rails_helper exists' do
141
+ let(:rails_helper_exists) { true }
142
+
143
+ it 'adds the default progress formatter, require rails_helper, the default path and the time tracker formatter' do
144
+ expect(subject).to eq [
145
+ '--format', 'progress',
146
+ '--require', 'rails_helper',
147
+ '--default-path', 'spec',
148
+ '--format', 'KnapsackPro::Formatters::TimeTracker',
149
+ ]
150
+ end
133
151
  end
134
152
  end
135
153
 
136
154
  context 'when args are present and a custom test directory is set' do
137
- let(:args) { '--color --profile' }
155
+ let(:args) { '--color --profile --require rails_helper' }
138
156
  let(:has_format_option) { false }
157
+ let(:has_require_rails_helper_option) { true }
158
+ let(:rails_helper_exists) { true }
139
159
  let(:test_dir) { 'custom_spec_dir' }
140
160
 
141
161
  it do
142
162
  expect(subject).to eq [
143
163
  '--color',
144
164
  '--profile',
165
+ '--require', 'rails_helper',
145
166
  '--format', 'progress',
146
167
  '--default-path', 'custom_spec_dir',
147
168
  '--format', 'KnapsackPro::Formatters::TimeTracker',
@@ -150,8 +171,10 @@ describe KnapsackPro::Pure::Queue::RSpecPure do
150
171
  end
151
172
 
152
173
  context 'when args are present and has format option' do
153
- let(:args) { '--color --profile --format d' }
174
+ let(:args) { '--color --profile --format d --require rails_helper' }
154
175
  let(:has_format_option) { true }
176
+ let(:has_require_rails_helper_option) { true }
177
+ let(:rails_helper_exists) { true }
155
178
  let(:test_dir) { 'spec' }
156
179
 
157
180
  it 'uses the format option from args instead of the default formatter' do
@@ -159,6 +182,7 @@ describe KnapsackPro::Pure::Queue::RSpecPure do
159
182
  '--color',
160
183
  '--profile',
161
184
  '--format', 'd',
185
+ '--require', 'rails_helper',
162
186
  '--default-path', 'spec',
163
187
  '--format', 'KnapsackPro::Formatters::TimeTracker',
164
188
  ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-23 00:00:00.000000000 Z
11
+ date: 2024-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -340,6 +340,7 @@ files:
340
340
  - spec/knapsack_pro/crypto/decryptor_spec.rb
341
341
  - spec/knapsack_pro/crypto/digestor_spec.rb
342
342
  - spec/knapsack_pro/crypto/encryptor_spec.rb
343
+ - spec/knapsack_pro/formatters/time_tracker_fetcher_spec.rb
343
344
  - spec/knapsack_pro/formatters/time_tracker_specs.rb
344
345
  - spec/knapsack_pro/hooks/queue_spec.rb
345
346
  - spec/knapsack_pro/logger_wrapper_spec.rb
@@ -411,7 +412,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
411
412
  - !ruby/object:Gem::Version
412
413
  version: '0'
413
414
  requirements: []
414
- rubygems_version: 3.4.19
415
+ rubygems_version: 3.5.6
415
416
  signing_key:
416
417
  specification_version: 4
417
418
  summary: Knapsack Pro splits tests across parallel CI nodes and ensures each parallel
@@ -462,6 +463,7 @@ test_files:
462
463
  - spec/knapsack_pro/crypto/decryptor_spec.rb
463
464
  - spec/knapsack_pro/crypto/digestor_spec.rb
464
465
  - spec/knapsack_pro/crypto/encryptor_spec.rb
466
+ - spec/knapsack_pro/formatters/time_tracker_fetcher_spec.rb
465
467
  - spec/knapsack_pro/formatters/time_tracker_specs.rb
466
468
  - spec/knapsack_pro/hooks/queue_spec.rb
467
469
  - spec/knapsack_pro/logger_wrapper_spec.rb