thoughtbot/factory_bot

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

Open

#1727 aperta il 30 gen 2025

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Ruby (2563 fork)batch import
featuregood first issue

Metriche repository

Star
 (8166 star)
Metriche merge PR
 (Merge medio 10h 15m) (1 PR mergiata in 30 g)

Descrizione

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"

Guida contributor