knapsack_pro 3.4.0 → 3.4.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: 23f9763190e37db931c1457e71dccca8ef1f9d6fcd99fe50b28b1571366833cc
4
- data.tar.gz: d93d4734cf560ecc77ae06959562c1fcf1ac61489671f374c3fc8a3e2f2e040a
3
+ metadata.gz: 2b7ff9f0b6a3c331eb6c09ea0e04678152db2bae4248e47181bcffe6c88ee194
4
+ data.tar.gz: 4ae766dc15f410d4c82baf223c5ca9abfce4a84c031a37693649e1b58e98b13a
5
5
  SHA512:
6
- metadata.gz: 254b42538b48ef6483e2479e4db2f5619389df83496443b6924a6953b2d49485563615888864cb0ec3696cb36e2f0338873294ffa559461076ba4033929134bc
7
- data.tar.gz: 310f6d28741d8631bba32b205e0f4a86a47b775f0c8f732a272ecf1151c88b2ca46e1975657f5fa5dcaaefefbaa2b2668b9e65e876addf838aa4013e83770723
6
+ metadata.gz: 63ee85c13851d6d87b8d73c189eae9b477ccfb231b9119e1efbc1921142a31b7c82b85a425223cf8f60927b2de8a0b58e72ae77395844f78b6bc2711b0cfe13d
7
+ data.tar.gz: 1b782f2383e2b583cb718e67b2a65feb0ee568378d09411aae80ac55a51e3fe243017ce179c6f3c6199e9fe7bf683dec0dd72465fa41a1f1b250bf50d231371d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ### 3.4.2
4
+
5
+ * Fix: Load `rspec/core` in Regular Mode when using RSpec split by test examples feature
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/181
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.4.1...v3.4.2
10
+
11
+ ### 3.4.1
12
+
13
+ * Improve the RSpec Queue Mode runner log output (add seed)
14
+
15
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/178
16
+
17
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.4.0...v3.4.1
18
+
3
19
  ### 3.4.0
4
20
 
5
21
  * Update documentation and code because the encryption feature does not work with the RSpec split by examples feature
@@ -12,16 +12,15 @@ module KnapsackPro
12
12
  end
13
13
 
14
14
  def self.has_tag_option?(cli_args)
15
- # use start_with? because user can define tag option in a few ways:
16
- # -t mytag
17
- # -tmytag
18
- # --tag mytag
19
- # --tag=mytag
20
- cli_args.any? { |arg| arg.start_with?('-t') || arg.start_with?('--tag') }
15
+ !!parsed_options(cli_args)&.[](:inclusion_filter)
21
16
  end
22
17
 
23
18
  def self.has_format_option?(cli_args)
24
- cli_args.any? { |arg| arg.start_with?('-f') || arg.start_with?('--format') }
19
+ !!parsed_options(cli_args)&.[](:formatters)
20
+ end
21
+
22
+ def self.order_option(cli_args)
23
+ parsed_options(cli_args)&.[](:order)
25
24
  end
26
25
 
27
26
  def self.test_path(example)
@@ -107,6 +106,12 @@ module KnapsackPro
107
106
  def self.rspec_configuration
108
107
  ::RSpec.configuration
109
108
  end
109
+
110
+ def self.parsed_options(cli_args)
111
+ ::RSpec::Core::Parser.parse(cli_args)
112
+ rescue SystemExit
113
+ nil
114
+ end
110
115
  end
111
116
 
112
117
  # This is added to provide backwards compatibility
@@ -2,6 +2,8 @@ module KnapsackPro
2
2
  module Runners
3
3
  module Queue
4
4
  class RSpecRunner < BaseRunner
5
+ @@used_seed = nil
6
+
5
7
  def self.run(args)
6
8
  require 'rspec/core'
7
9
  require_relative '../../formatters/rspec_queue_summary_formatter'
@@ -11,7 +13,6 @@ module KnapsackPro
11
13
  ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED'] = 'true'
12
14
  ENV['KNAPSACK_PRO_QUEUE_ID'] = KnapsackPro::Config::EnvGenerator.set_queue_id
13
15
 
14
- adapter_class = KnapsackPro::Adapters::RSpecAdapter
15
16
  KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
16
17
  runner = new(adapter_class)
17
18
 
@@ -61,6 +62,8 @@ module KnapsackPro
61
62
  KnapsackPro::Formatters::RSpecQueueSummaryFormatter.print_summary
62
63
  KnapsackPro::Formatters::RSpecQueueProfileFormatterExtension.print_summary
63
64
 
65
+ args += ['--seed', @@used_seed] if @@used_seed
66
+
64
67
  log_rspec_command(args, all_test_file_paths, :end_of_queue)
65
68
  end
66
69
 
@@ -82,12 +85,15 @@ module KnapsackPro
82
85
  all_test_file_paths += test_file_paths
83
86
  cli_args = args + test_file_paths
84
87
 
85
- log_rspec_command(args, test_file_paths, :subset_queue)
86
-
87
88
  options = ::RSpec::Core::ConfigurationOptions.new(cli_args)
