@@ -38,28 +38,50 @@ def run_in_transaction?
38
38
module Fixtures
39
39
extend ActiveSupport ::Concern
40
40
41
+ # rubocop:disable Metrics/BlockLength
41
42
class_methods do
42
- def fixtures ( *args )
43
- orig_methods = private_instance_methods
44
- super . tap do
45
- new_methods = private_instance_methods - orig_methods
46
- new_methods . each do |method_name |
47
- proxy_method_warning_if_called_in_before_context_scope ( method_name )
43
+ if ::Rails . version . to_f >= 7.1
44
+ def fixtures ( *args )
45
+ super . tap do
46
+ fixture_sets . each_key do |fixture_name |
47
+ proxy_method_warning_if_called_in_before_context_scope ( fixture_name )
48
+ end
49
+ end
50
+ end
51
+
52
+ def proxy_method_warning_if_called_in_before_context_scope ( fixture_name )
53
+ define_method ( fixture_name ) do |*args , **kwargs , &blk |
54
+ if RSpec . current_scope == :before_context_hook
55
+ RSpec . warn_with ( "Calling fixture method in before :context " )
56
+ else
57
+ access_fixture ( fixture_name , *args , **kwargs , &blk )
58
+ end
59
+ end
60
+ end
61
+ else
62
+ def fixtures ( *args )
63
+ orig_methods = private_instance_methods
64
+ super . tap do
65
+ new_methods = private_instance_methods - orig_methods
66
+ new_methods . each do |method_name |
67
+ proxy_method_warning_if_called_in_before_context_scope ( method_name )
68
+ end
48
69
end
49
70
end
50
- end
51
71
52
- def proxy_method_warning_if_called_in_before_context_scope ( method_name )
53
- orig_implementation = instance_method ( method_name )
54
- define_method ( method_name ) do |*args , &blk |
55
- if RSpec . current_scope == :before_context_hook
56
- RSpec . warn_with ( "Calling fixture method in before :context " )
57
- else
58
- orig_implementation . bind ( self ) . call ( *args , &blk )
72
+ def proxy_method_warning_if_called_in_before_context_scope ( method_name )
73
+ orig_implementation = instance_method ( method_name )
74
+ define_method ( method_name ) do |*args , &blk |
75
+ if RSpec . current_scope == :before_context_hook
76
+ RSpec . warn_with ( "Calling fixture method in before :context " )
77
+ else
78
+ orig_implementation . bind ( self ) . call ( *args , &blk )
79
+ end
59
80
end
60
81
end
61
82
end
62
83
end
84
+ # rubocop:enable Metrics/BlockLength
63
85
end
64
86
end
65
87
end
0 commit comments