将装置转换为 Rails 中的 Factory Girl

发布于 2024-08-06 00:28:57 字数 88 浏览 15 评论 0原文

我想将我的装置迁移到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不及他 2024-08-13 00:28:57

我假设您想要做的是找到一个脚本来查看您的模型并为它们生成工厂。我尝试过一次(使用除了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.

勿忘心安 2024-08-13 00:28:57

几天前,我刚刚发布了一个名为 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)

黎夕旧梦 2024-08-13 00:28:57

您到底期望最终的工厂是什么样的?工厂的整个想法是您不必维护一长串测试数据。相反,数据是动态创建的,靠近您的测试,就在它应该在的地方。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文