将装置转换为Rails中的Factory Girl [英] Convert fixtures into Factory Girl in Rails

查看:58
本文介绍了将装置转换为Rails中的Factory Girl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的装置迁移到Rails中的"Factory Girl".

I'd like to migrate my fixtures to "Factory Girl" in Rails.

有没有简单的方法可以将所有yml文件转换为factory.rb文件?

Is there any easy way to convert all yml files in a factories.rb file?

推荐答案

我假设您要寻找的是找到一个脚本,该脚本将遍历您的模型并为其生成工厂.我尝试了一次(使用factory_girl以外的方法),发现其中充满了不良数据.

I am assuming what you are looking to do is find a script which will look through your models and generate the factories for them. I tried this once (with something other than factory_girl) and found it full of bad data.

我建议您慢慢过渡到使用工厂.在编写新测试或更新旧测试时,请创建必要的工厂.随着时间的流逝,如果您有时间和精力,则可以选择一个单独的测试用例,并用适当的工厂调用替换所有固定的数据调用,并删除测试用例顶部的特定固定要求.

I would suggest that you slowly transition to using factories. As you write new tests or update old ones, create the necessary factories. As time goes by, if you have the time and energy you can then choose an individual test case and replace all the fixtured data calls with the proper factory calls and remove the specific fixture requirement at the top of the test case.

这篇关于将装置转换为Rails中的Factory Girl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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