File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 33require  'rspec/rails/matchers' 
44
55if  ::Rails ::VERSION ::MAJOR  >= 7 
6+   require  'active_support/current_attributes/test_helper' 
67  require  'active_support/execution_context/test_helper' 
78end 
89
@@ -18,6 +19,7 @@ module RailsExampleGroup
1819      include  RSpec ::Rails ::FixtureSupport 
1920      if  ::Rails ::VERSION ::MAJOR  >= 7 
2021        include  RSpec ::Rails ::TaggedLoggingAdapter 
22+         include  ActiveSupport ::CurrentAttributes ::TestHelper 
2123        include  ActiveSupport ::ExecutionContext ::TestHelper 
2224      end 
2325    end 
Original file line number Diff line number Diff line change 11module  RSpec ::Rails 
22  RSpec . describe  RailsExampleGroup  do 
3-     if  ::Rails ::VERSION ::MAJOR  >= 7 
4-       it  'supports tagged_logger'  do 
5-         expect ( described_class . private_instance_methods ) . to  include ( :tagged_logger ) 
6-       end 
3+     it  'supports tagged_logger' ,  if : ::Rails ::VERSION ::MAJOR  >= 7  do 
4+       expect ( described_class . private_instance_methods ) . to  include ( :tagged_logger ) 
75    end 
86
97    it  'does not leak context between example groups' ,  if : ::Rails ::VERSION ::MAJOR  >= 7  do 
@@ -32,5 +30,31 @@ module RSpec::Rails
3230
3331      expect ( results ) . to  all  be  true 
3432    end 
33+ 
34+     it  'will not leak ActiveSupport::CurrentAttributes between examples' ,  if : ::Rails ::VERSION ::MAJOR  >= 7  do 
35+       group  = 
36+         RSpec ::Core ::ExampleGroup . describe ( "A group" ,  order : :defined )  do 
37+           include  RSpec ::Rails ::RailsExampleGroup 
38+ 
39+           # rubocop:disable Lint/ConstantDefinitionInBlock 
40+           class  CurrentSample  < ActiveSupport ::CurrentAttributes 
41+             attribute  :request_id 
42+           end 
43+           # rubocop:enable Lint/ConstantDefinitionInBlock 
44+ 
45+           it  'sets a current attribute'  do 
46+             CurrentSample . request_id  =  '123' 
47+             expect ( CurrentSample . request_id ) . to  eq ( '123' ) 
48+           end 
49+ 
50+           it  'does not leak current attributes'  do 
51+             expect ( CurrentSample . request_id ) . to  eq ( nil ) 
52+           end 
53+         end 
54+ 
55+       expect ( 
56+         group . run ( failure_reporter )  ? true  : failure_reporter . exceptions 
57+       ) . to  be  true 
58+     end 
3559  end 
3660end 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments