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

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

问题描述

我们有两个网络应用共享相同的数据库和模型.为了保持干燥,我们创建了一个包含所有这些模型的引擎.该引擎通过 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/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天全站免登陆