88
- exit_code = ::RSpec::Core::Runner.new(options).run($stderr, $stdout)
89
+ rspec_runner = ::RSpec::Core::Runner.new(options)
90
+
91
+ exit_code = rspec_runner.run($stderr, $stdout)
89
92
  exitstatus = exit_code if exit_code != 0
90
93
 
94
+ printable_args = args_with_seed_option_added_when_viable(args, rspec_runner)
95
+ log_rspec_command(printable_args, test_file_paths, :subset_queue)
96
+
91
97
  rspec_clear_examples
92
98
 
93
99
  KnapsackPro::Hooks::Queue.call_after_subset_queue
@@ -107,19 +113,22 @@ module KnapsackPro
107
113
 
108
114
  private
109
115
 
116
+ def self.adapter_class
117
+ KnapsackPro::Adapters::RSpecAdapter
118
+ end
119
+
110
120
  def self.log_rspec_command(cli_args, test_file_paths, type)
111
121
  case type
112
122
  when :subset_queue
113
- KnapsackPro.logger.info("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine. (If you use the `-- order random` option, remember to add correct `--seed 123` that you can find at the end of the RSpec output.)")
123
+ KnapsackPro.logger.info("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine:")
114
124
  when :end_of_queue
115
125
  KnapsackPro.logger.info("To retry all the tests assigned to this CI node, please run the following command on your machine:")
116
126
  end
117
127
 
118
- stringify_cli_args = cli_args.join(' ')
119
- stringify_cli_args.slice!("--format #{KnapsackPro::Formatters::RSpecQueueSummaryFormatter}")
128
+ stringified_cli_args = cli_args.join(' ').sub(" --format #{KnapsackPro::Formatters::RSpecQueueSummaryFormatter}", '')
120
129
 
121
130
  KnapsackPro.logger.info(
122
- "bundle exec rspec #{stringify_cli_args} " +
131
+ "bundle exec rspec #{stringified_cli_args} " +
123
132
  KnapsackPro::TestFilePresenter.stringify_paths(test_file_paths)
124
133
  )
125
134
  end
@@ -151,6 +160,24 @@ module KnapsackPro
151
160
  ::RSpec.configuration.reset_filters
152
161
  end
153
162
  end
163
+
164
+ def self.args_with_seed_option_added_when_viable(args, rspec_runner)
165
+ order_option = adapter_class.order_option(args)
166
+
167
+ if order_option
168
+ # Don't add the seed option for order other than random, e.g. `defined`
169
+ return args unless order_option.include?('rand')
170
+ # Don't add the seed option if the seed is already set in args, e.g. `rand:12345`
171
+ return args if order_option.to_s.split(':')[1]
172
+ end
173
+
174
+ # Don't add the seed option if the seed was not used (i.e. a different order is being used, e.g. `defined`)
175
+ return args unless rspec_runner.configuration.seed_used?
176
+
177
+ @@used_seed = rspec_runner.configuration.seed.to_s
178
+
179
+ args + ['--seed', @@used_seed]
180
+ end
154
181
  end
155
182
  end
156
183
  end
@@ -2,6 +2,8 @@ module KnapsackPro
2
2
  module Runners
3
3
  class RSpecRunner < BaseRunner
4
4
  def self.run(args)
5
+ require 'rspec/core'
6
+
5
7
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN'] = KnapsackPro::Config::Env.test_suite_token_rspec
6
8
  ENV['KNAPSACK_PRO_RECORDING_ENABLED'] = 'true'
7
9
 
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '3.4.0'
2
+ VERSION = '3.4.2'
3
3
  end
@@ -110,6 +110,58 @@ describe KnapsackPro::Adapters::RSpecAdapter do
110
110
  end
111
111
  end
112
112
 
113
+ describe '.order_option' do
114
+ subject { described_class.order_option(cli_args) }
115
+
116
+ context "when order is 'defined'" do
117
+ let(:cli_args) { ['--order', 'defined'] }
118
+
119
+ it { expect(subject).to eq 'defined' }
120
+ end
121
+
122
+ context "when order is 'recently-modified'" do
123
+ let(:cli_args) { ['--order', 'recently-modified'] }
124
+
125
+ it { expect(subject).to eq 'recently-modified' }
126
+ end
127
+
128
+ context "when order is 'rand'" do
129
+ let(:cli_args) { ['--order', 'rand'] }
130
+
131
+ it { expect(subject).to eq 'rand' }
132
+
133
+ context 'with the seed' do
134
+ let(:cli_args) { ['--order', 'rand:123456'] }
135
+
136
+ it { expect(subject).to eq 'rand:123456' }
137
+ end
138
+ end
139
+
140
+ context "when order is 'random'" do
141
+ let(:cli_args) { ['--order', 'random'] }
142
+
143
+ it { expect(subject).to eq 'random' }
144
+
145
+ context 'with the seed' do
146
+ let(:cli_args) { ['--order', 'random:123456'] }
147
+
148
+ it { expect(subject).to eq 'random:123456' }
149
+ end
150
+ end
151
+
152
+ context 'when some custom order is specified' do
153
+ let(:cli_args) { ['--order', 'some-custom-order'] }
154
+
155
+ it { expect(subject).to eq 'some-custom-order' }
156
+ end
157
+
158
+ context "when the seed is given with the --seed command" do
159
+ let(:cli_args) { ['--seed', '123456'] }
160
+
161
+ it { expect(subject).to eq 'rand:123456' }
162
+ end
163
+ end
164
+
113
165
  describe '.test_path' do
