Convert fixtures into Factory Girl in Rails

浪尽此生 提交于 2019-11-30 17:53:14

问题


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?


回答1:


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.




回答2:


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)




回答3:


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.



来源:https://stackoverflow.com/questions/1445584/convert-fixtures-into-factory-girl-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!