Skip to content

Commit

Permalink
fix(Queue Mode): ensure exit code is 1 when RSpec raised an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturT committed Aug 1, 2023
1 parent 44ac573 commit 2dea588
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/knapsack_pro/runners/queue/rspec_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ def self.run_tests(accumulator)
exit_code = rspec_runner.run($stderr, $stdout)
exitstatus = exit_code if exit_code != 0
rescue Exception => exception
KnapsackPro.logger.debug("Having exception when running rspec: #{exception}")
KnapsackPro.logger.error("Having exception when running RSpec: #{exception.inspect}")
KnapsackPro::Formatters::RSpecQueueSummaryFormatter.print_exit_summary
KnapsackPro::Hooks::Queue.call_after_subset_queue
KnapsackPro::Hooks::Queue.call_after_queue
Kernel.exit(1)
raise
else
if rspec_runner.world.wants_to_quit
Expand Down
7 changes: 4 additions & 3 deletions spec/knapsack_pro/runners/queue/rspec_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
double(world: double(wants_to_quit: rspec_wants_to_quit, rspec_is_quitting: rspec_is_quitting))
end

context 'having no exception when running rspec' do
context 'having no exception when running RSpec' do
before do
subset_queue_id = 'fake-subset-queue-id'
expect(KnapsackPro::Config::EnvGenerator).to receive(:set_subset_queue_id).and_return(subset_queue_id)
Expand Down Expand Up @@ -337,7 +337,7 @@
end
end

context 'having exception when running rspec' do
context 'having exception when running RSpec' do
before do
subset_queue_id = 'fake-subset-queue-id'
expect(KnapsackPro::Config::EnvGenerator).to receive(:set_subset_queue_id).and_return(subset_queue_id)
Expand Down Expand Up @@ -365,6 +365,7 @@
allow(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
allow(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
allow(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_exit_summary)
expect(Kernel).to receive(:exit).with(1)
end

it 'does not call #save_subset_queue_to_file or #rspec_clear_examples' do
Expand All @@ -375,7 +376,7 @@

it 'logs the exception' do
expect(KnapsackPro).to receive(:logger).once.and_return(logger)
expect(logger).to receive(:debug).with("Having exception when running rspec: SystemExit")
expect(logger).to receive(:error).with("Having exception when running RSpec: #<SystemExit: SystemExit>")
expect { subject }.to raise_error SystemExit
end

Expand Down

0 comments on commit 2dea588

Please sign in to comment.