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

Show the registered traits in the "Trait not registered" error message #1727

Open
neilvcarvalho opened this issue Jan 30, 2025 · 2 comments · May be fixed by #1732
Open

Show the registered traits in the "Trait not registered" error message #1727

neilvcarvalho opened this issue Jan 30, 2025 · 2 comments · May be fixed by #1732
Labels

Comments

@neilvcarvalho
Copy link
Member

Problem this feature will solve

Sometimes, when creating a new record with Factory Bot, we believe a trait exists, but it doesn't. That can happen because it was written in another way, because of a typo, or just because it wasn't implemented yet.

Failure/Error: admin = create(:user, :admin)

KeyError:
Trait not registered: "admin"

When that happens, we have to find the factory definition to know what are the available traits. It would be less disruptive to the flow to know what traits were registered.

Desired solution

We could see something like:

Failure/Error: admin = create(:user, :admin)

KeyError:
Trait not registered: "admin". Registered traits: "administrator", "guest"
@CodeMeister
Copy link
Contributor

Great idea @neilvcarvalho

Pull request #1717 fixes an issue with inherited traits and changes how they are recorded, so the code for this feature will depend on whether #1717 is approved or rejected.

Can you take look? 🙏

@neilvcarvalho
Copy link
Member Author

Great to know! This PR is on my list for tomorrow (which also includes a release for Factory Bot and Factory Bot Rails).

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.

2 participants