Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to used ruby 2.7 #1719

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

br4tech
Copy link

@br4tech br4tech commented Nov 11, 2024

Description

Syntax error in factory_bot gem files when using Ruby 2.7.0.

Reproduction Steps

  1. Install Ruby 2.7.0.
  2. Create a new Rails application.
  3. Add the factory_bot_rails gem to the Gemfile.
  4. Run bundle install.
  5. Create a test file that uses FactoryBot.
  6. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant