将装置转换为 Rails 中的 Factory Girl
我想将我的装置迁移到 Rails 中的“Factory Girl”。
有没有简单的方法可以转换factories.rb 文件中的所有yml 文件?
I'd like to migrate my fixtures to "Factory Girl" in Rails.
Is there any easy way to convert all yml files in a factories.rb file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您想要做的是找到一个脚本来查看您的模型并为它们生成工厂。我尝试过一次(使用除了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.
几天前,我刚刚发布了一个名为 fix_to_chix 的 gem,以解决完全相同的问题。
它可能需要很多增强功能,但可能会对您有所帮助: http://github.com/caike/fix_to_chix< /a> (您需要将其复制并粘贴到浏览器上,因为似乎在网址中放置了一些字符)
I've just released a gem called fix_to_chix a few days ago to address the exact same issue.
It probably needs a lot of enhancements, but it might help you: http://github.com/caike/fix_to_chix (you need to copy and paste it on your browser since SO seems to put some chars in the url)
您到底期望最终的工厂是什么样的?工厂的整个想法是您不必维护一长串测试数据。相反,数据是动态创建的,靠近您的测试,就在它应该在的地方。
What exactly would you expect the resulting factories to be? The whole idea of Factories is that you don't have to maintain a long list of test data. Instead, the data is created on the fly, close to your tests, where it should be.