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

Syntax error in factory_bot gem files when using Ruby 2.7.0 #1718

Closed
br4tech opened this issue Nov 11, 2024 · 2 comments
Closed

Syntax error in factory_bot gem files when using Ruby 2.7.0 #1718

br4tech opened this issue Nov 11, 2024 · 2 comments
Labels

Comments

@br4tech
Copy link

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
@br4tech br4tech added the bug label Nov 11, 2024
@Earlopain
Copy link
Contributor

Earlopain commented Dec 3, 2024

#1719 will do nothing for you. The required ruby version for factory_bot is already Ruby 3.0 and you will not be able to install it with these changes. See #1614

gem 'factory_bot', '!= 6.4.5' should help you out.

@neilvcarvalho
Copy link
Member

Hi @br4tech, thanks for opening this detailed issue.

@Earlopain is correct: Ruby 2.7 is supported up to version 6.4.4.

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

No branches or pull requests

3 participants