thoughtbot / factory_bot_rails

Factory Bot ♥ Rails

Home Page:https://thoughtbot.com/services/ruby-on-rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

config.factory_bot.definition_file_paths in an Engine

jrochkind opened this issue · comments

You can configure by adding the following to "config/application.rb" or the appropriate environment configuration in "config/environments":

 config.factory_bot.definition_file_paths = ["custom/factories"]

When I try to do this in my project (which is a Rails engine, so that may be part of the issue), I get

NoMethodError: undefined method `factory_bot' for #<Rails::Application::Configuration:0x00007faa177a7240>

Any ideas for how to get this to work in engine dev? The defaults are looking for factories in the engine 'dummy' app rather than the engine itself, is why I am needing to customize it.

This configuration is new (#289) and isn't in a released version yet. I am working on a fb and fbr 5 release, but it is not quite ready.

I think https://github.com/thoughtbot/factory_bot_rails/pull/149/files is how people used to do this.

Ah right, I forgot about being careful about looking at master README.

Thanks, that link is helpful. You might still get a "double" load doing it that way. Maybe. I haven't figured out how/the place to intervene to actually replace factory_bot_rails' defaults before it loads factories from them.

Hopefully your new code takes that into account, including in engine context, glad you were already working on improvements here!

Yup, the new configuration should work fine in an engine. I'll close this for now, but once version 5 is out, we can open another issue if there are any problems.