How to use FactoryGirl factories from an engine
Asked Answered
P

1

11

We have two web apps that share the same database and models. To keep it DRY we created an engine that contains all those models. This engine is included in the respective apps via the Gemfile. We do have tests with RSpec and FactoryGirl inside the engine.

Now we are trying to write integration tests and we would like to use the factories from the engine without copying or symlinking. Is there a way to achieve this programmatically?

Protero answered 28/11, 2013 at 8:58 Comment(1)
Wish I knew the answer – researching exactly this question now ><Mefford
M
13

Ok so this works: https://github.com/thoughtbot/factory_girl_rails/pull/42

As it says on that pull request, include that code snippet in your core engine.

In the core engine you also need to modify your ".gemspec" file to add in the "spec/factories" files:

s.files = Dir["{app,config,db,lib}/**/*", "spec/factories/**/*", "LICENSE", "Rakefile", "README.md"]

Then those factories will be available in the application that includes your engine.

Mefford answered 22/12, 2013 at 13:19 Comment(2)
Awesome, that did the trick! Thanks and happy holidays to you!Protero
You're welcome! I was happy to get it working for myself too :DMefford

© 2022 - 2024 — McMap. All rights reserved.