Since 1999

 

1 minutes estimated reading time.

Automatically Migrate from Factory Girl to Factory Bot

Alex Piechowski

Gem updates are tedious. Gem name changes are even more tedious. This quick script converts Factory Girl references to Factory Bot references.

grep -e FactoryGirl -sl **/*.rake **/*.rb | xargs sed -i "s/FactoryGirl/FactoryBot/g"
grep -e factory_girl -sl **/*.rake **/*.rb Gemfile | xargs sed -i "s/factory_girl/factory_bot/g"
# run bundle install to generate a new Gemfile.lock

The first line searches for all instances of FactoryGirl and replaces them with FactoryBot in all ruby or rake files. The second one covers factory_girl to factory_bot in ruby, rake, or your Gemfile.

After that, the last step is for you to build your Gemfile.lock with a bundle install and your migration should be complete.