如何通过引擎使用FactoryGirl工厂 [英] How to use FactoryGirl factories from an engine

查看:57
本文介绍了如何通过引擎使用FactoryGirl工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有两个共享相同数据库和模型的Web应用程序.为了使其保持干燥,我们创建了一个包含所有这些模型的引擎.该引擎通过Gemfile包含在相应的应用程序中.我们确实对引擎内部的RSpec和FactoryGirl进行了测试.

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?

推荐答案

好,这可行: https://github.com. com/thoughtbot/factory_girl_rails/pull/42

如在该请求请求中所述,请在您的核心引擎中包含该代码段.

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

在核心引擎中,您还需要修改".gemspec"文件以添加到"spec/factories"文件中:

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.

这篇关于如何通过引擎使用FactoryGirl工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