包括 FactoryGirl 工厂
我使用 Factory Girl 而不是固定装置。我注意到,为了使我的 FactoryGirl 类可用,我必须调用此代码
def setup
super
Factory( :li_store);
Factory( :li_customer);
....
如果我的设置中或测试中的其他任何地方没有这些行,则不会创建我的 FactoryGirl 对象。有什么办法可以将我的工厂纳入其中吗?我尝试将工厂文件的 require 语句添加到测试的顶部,但它抱怨对象已经注册。
非常感谢任何帮助。
I am using Factory Girl instead of fixtures. I have noticed, that for my FactoryGirl classes to be available I have to call this code
def setup
super
Factory( :li_store);
Factory( :li_customer);
....
If I don't have those lines in my setup or anywhere else in my test then my FactoryGirl objects aren't created. Is there a way I can include my factories ? I have tried adding a require statement of the factory file to the top of my test, but it complains that the objects are already registered.
Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的测试中
require 'factory_girl'
并将您的factories.rb
文件放在/specs
或/tests
下。factories.rb
文件如下所示:在您的测试中,您只需调用
In your tests
require 'factory_girl'
and put yourfactories.rb
file under/specs
or/tests
.The
factories.rb
file looks like this:In your tests you then just call