How to use FactoryGirl factories from an engine

亡梦爱人 提交于 2019-12-09 02:56:20

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20261585/how-to-use-factorygirl-factories-from-an-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!