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

require 'factory_bot' fails with latest ActiveSupport gem (7.2.0) #1685

Closed
aramprice opened this issue Aug 12, 2024 · 0 comments · Fixed by #1686
Closed

require 'factory_bot' fails with latest ActiveSupport gem (7.2.0) #1685

aramprice opened this issue Aug 12, 2024 · 0 comments · Fixed by #1686
Labels

Comments

@aramprice
Copy link

aramprice commented Aug 12, 2024

Per rails/rails#52582 one must require "active_support" before requiring any other definition(s) like active_support/core_ext/module/delegation.

Seems like the fix would be to add require "active_supoet" just before line 2 of lib/factory_bot.rb

Description

~/.gem/ruby/3.2.5/gems/activesupport-7.2.0/lib/active_support/delegation.rb:47:in `generate': uninitialized constant #<Class:ActiveSupport::Delegation>::Inflector (NameError)

Reproduction Steps

Create foo.rb with the following contents:

require 'factory_bot'

puts 'Success!'

Then invoke the file with ruby

Expected behavior

Should behave the same as with earlier versions of ActiveSupport:

; gem list activesupport

*** LOCAL GEMS ***

activesupport (7.1.3.4)

; ruby foo.rb
Success!

Actual behavior

; gem list activesupport

*** LOCAL GEMS ***

activesupport (7.2.0)

; ruby foo.rb
~/.gem/ruby/3.2.5/gems/activesupport-7.2.0/lib/active_support/delegation.rb:47:in `generate': uninitialized constant #<Class:ActiveSupport::Delegation>::Inflector (NameError)

          unless Inflector.safe_constantize(to.name).equal?(to)
                 ^^^^^^^^^
	from ~/.gem/ruby/3.2.5/gems/activesupport-7.2.0/lib/active_support/core_ext/module/delegation.rb:161:in `delegate'
	from ~/.gem/ruby/3.2.5/gems/factory_bot-6.4.6/lib/factory_bot/definition_hierarchy.rb:3:in `<class:DefinitionHierarchy>'
	from ~/.gem/ruby/3.2.5/gems/factory_bot-6.4.6/lib/factory_bot/definition_hierarchy.rb:2:in `<module:FactoryBot>'
	from ~/.gem/ruby/3.2.5/gems/factory_bot-6.4.6/lib/factory_bot/definition_hierarchy.rb:1:in `<top (required)>'
	from <internal:~/.rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:97:in `require'
	from <internal:~/.rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:97:in `require'
	from ~/.gem/ruby/3.2.5/gems/factory_bot-6.4.6/lib/factory_bot.rb:8:in `<top (required)>'
	from <internal:~/.rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
	from <internal:~/.rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
	from <internal:~/.rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:40:in `require'
	from foo.rb:1:in `<main>'
<internal:~/.rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require': cannot load such file -- factory_bot (LoadError)
	from <internal:~/.rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
	from foo.rb:1:in `<main>'

System configuration

factory_bot version: factory_bot (6.4.6)
rails version: n/a activesupport (7.2.0)
ruby version: ruby-3.2.5

@aramprice aramprice added the bug label Aug 12, 2024
@aramprice aramprice changed the title factory bot fails to load with latest (7.2.0) ActiveSupport factory bot fails to load with latest ActiveSupport gem (7.2.0) Aug 12, 2024
@aramprice aramprice changed the title factory bot fails to load with latest ActiveSupport gem (7.2.0) require 'factory_bot' fails with latest ActiveSupport gem (7.2.0) Aug 12, 2024
Earlopain added a commit to Earlopain/factory_bot that referenced this issue Aug 13, 2024
In order to use parts of active_support, active_support itself must be required first.
https://guides.rubyonrails.org/active_support_core_extensions.html#cherry-picking-a-definition

Fixes thoughtbot#1685
Earlopain added a commit to Earlopain/factory_bot that referenced this issue Aug 13, 2024
In order to use parts of active_support, active_support itself must be required first.
https://guides.rubyonrails.org/active_support_core_extensions.html#cherry-picking-a-definition

Fixes thoughtbot#1685
brucebolt added a commit to alphagov/link-checker-api that referenced this issue Aug 15, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.
brucebolt added a commit to alphagov/publishing-api that referenced this issue Aug 15, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.
brucebolt added a commit to alphagov/link-checker-api that referenced this issue Aug 15, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.
KludgeKML added a commit to alphagov/locations-api that referenced this issue Aug 21, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.

(Thanks to @brucebolt)
KludgeKML added a commit to alphagov/email-alert-api that referenced this issue Aug 21, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.

(Thanks to @brucebolt)
KludgeKML added a commit to alphagov/email-alert-api that referenced this issue Aug 27, 2024
As per rails/rails#52582, one must `require
active_support` before requiring any other definition(s) like
`active_support/core_ext/module/delegation`, which is included by
`factory_bot_rails`.

Therefore requiring `active_support` here, until
thoughtbot/factory_bot#1685 is resolved.

(Thanks to @brucebolt)
deepakkumarnd added a commit to openvitae-tech/blackboard-lms that referenced this issue Oct 17, 2024
On updating rails the tests failed due to an issue with factory_bot. This is fixed by updating factory_bot_rails
thoughtbot/factory_bot#1685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant