diff --git a/spec/rspec/mocks/mutate_const_spec.rb b/spec/rspec/mocks/mutate_const_spec.rb index f4fcfcc5d..ff545c4d8 100644 --- a/spec/rspec/mocks/mutate_const_spec.rb +++ b/spec/rspec/mocks/mutate_const_spec.rb @@ -149,10 +149,7 @@ def change_const_value_to(value) if RUBY_VERSION >= '3.1' describe 'with global exclude_stubbed_classes_from_subclasses option set' do include_context "with isolated configuration" - - before do - RSpec::Mocks.configuration.exclude_stubbed_classes_from_subclasses = true - end + include_context "with stubbed classes excluded from subclasses" it 'gives the same subclasses after rspec clears its mocks' do original_subclasses = TestClass.subclasses @@ -372,10 +369,7 @@ def change_const_value_to(value) if RUBY_VERSION >= '3.1' describe 'with global exclude_stubbed_classes_from_subclasses option set' do include_context "with isolated configuration" - - before do - RSpec::Mocks.configuration.exclude_stubbed_classes_from_subclasses = true - end + include_context "with stubbed classes excluded from subclasses" it 'gives the same subclasses after rspec clears its mocks' do original_subclasses = TestClass::Nested.subclasses diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7388670af..c1e87cdb9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -174,3 +174,13 @@ def self.fake_matcher_description RSpec::Mocks.configuration.syntax = orig_syntax end end + +RSpec.shared_context "with stubbed classes excluded from subclasses" do + before do + RSpec::Mocks.configuration.exclude_stubbed_classes_from_subclasses = true + end + + after do + RSpec::Mocks.configuration.exclude_stubbed_classes_from_subclasses = false + end +end