Created
May 28, 2010 09:42
-
-
Save peter/416978 to your computer and use it in GitHub Desktop.
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
# Notes on migrating from the RSpec builtin mocking framework to the Mocha framework | |
# 1. Comment in this line in spec_helper.rb: | |
config.mock_with :mocha | |
# 2. Specify your gem dependency (optional) in config/environments/test.rb: | |
config.gem "mocha", :version => "0.9.8" | |
# 3. Use query-replace to do most but not all of the DSL conversion | |
# should_receive -> expects | |
find spec -type f -iname '*.rb'|xargs ruby -pi.bak -e 'gsub(/\.should_receive\(/, ".expects(")' | |
# stub! -> stubs | |
find spec -type f -iname '*.rb'|xargs ruby -pi.bak -e 'gsub(/\.stub!\(/, ".stubs(")' | |
# and_return -> returns | |
find spec -type f -iname '*.rb'|xargs ruby -pi.bak -e 'gsub(/\.and_return\(/, ".returns(")' | |
# and_raise -> raises | |
find spec -type f -iname '*.rb'|xargs ruby -pi.bak -e 'gsub(/\.and_raise\(/, ".raises(")' | |
# mock(:symbol) -> mock(string) | |
find spec -type f -iname '*.rb'|xargs ruby -pi.bak -e "gsub(/mock\(:([a-z0-9_]+)\)/, 'mock(\'\1\')')" | |
# 4. Inspect and tweak the query-replace changes if needed | |
# 5. Do the following changes manually (or with a smart query-replace): | |
# - should_return with block becomes .with(arg_value1).returns(return_value1) | |
# - should_not_receive => expects.never |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment