-
-
Save serg-kovalev/8487870b128b093721e4 to your computer and use it in GitHub Desktop.
FactoryGirl upgrade from version 2.* to 3.*
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FactoryGirl3ForYouAndMe | |
# The new syntax: http://robots.thoughtbot.com/post/19412394597/factory-girl-hits-3-0 | |
# | |
# Where to learn sed? | |
# http://www.grymoire.com/Unix/Sed.html#uh-6 | |
# http://www.markhneedham.com/blog/2011/01/11/sed-across-multiple-files/ | |
# | |
# What needs to change? | |
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.create" | |
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.build" | |
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.define" | |
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.attributes_for" | |
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory\(\:" | |
# Lets do it! | |
find . -type f -name "factor*.rb" -print0 | xargs -0 sed -i '.sed' -e 's/Factory.define/FactoryGirl.define/' | |
find . -type f -name "*_spec.rb" -print0 | xargs -0 sed -i '.sed' -e 's/Factory.create/FactoryGirl.create/' -e 's/Factory.build/FactoryGirl.build/' -e 's/Factory(:/FactoryGirl.create(:/' -e 's/Factory.define/FactoryGirl.define/' -e 's/Factory.attributes_for/FactoryGirl.attributes_for/' | |
# Fix FeedEngine Factory | |
find . -type f -name "*_spec.rb" -print0 | xargs -0 sed -i '.sed' -e 's/FeedEngine::FactoryGirl/FeedEngine::Factory/' | |
# Use syntax methods | |
find . -type f -name "*_spec.rb" -print0 | xargs -0 sed -i '.sed' -e 's/FactoryGirl.create/create/' -e 's/FactoryGirl.build/build/' -e 's/FactoryGirl.attributes_for/attributes_for/' | |
# Goodbye backups | |
find . -name "*.sed" -print0 | xargs -0 rm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment