Skip to content

Commit 81992e1

Browse files
committed
Rails 7.1 remove fixture methods, so know we use fixture sets to define this
1 parent 74eab82 commit 81992e1

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

lib/rspec/rails/fixture_support.rb

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,50 @@ def run_in_transaction?
3838
module Fixtures
3939
extend ActiveSupport::Concern
4040

41+
# rubocop:disable Metrics/BlockLength
4142
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
4869
end
4970
end
50-
end
5171

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
5980
end
6081
end
6182
end
6283
end
84+
# rubocop:enable Metrics/BlockLength
6385
end
6486
end
6587
end

0 commit comments

Comments
 (0)