knapsack_pro 8.1.1 → 8.1.2

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: 5ad155a65c67bffcb3dad75d114396d2e53cc8896f21a84de7325a56f9a582ba
4
- data.tar.gz: 6a6e0958d5596b150cdc6ee46453d5ff9991255e98113990015e34a8fef8aa1d
3
+ metadata.gz: 0cb3592a7a5f0e3f69138e53d5659954e0e84190ad84380d823e776268d4e900
4
+ data.tar.gz: b40c96cebfb9c4446998291b01c435f6e29cd937a51848593510ed633e56b14b
5
5
  SHA512:
6
- metadata.gz: ee9feec10df81e17331b3664af0a30f8d75c4d436bb9c897829588518bb3468e5c00a3729d0e5c9f731ce535ab2b02dc5747a52a743e400bd49ffd046bb7ef51
7
- data.tar.gz: d982189a7880df48104810628f1ff6e416c420325ace9fc2827c988c0289bfe27d2e78ff4bdffd94fe20891e37333805f2d530ab40aa822632847daed5b9596d
6
+ metadata.gz: 8308e34071c72b055335ded1422bb49762c600fffbc86f83a54911dde1cc23db59e472233bd53c1ec558fbf612c11b537587e241774dd8824d14e6665fd914e8
7
+ data.tar.gz: 35829c1ba92de81be2d7b3f5bd428b9fb2a66a8ad3da940f21e196b02b7962ce13f0c453f27c85c3acfce681223b3a83145baf2b26ef12b10a66dcf67f0d9fa3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ### 8.1.2
4
+
5
+ * Allow running RSpec with `--force-color` (and the default Split by Test Examples)
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/298
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v8.1.1...v8.1.2
10
+
3
11
  ### 8.1.1
4
12
 
5
13
  * Do not load Rake tasks on behalf of the user for RSpec and Minitest in Queue Mode
@@ -33,32 +33,22 @@ module KnapsackPro
33
33
  # Apply a --format option which overrides formatters from the RSpec custom option files like `.rspec`.
34
34
  cli_args = cli_args_without_formatters + cli_format + [
35
35
  '--dry-run',
36
- '--no-color',
37
36
  '--out', report_path,
38
- '--default-path', test_dir,
37
+ '--default-path', test_dir
39
38
  ] + KnapsackPro::TestFilePresenter.paths(test_file_entities)
40
- options = ::RSpec::Core::ConfigurationOptions.new(cli_args)
41
- exit_code = ::RSpec::Core::Runner.new(options).run($stderr, $stdout)
42
- if exit_code != 0
43
- debug_cmd = ([
44
- 'bundle exec rspec',
45
- ] + cli_args).join(' ')
46
-
47
- KnapsackPro.logger.error('-'*10 + ' START of actionable error message ' + '-'*50)
48
- KnapsackPro.logger.error('RSpec (with a dry-run option) had a problem generating the report with test examples for the slow test files. Here is what you can do:')
49
-
50
- KnapsackPro.logger.error("a) Please look for an error message from RSpec in the output above or below. If you don't see anything, that is fine. Sometimes RSpec does not produce any errors in the output.")
51
-
52
- KnapsackPro.logger.error("b) Check if RSpec generated the report file #{report_path}. If the report exists, it may contain an error message. Here is a preview of the report file:")
53
- KnapsackPro.logger.error(report_content || 'N/A')
54
-
55
- KnapsackPro.logger.error('c) To reproduce the error manually, please run the following RSpec command. This way, you can find out what is causing the error. Please ensure you run the command in the same environment where the error occurred. For instance, if the error happens on the CI server, you should run the command in the CI environment:')
56
- KnapsackPro.logger.error(debug_cmd)
39
+ exit_code = begin
40
+ options = ::RSpec::Core::ConfigurationOptions.new(cli_args)
41
+ ::RSpec::Core::Runner.new(options).run($stderr, $stdout)
42
+ rescue SystemExit => e
43
+ e.status
44
+ end
57
45
 
58
- KnapsackPro.logger.error('-'*10 + ' END of actionable error message ' + '-'*50)
46
+ return if exit_code.zero?
59
47
 
60
- raise 'There was a problem while generating test examples for the slow test files. Please read the actionable error message above.'
61
- end
48
+ report.fetch('messages', []).each { |message| puts message }
49
+ command = (['bundle exec rspec'] + cli_args).join(' ')
50
+ KnapsackPro.logger.error("Failed to generate the slow test files report: #{command}")
51
+ exit exit_code
62
52
  end
63
53
 
64
54
  def test_file_example_paths
@@ -92,8 +82,9 @@ module KnapsackPro
92
82
  "#{report_dir}/rspec_dry_run_json_report_node_#{KnapsackPro::Config::Env.ci_node_index}.json"
93
83
  end
94
84
 
95
- def report_content
96
- File.read(report_path) if File.exist?(report_path)
85
+ def report
86
+ return {} unless File.exist?(report_path)
87
+ JSON.parse(File.read(report_path))
97
88
  end
98
89
 
99
90
  def adapter_class
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KnapsackPro
4
- VERSION = '8.1.1'
4
+ VERSION = '8.1.2'
5
5
  end
@@ -48,7 +48,6 @@ describe KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector do
48
48
  expect(RSpec::Core::ConfigurationOptions).to receive(:new).with(expected_args + [
49
49
  '--format', expected_format,
50
50
  '--dry-run',
51
- '--no-color',
52
51
  '--out', report_path,
53
52
  '--default-path', test_dir,
54
53
  'spec/a_spec.rb', 'spec/b_spec.rb',
@@ -78,7 +77,7 @@ describe KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector do
78
77
  end
79
78
 
80
79
  it do
81
- expect { subject }.to raise_error(RuntimeError, 'There was a problem while generating test examples for the slow test files. Please read the actionable error message above.')
80
+ expect { subject }.to raise_error(SystemExit) { |error| expect(error.status).to eq exit_code }
82
81
  end
83
82
  end
84
83
  end
@@ -123,6 +122,36 @@ describe KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector do
123
122
  expect { subject }.to raise_error("The internal KNAPSACK_PRO_RSPEC_OPTIONS environment variable is unset. Ensure it is not overridden accidentally. Otherwise, please report this as a bug: https://knapsackpro.com/perma/ruby/support")
124
123
  end
125
124
  end
125
+
126
+ context 'with --force-color' do
127
+ let(:rspec_args) { '--force-color' }
128
+ let(:expected_args) { ['--force-color'] }
129
+ let(:expected_format) { 'json' }
130
+
131
+ it_behaves_like 'generate_json_report runs RSpec::Core::Runner'
132
+ end
133
+
134
+ context 'with --no-color and --force-color' do
135
+ let(:rspec_args) { '--no-color --force-color' }
136
+
137
+ after { KnapsackPro.reset_logger! }
138
+
139
+ it do
140
+ subject_class = Class.new(KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector) do
141
+ define_method(:slow_test_files) do
142
+ [{ 'path' => 'spec/a_spec.rb' }]
143
+ end
144
+ end
145
+
146
+ expect do
147
+ KnapsackPro.logger = ::Logger.new($stdout)
148
+ subject_class.new.generate_json_report(rspec_args)
149
+ end
150
+ .to output(/Please only use one of `--force-color` and `--no-color`/).to_stderr
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
+ .and raise_error(SystemExit) { |error| expect(error.status).to eq 1 }
153
+ end
154
+ end
126
155
  end
127
156
 
128
157
  describe '#test_file_example_paths' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.1
4
+ version: 8.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-10 00:00:00.000000000 Z
10
+ date: 2025-04-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake