Skip to content

Instantly share code, notes, and snippets.

@gkop
Created April 9, 2012 01:58
Show Gist options
  • Save gkop/2340796 to your computer and use it in GitHub Desktop.
Save gkop/2340796 to your computer and use it in GitHub Desktop.
Regexes to upgrade to new FactoryGirl syntax
# NOTE if you want to do this outside a git repo, find . -type f can by substituted for git grep -l 'Factory'
# fix Factory.create and Factory()
$ git grep -l 'Factory' | xargs perl -pi -e 's/Factory(\.create)?\((\:)?(\w+)(, )?/FactoryGirl\.create\($2$3$4/g'
# fix Factory.build
$ git grep -l 'Factory' | xargs perl -pi -e 's/Factory\.build\((\:)?(\w+)(, )?/FactoryGirl\.build\($1$2$3/g'
# fix Factory.define
# NOTE after running this, at the very least you still have to wrap your definitions sets with a FactoryGirl.define do end block,
# and remove the block parameters from the definitions themselves. And there are gotchas, like needing to use Kernel.rand
# instead of rand
$ git grep -l 'Factory' | xargs perl -pi -e 's/Factory\.define/factory/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment