Upgrading your codebase should involve only a few steps, and in most cases, it involves updating the Gemfile, factories file(s), and support file configuring the testing framework.
Replace references to factory_girl_rails or factory_girl with factory_bot_rails or factory_bot. Both new gems are available starting at version 4.8.2.
# Gemfile
# old
group :development, :test do
gem "factory_girl_rails"
# or
gem "factory_girl"
end
# new
group :development, :test do
gem "factory_bot_rails"
# or
gem "factory_bot"
end
A global find-and-replace of FactoryGirl
to FactoryBot
across the codebase
to replace all references with the new constant should do the trick. For
example, on macOS:
grep -e FactoryGirl **/*.rake **/*.rb -s -l | xargs sed -i "" "s|FactoryGirl|FactoryBot|g"
Linux:
find . -type f -print0| xargs -0 sed -i 's/FactoryGirl/FactoryBot/g'
If these examples don't work for you, various other approaches have been suggested in pull requests #1070, #1075, #1084, #1095, and #1102.
If you're requiring files from factory_girl or factory_girl_rails directly, you'll have to update the paths.
grep -e factory_girl **/*.rake **/*.rb -s -l | xargs sed -i "" "s|factory_girl|factory_bot|g"