1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Fix delegation

* (*args, **kwargs) is incorrect in 2.7, only ruby2_keywords works on 2.7.
* See https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
This commit is contained in:
Benoit Daloze 2021-02-13 11:58:41 +01:00 committed by Daniel Colson
parent b6606abe7a
commit 6f3fe876f8
2 changed files with 10 additions and 30 deletions

View file

@ -6,22 +6,11 @@ module FactoryBot
@invoked_methods = [] @invoked_methods = []
end end
if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("3.0")
def method_missing(name, *args, **kwargs, &block) # rubocop:disable Style/MissingRespondToMissing
@invoked_methods << name
super
end
elsif ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
ruby2_keywords def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@invoked_methods << name
super
end
else
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@invoked_methods << name @invoked_methods << name
super super
end end
end ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
def __invoked_methods__ def __invoked_methods__
@invoked_methods.uniq @invoked_methods.uniq

View file

@ -35,15 +35,6 @@ module FactoryBot
attr_accessor :instance attr_accessor :instance
if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
def method_missing(method_name, *args, **kwargs, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
if @instance.respond_to?(method_name)
@instance.send(method_name, *args, **kwargs, &block)
else
SyntaxRunner.new.send(method_name, *args, **kwargs, &block)
end
end
else
def method_missing(method_name, *args, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing def method_missing(method_name, *args, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
if @instance.respond_to?(method_name) if @instance.respond_to?(method_name)
@instance.send(method_name, *args, &block) @instance.send(method_name, *args, &block)
@ -51,7 +42,7 @@ module FactoryBot
SyntaxRunner.new.send(method_name, *args, &block) SyntaxRunner.new.send(method_name, *args, &block)
end end
end end
end ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
def respond_to_missing?(method_name, _include_private = false) def respond_to_missing?(method_name, _include_private = false)
@instance.respond_to?(method_name) || SyntaxRunner.new.respond_to?(method_name) @instance.respond_to?(method_name) || SyntaxRunner.new.respond_to?(method_name)