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

Add factory_bot.before_factory_run instrumentation event #1673

Open
donny741 opened this issue Jul 18, 2024 · 0 comments
Open

Add factory_bot.before_factory_run instrumentation event #1673

donny741 opened this issue Jul 18, 2024 · 0 comments
Labels

Comments

@donny741
Copy link

Problem this feature will solve

I need to implement a factory call stack that can be displayed in the error message that is raised from factory's after callback.

Factories can be deeply nested into one another and when the error message is displayed, it is hard to track down the path that led to the error because only the top-level factory is displayed in the message, and stack trace does not include nested factories.

Desired solution

Add ActiveSupport::Notifications.instrument("factory_bot.before_factory_run", instrumentation_payload) to factory_runner.rb before L28

Alternatives considered

Using Global callbacks, however, I cannot find a way to get the factory name from within the callback.

Using factory_bot.compile_factory event instead. Works only when running a single spec, with multiple specs, the compiled factories are cached and the event is no longer invoked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant