Convert fixtures into Factory Girl in Rails

后端 未结 3 412
孤城傲影
孤城傲影 2021-01-06 07:48

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?

相关标签:
3条回答
  • 2021-01-06 08:00

    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.

    0 讨论(0)
  • 2021-01-06 08:10

    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)

    0 讨论(0)
  • 2021-01-06 08:17

    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.

    0 讨论(0)
提交回复
热议问题