114
166
  let(:example_group) do
115
167
  {
@@ -177,7 +177,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
177
177
  describe '.run_tests' do
178
178
  let(:runner) { instance_double(described_class) }
179
179
  let(:can_initialize_queue) { double(:can_initialize_queue) }
180
- let(:args) { ['--example-arg', 'example-value', '--default-path', 'fake-test-dir'] }
180
+ let(:args) { ['--no-color', '--default-path', 'fake-test-dir'] }
181
181
  let(:exitstatus) { double }
182
182
  let(:all_test_file_paths) { [] }
183
183
  let(:accumulator) do
@@ -198,6 +198,8 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
198
198
 
199
199
  context 'when test files exist' do
200
200
  let(:test_file_paths) { ['a_spec.rb', 'b_spec.rb'] }
201
+ let(:logger) { double }
202
+ let(:rspec_seed) { 7771 }
201
203
 
202
204
  before do
203
205
  subset_queue_id = 'fake-subset-queue-id'
@@ -212,7 +214,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
212
214
 
213
215
  options = double
214
216
  expect(RSpec::Core::ConfigurationOptions).to receive(:new).with([
215
- '--example-arg', 'example-value',
217
+ '--no-color',
216
218
  '--default-path', 'fake-test-dir',
217
219
  'a_spec.rb', 'b_spec.rb',
218
220
  ]).and_return(options)
@@ -226,6 +228,16 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
226
228
  expect(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
227
229
 
228
230
  expect(KnapsackPro::Report).to receive(:save_subset_queue_to_file)
231
+
232
+ configuration = double
233
+ expect(rspec_core_runner).to receive(:configuration).twice.and_return(configuration)
234
+ expect(configuration).to receive(:seed_used?).and_return(true)
235
+ expect(configuration).to receive(:seed).and_return(rspec_seed)
236
+
237
+ expect(KnapsackPro).to receive(:logger).twice.and_return(logger)
238
+ expect(logger).to receive(:info)
239
+ .with("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine:")
240
+ expect(logger).to receive(:info).with(/#{args.join(' ')} --seed #{rspec_seed}/)
229
241
  end
230
242
 
231
243
  context 'when exit code is zero' do
@@ -264,8 +276,13 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
264
276
 
265
277
  context 'when all_test_file_paths exist' do
266
278
  let(:all_test_file_paths) { ['a_spec.rb'] }
279
+ let(:logger) { double }
280
+
281
+ before do
282
+ described_class.class_variable_set(:@@used_seed, used_seed)
283
+
284
+ expect(KnapsackPro).to receive(:logger).twice.and_return(logger)
267
285
 
268
- it do
269
286
  expect(KnapsackPro::Adapters::RSpecAdapter).to receive(:verify_bind_method_called)
270
287
 
271
288
  expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_summary)
@@ -274,10 +291,33 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
274
291
  expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
275
292
  expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
276
293
 
277
- expect(subject).to eq({
278
- status: :completed,
279
- exitstatus: exitstatus,
280
- })
294
+ expect(logger).to receive(:info)
295
+ .with('To retry all the tests assigned to this CI node, please run the following command on your machine:')
296
+ expect(logger).to receive(:info).with(logged_rspec_command_matcher)
297
+ end
298
+
299
+ context 'when @@used_seed has been set' do
300
+ let(:used_seed) { '8333' }
301
+ let(:logged_rspec_command_matcher) { /#{args.join(' ')} --seed #{used_seed} \"a_spec.rb"/ }
302
+
303
+ it do
304
+ expect(subject).to eq({
305
+ status: :completed,
306
+ exitstatus: exitstatus,
307
+ })
308
+ end
309
+ end
310
+
311
+ context 'when @@used_seed has not been set' do
312
+ let(:used_seed) { nil }
313
+ let(:logged_rspec_command_matcher) { /#{args.join(' ')} \"a_spec.rb"/ }
314
+
315
+ it do
316
+ expect(subject).to eq({
317
+ status: :completed,
318
+ exitstatus: exitstatus,
319
+ })
320
+ end
281
321
  end
282
322
  end
283
323
 
@@ -287,6 +327,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
287
327
  it do
288
328
  expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
289
329
  expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
330
+ expect(KnapsackPro).to_not receive(:logger)
290
331
 
291
332
  expect(subject).to eq({
292
333
  status: :completed,
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: 3.4.0
4
+ version: 3.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-21 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake