mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
37bc11d720
Ruby has [changed the arity of Symbol#to_proc from -1 to -2][ruby]. This commit
updates some arity checks we have in factory_bot to handle that case.
This should get the Ruby HEAD + Rails 6 tests passing on CI (the Ruby
head with other versions of Rails is still failing for various reasons).
[ruby]: 5b29ea0845
33 lines
633 B
Ruby
33 lines
633 B
Ruby
module FactoryBot
|
|
class Callback
|
|
attr_reader :name
|
|
|
|
def initialize(name, block)
|
|
@name = name.to_sym
|
|
@block = block
|
|
end
|
|
|
|
def run(instance, evaluator)
|
|
case block.arity
|
|
when 1, -1, -2 then syntax_runner.instance_exec(instance, &block)
|
|
when 2 then syntax_runner.instance_exec(instance, evaluator, &block)
|
|
else syntax_runner.instance_exec(&block)
|
|
end
|
|
end
|
|
|
|
def ==(other)
|
|
name == other.name &&
|
|
block == other.block
|
|
end
|
|
|
|
protected
|
|
|
|
attr_reader :block
|
|
|
|
private
|
|
|
|
def syntax_runner
|
|
@syntax_runner ||= SyntaxRunner.new
|
|
end
|
|
end
|
|
end
|