Skip to content

Commit

Permalink
Fix rspec is quitting signal
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Mar 20, 2024
1 parent df15696 commit ecbc6d2
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 24 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.11.32 2024-03-20

* [#1429](https://github.com/mbj/mutant/pull/1429)

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)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 9 additions & 1 deletion lib/mutant/integration/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module Mutant
# Current mutant version
VERSION = '0.11.31'
VERSION = '0.11.32'
end # Mutant
79 changes: 76 additions & 3 deletions spec/unit/mutant/integration/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test_app/Gemfile.rspec3.10.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test_app/Gemfile.rspec3.11.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test_app/Gemfile.rspec3.12.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test_app/Gemfile.rspec3.13.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test_app/Gemfile.rspec3.8.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test_app/Gemfile.rspec3.9.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ecbc6d2

Please sign in to comment.