File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 22# suite and ammeter.
33require 'rspec/rails/matchers'
44
5+ if ::Rails ::VERSION ::MAJOR >= 7
6+ require 'active_support/execution_context/test_helper'
7+ end
8+
59module RSpec
610 module Rails
711 # @api public
@@ -12,7 +16,10 @@ module RailsExampleGroup
1216 include RSpec ::Rails ::MinitestLifecycleAdapter
1317 include RSpec ::Rails ::MinitestAssertionAdapter
1418 include RSpec ::Rails ::FixtureSupport
15- include RSpec ::Rails ::TaggedLoggingAdapter if ::Rails ::VERSION ::MAJOR >= 7
19+ if ::Rails ::VERSION ::MAJOR >= 7
20+ include RSpec ::Rails ::TaggedLoggingAdapter
21+ include ActiveSupport ::ExecutionContext ::TestHelper
22+ end
1623 end
1724 end
1825end
Original file line number Diff line number Diff line change @@ -5,5 +5,32 @@ module RSpec::Rails
55 expect ( described_class . private_instance_methods ) . to include ( :tagged_logger )
66 end
77 end
8+
9+ it 'does not leak context between example groups' , if : ::Rails ::VERSION ::MAJOR >= 7 do
10+ groups =
11+ [
12+ RSpec ::Core ::ExampleGroup . describe ( "A group" ) do
13+ include RSpec ::Rails ::RailsExampleGroup
14+ specify { expect ( ActiveSupport ::ExecutionContext . to_h ) . to eq ( { } ) }
15+ end ,
16+ RSpec ::Core ::ExampleGroup . describe ( "A controller group" , type : :controller ) do
17+ specify do
18+ Rails . error . set_context ( foo : "bar" )
19+ expect ( ActiveSupport ::ExecutionContext . to_h ) . to eq ( foo : "bar" )
20+ end
21+ end ,
22+ RSpec ::Core ::ExampleGroup . describe ( "Another group" ) do
23+ include RSpec ::Rails ::RailsExampleGroup
24+ specify { expect ( ActiveSupport ::ExecutionContext . to_h ) . to eq ( { } ) }
25+ end
26+ ]
27+
28+ results =
29+ groups . map do |group |
30+ group . run ( failure_reporter ) ? true : failure_reporter . exceptions
31+ end
32+
33+ expect ( results ) . to all be true
34+ end
835 end
936end
You can’t perform that action at this time.
0 commit comments