Skip to content

Instantly share code, notes, and snippets.

@mikegrassotti
Created March 30, 2012 05:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikegrassotti/2247065 to your computer and use it in GitHub Desktop.
Save mikegrassotti/2247065 to your computer and use it in GitHub Desktop.
Using sed to upgrade to Factory Girl 3
# 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
@barttenbrinke
Copy link

Thanks for saving days of work for programmers around the world!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment