thoughtbot / thoughtbot/factory_bot
Don't allow duplicate traits
Open
Nobody has claimed this yet.
bug
- Dominant language
- Ruby
- Stars
- 8.2k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
A factory can have the same trait multiple times
Reproduction Steps
FactoryBot.define do
factory :user, class: OpenStruct do
trait :admin do
name { "Admin" }
end
trait :admin do
name { "Administrator" }
end
end
end
Expected behavior
Raises an error when defining the second trait
Actual behavior
Lets me define a second trait but keeps only the first trait
System configuration
factory_bot version: 6.1.0
rails version: 6.1.3.1
ruby version: 2.7.3
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 by tracing how a factory registers a trait during the trait definition entry point, then inspect the existing tests around trait definitions. Add a regression test for defining the same trait name twice and verify that the second definition raises an error rather than being silently ignored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100