thoughtbot / thoughtbot/factory_bot
FactoryBot.modify does not override gem factory
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 8.2k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I tried to get all factories from spree gem, but overriding some of the factories, in this case user factories.
I add it them using require 'spree/testing_support/factories' in spec_helper.rb.
But
Using FactoryBot.modify I get
Factory not registered: "user"
Using FactoryBot.define I get
Factory already registered: user
Reproduction Steps
https://github.com/Set27/factory_bot_overriding_issue
System configuration
factory_bot 6.5.1
rails 7.2.2.1
ruby 3.3.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and the require in spec_helper.rb, then inspect how spree/testing_support/factories registers the user factories before FactoryBot.modify runs. Compare the KeyError from FactoryBot.modify with the duplicate-definition error from FactoryBot.define. Done means the gem-provided user factory can be overridden without either error, with the behavior demonstrated in the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100