Expanded trait error message to include list of defined traits. #1732
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes: #1727
Expands trait error messages to include a list of the factory's defined traits.
Included
The message now includes:
Registered traits: [:trait_1, :trait_2, :trait_3]
Example
Internal Definition Call
factory: :user
defined traits: :accessible_trait
error: internal reference to a missing trait :inaccessible_trait
Error Message:
Trait not registered: "inaccessible_trait". Registered traits: [:accessible_trait]. Referenced within "user" definition
User Trait Specified
factory: :user
defined traits: :accessible_trait
error: user calls an non-existent trait with
build(:user, :missing_trait)
Error Message:
Trait not registered: "missing_trait". Registered traits: [:accessible_trait]
Note
When the error is because a missing trait was called from within a factory's definition, the message still includes the original:
Referenced within "user" definition
Changes
lib/factory_bot/definition.rb
spec/acceptance/enum_traits_spec.rb
spec/acceptance/traits_spec.rb updated specs for new error message layout. added new use-case tests with: