Syntax error in factory_bot gem files when using Ruby 2.7.0
Opened this issue · 1 comments
br4tech commented
Description
Syntax error in factory_bot gem files when using Ruby 2.7.0.
Reproduction Steps
- Install Ruby 2.7.0.
- Create a new Rails application.
- Add the
factory_bot_rails
gem to the Gemfile. - Run
bundle install
. - Create a test file that uses
FactoryBot
. - Run the test with
rspec
.
Expected Behavior
The test should run without errors.
Actual Behavior
A syntax error occurs in factory_bot
gem files, such as evaluator.rb
and definition_proxy.rb
, preventing the test from running. The error message points to lines of code using the method_missing
and sequence
methods.
1. File : evaluator.rb
Correction:
Add the *args
and &block
parameters to the method_missing
method definition
def method_missing(method_name, *args, &block)
if @instance.respond_to?(method_name)
@instance.send(method_name, *args, &block)
else
SyntaxRunner.new.send(method_name, *args, &block)
end
end
2. File : definition_proxy.rb
Correction:
The method_missing
method definition is already correct. Change the sequence
method definition to:
def sequence(name, *args, &block)
sequence = Sequence.new(name, *args, &block)
FactoryBot::Internal.register_inline_sequence(sequence)
add_attribute(name) { increment_sequence(sequence) }
end
3. File : default.rb
Correction:
Change the sequence
method definition to::
def sequence(name, *args, &block)
register_sequence(Sequence.new(name, *args, &block))
end
The corrections involve adding the parameters *args
and &block
to the method_missing
and sequence
methods to ensure compatibility with Ruby 2.7.0 syntax.
System Configuration
- factory_bot_rails version: 6.4.5
- factory_bot version: 6.4.5
- rails version: 6.0.0
- ruby version: 2.7.0