You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Factory bot allows for traits to be defined outside of a factory definition. This introduces the risk of collisions in as the tests grow in a codebase.
Traits allow you to group attributes together and then apply them to any factory.
And the reason for the very existence suggests that global traits have a reason to exist outside of factories.
But I agree with you that if a trait is meant to be used in several factories, it would make sense to at least define it in a separate file.
Are you certain that FactoryBot wouldn't/shouldn't warn about this?
It would be quite hard to tell if e.g. an :admin trait is defined in both spec/factories/common_traits.rb and spec/factories/admin.rb with static analysis.
It looks like factory bot does raise a FactoryBot::DuplicateDefinitionError. In our case, traits were added to the global scope unintentionally. I was hoping a cop could make global factories explicit.
it would make sense to at least define it in a separate file
This makes sense to me. Thoughts on a "global traits shouldn't be defined in the same file as factories" type of cop?
If this doesn't seem generally valuable, feel free to close @pirj
Factory bot allows for traits to be defined outside of a factory definition. This introduces the risk of collisions in as the tests grow in a codebase.
Example:
Works in a test
Could a cop flag global trait definitions?
The text was updated successfully, but these errors were encountered: