Convert fixtures into Factory Girl in Rails

回眸只為那壹抹淺笑 提交于 2019-11-30 22:04:09

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.

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.

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