Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Created September 2, 2012 22:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lucascaton/3605012 to your computer and use it in GitHub Desktop.
Save lucascaton/3605012 to your computer and use it in GitHub Desktop.
RSpec's New Expectation Syntax - migration script
# Include this in your spec_helper.rb:
config.expect_with :rspec do |c|
c.syntax = :expect
end
# Then, run:
find spec -name "*.rb" -exec gsed -i -e "s/\(\s\+\)\(.*\)\.should_not /\1expect(\2).not_to /g" -e "s/\(\s\+\)\(.*\)\.should /\1expect(\2).to /g" "{}" \;
# About RSpec's New Expectation Syntax
# http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
@lucascaton
Copy link
Author

If you don't have gsed and you're using Mac OSX, try to install that, running:
brew install gnu-sed

@thibaudgg
Copy link

If you want to migrate should_receive and should_not_receive too, run:

find spec -name "*.rb" -exec gsed -i -e "s/\(\s\+\)\(.*\)\.should_not /\1expect(\2).not_to /g" -e "s/\(\s\+\)\(.*\)\.should /\1expect(\2).to /g" -e "s/\(\s\+\)\(.*\)\.should_receive/\1expect(\2).to receive/g" -e "s/\(\s\+\)\(.*\)\.should_not_receive/\1expect(\2).to_not receive/g" "{}" \;

Thanks!

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