From d248c437b98571fe835790256d6ff7bfbcc1b346 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 20 Mar 2024 12:57:43 +0000 Subject: [PATCH] Fix rspec is quitting signal --- Changelog.md | 6 ++ Gemfile.lock | 2 +- lib/mutant/integration/rspec.rb | 10 ++- lib/mutant/version.rb | 2 +- spec/unit/mutant/integration/rspec_spec.rb | 79 +++++++++++++++++++++- test_app/Gemfile.rspec3.10.lock | 6 +- test_app/Gemfile.rspec3.11.lock | 6 +- test_app/Gemfile.rspec3.12.lock | 6 +- test_app/Gemfile.rspec3.13.lock | 6 +- test_app/Gemfile.rspec3.8.lock | 6 +- test_app/Gemfile.rspec3.9.lock | 6 +- 11 files changed, 111 insertions(+), 24 deletions(-) diff --git a/Changelog.md b/Changelog.md index 74cb5af85..0effe7706 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +# v0.11.32 2024-03-20 + +* [#1430](https://github.com/mbj/mutant/pull/1430) + + Also factor in Rspec 3.9+ signal `rspec_is_quitting` to detect rspec not being able to load examples. + # v0.11.31 2024-03-14 * [#1428](https://github.com/mbj/mutant/pull/1428) diff --git a/Gemfile.lock b/Gemfile.lock index bfa6fdc75..d85cc4b70 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - mutant (0.11.31) + mutant (0.11.32) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) diff --git a/lib/mutant/integration/rspec.rb b/lib/mutant/integration/rspec.rb index 662bf2b3b..71d5fbc32 100644 --- a/lib/mutant/integration/rspec.rb +++ b/lib/mutant/integration/rspec.rb @@ -50,7 +50,7 @@ def initialize(*) def setup @setup_elapsed = timer.elapsed do @runner.setup(world.stderr, world.stdout) - fail 'Rspec setup failure' if @rspec_world.wants_to_quit + fail 'RSpec setup failure' if rspec_setup_failure? example_group_map end @runner.configuration.force(color_mode: :on) @@ -102,6 +102,14 @@ def available_tests private + def rspec_setup_failure? + @rspec_world.wants_to_quit || rspec_is_quitting? + end + + def rspec_is_quitting? + @rspec_world.respond_to?(:rspec_is_quitting) && @rspec_world.rspec_is_quitting + end + def effective_arguments arguments.empty? ? DEFAULT_CLI_OPTIONS : arguments end diff --git a/lib/mutant/version.rb b/lib/mutant/version.rb index ad983651e..3b39755e4 100644 --- a/lib/mutant/version.rb +++ b/lib/mutant/version.rb @@ -2,5 +2,5 @@ module Mutant # Current mutant version - VERSION = '0.11.31' + VERSION = '0.11.32' end # Mutant diff --git a/spec/unit/mutant/integration/rspec_spec.rb b/spec/unit/mutant/integration/rspec_spec.rb index 77d1d58e4..3101e747e 100644 --- a/spec/unit/mutant/integration/rspec_spec.rb +++ b/spec/unit/mutant/integration/rspec_spec.rb @@ -17,6 +17,7 @@ let(:rspec_options) { instance_double(RSpec::Core::ConfigurationOptions) } let(:rspec_runner) { instance_double(RSpec::Core::Runner) } let(:world) { fake_world } + let(:is_quitting) { false } let(:wants_to_quit) { false } let(:example_a) do @@ -206,10 +207,82 @@ end end - it { should be(object) } + shared_examples 'success' do + it { should be(object) } - it 'freezes object' do - expect { subject }.to change { object.frozen? }.from(false).to(true) + it 'freezes object' do + expect { subject }.to change { object.frozen? }.from(false).to(true) + end + end + + context 'on success' do + include_examples 'success' + end + + shared_examples 'setup failure' do + def apply + object.setup + end + + it 'raises expeced error' do + expect { apply }.to raise_error('RSpec setup failure') + end + end + + context 'on rspec setup failure' do + context 'when rspec wants to quit' do + let(:wants_to_quit) { true } + + include_examples 'setup failure' + end + + context 'when rspec does not want to quit' do + before do + allow(rspec_world).to receive_messages(respond_to?: supports_is_quitting) + end + + shared_examples 'support query' do + it 'queries support' do + begin + subject + # rubocop:disable + rescue + # rubocop:enable + end + + expect(rspec_world).to have_received(:respond_to?).with(:rspec_is_quitting) + end + end + + context 'and rspec supports is currently quitting' do + let(:supports_is_quitting) { true } + + before do + allow(rspec_world).to receive_messages(rspec_is_quitting: rspec_is_quitting) + end + + context 'and its currently quitting' do + let(:rspec_is_quitting) { true } + + include_examples 'setup failure' + include_examples 'support query' + end + + context 'and its not currently quitting' do + let(:rspec_is_quitting) { false } + + include_examples 'success' + include_examples 'support query' + end + end + + context 'and rspec does not support is currently quitting' do + let(:supports_is_quitting) { false } + + include_examples 'success' + include_examples 'support query' + end + end end end diff --git a/test_app/Gemfile.rspec3.10.lock b/test_app/Gemfile.rspec3.10.lock index 4a22e0313..e9acb07c3 100644 --- a/test_app/Gemfile.rspec3.10.lock +++ b/test_app/Gemfile.rspec3.10.lock @@ -1,14 +1,14 @@ PATH remote: .. specs: - mutant (0.11.31) + mutant (0.11.32) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) unparser (~> 0.6.9) - mutant-rspec (0.11.31) - mutant (= 0.11.31) + mutant-rspec (0.11.32) + mutant (= 0.11.32) rspec-core (>= 3.8.0, < 4.0.0) GEM diff --git a/test_app/Gemfile.rspec3.11.lock b/test_app/Gemfile.rspec3.11.lock index 0dd1d5e77..4a052a644 100644 --- a/test_app/Gemfile.rspec3.11.lock +++ b/test_app/Gemfile.rspec3.11.lock @@ -1,14 +1,14 @@ PATH remote: .. specs: - mutant (0.11.31) + mutant (0.11.32) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) unparser (~> 0.6.9) - mutant-rspec (0.11.31) - mutant (= 0.11.31) + mutant-rspec (0.11.32) + mutant (= 0.11.32) rspec-core (>= 3.8.0, < 4.0.0) GEM diff --git a/test_app/Gemfile.rspec3.12.lock b/test_app/Gemfile.rspec3.12.lock index d470ab11d..0f1d0b9f7 100644 --- a/test_app/Gemfile.rspec3.12.lock +++ b/test_app/Gemfile.rspec3.12.lock @@ -1,14 +1,14 @@ PATH remote: .. specs: - mutant (0.11.31) + mutant (0.11.32) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) unparser (~> 0.6.9) - mutant-rspec (0.11.31) - mutant (= 0.11.31) + mutant-rspec (0.11.32) + mutant (= 0.11.32) rspec-core (>= 3.8.0, < 4.0.0) GEM diff --git a/test_app/Gemfile.rspec3.13.lock b/test_app/Gemfile.rspec3.13.lock index e10ac80e5..523cc01ad 100644 --- a/test_app/Gemfile.rspec3.13.lock +++ b/test_app/Gemfile.rspec3.13.lock @@ -1,14 +1,14 @@ PATH remote: .. specs: - mutant (0.11.31) + mutant (0.11.32) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) unparser (~> 0.6.9) - mutant-rspec (0.11.31) - mutant (= 0.11.31) + mutant-rspec (0.11.32) + mutant (= 0.11.32) rspec-core (>= 3.8.0, < 4.0.0) GEM diff --git a/test_app/Gemfile.rspec3.8.lock b/test_app/Gemfile.rspec3.8.lock index 0225585b3..a3becd37e 100644 --- a/test_app/Gemfile.rspec3.8.lock +++ b/test_app/Gemfile.rspec3.8.lock @@ -1,14 +1,14 @@ PATH remote: .. specs: - mutant (0.11.31) + mutant (0.11.32) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) unparser (~> 0.6.9) - mutant-rspec (0.11.31) - mutant (= 0.11.31) + mutant-rspec (0.11.32) + mutant (= 0.11.32) rspec-core (>= 3.8.0, < 4.0.0) GEM diff --git a/test_app/Gemfile.rspec3.9.lock b/test_app/Gemfile.rspec3.9.lock index d470ab11d..0f1d0b9f7 100644 --- a/test_app/Gemfile.rspec3.9.lock +++ b/test_app/Gemfile.rspec3.9.lock @@ -1,14 +1,14 @@ PATH remote: .. specs: - mutant (0.11.31) + mutant (0.11.32) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) unparser (~> 0.6.9) - mutant-rspec (0.11.31) - mutant (= 0.11.31) + mutant-rspec (0.11.32) + mutant (= 0.11.32) rspec-core (>= 3.8.0, < 4.0.0) GEM