1

I'm currently upgrading my rails application from rails 4 to rails 5. Is it necessary to change from Factory_girl to Factory_bot? What will happen if I proceed with a deprecation warning? further, I might be upgrading that application to rails 6, so would factory_girl work for rails 6?

Chaitali
  • 87
  • 13
  • 1
    The change it's just a naming change, it doesn't change any functionality. Anyway, the change is so easy it makes no sense to stick with the old one https://github.com/thoughtbot/factory_bot/blob/4-9-0-stable/UPGRADE_FROM_FACTORY_GIRL.md – arieljuod Jan 13 '20 at 12:41
  • Thank you for your suggestion. I have changed it to factory_bot in all files. However, I'm getting an error that the Factory is not registered. Also, is it compulsory to have rails_helper file? It seems that I don't have it in my old running application on rails 4. Error: Request should create a valid object Failure/Error: user = FactoryBot.create(:user) KeyError: Factory not registered: "user" – Chaitali Jan 14 '20 at 10:22
  • Usually the rails_helper file includes tests configuration specific to rails (while test_helper includes not rails related test configuration). I'm not sure why you don't have that. Are you using factory_bot or factory_bot_rails? – arieljuod Jan 14 '20 at 13:18
  • We are using factory_bot_rails – Chaitali Jan 14 '20 at 17:53

1 Answers1

0

FactoryGirl was renamed to FactoryBot in October 2017. (The original name was based on some inside joke/pop culture reference, which some argued was a poor decision.)

This has got nothing to do with upgrading rails, and everything to do with upgrading factory_girl/factory_bot.

Use the new name. It makes no sense to keep the old name - and regardless, your code will break at some point when updating versions, if you don't perform the rename.

The change is quite straightforward, and there are various guides people have written about the upgrade, such as this.

Essentially, all you need to do is:

  1. Rename factory_girl and/or factory_girl_rails in the Gemfile, to factory_bot and factory_bot_rails.
  2. Rename any mention of FactoryGirl to FactoryBot. (You could use git grep to ensure nothing is missed.)
Tom Lord
  • 27,404
  • 4
  • 50
  • 77