Rietta
Rietta.com Security
You are reading The Rietta Blog, a publication about the web since 2005.

Automatically Migrate From Factory Girl to Factory Bot

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

1
2
3
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.

About Alex Piechowski

Alex Piechowski's photo

Alex Piechowski is a web application developer who is focused on Ruby on Rails app design that takes security into consideration.