Skip to content

Instantly share code, notes, and snippets.

@biinari
Last active December 27, 2018 16:47
Show Gist options
  • Save biinari/7483179 to your computer and use it in GitHub Desktop.
Save biinari/7483179 to your computer and use it in GitHub Desktop.
Converts mocha expectations to rspec-mocks.
s/\([^.a-zA-Z_-]\)stub\>/\1double/g
s/\([^.a-zA-Z_-]\)mock\>/\1double/g
s/\.returns\>/.and_return/g
s/\.yields\>/.and_yield/g
s/\(\S\+\)\.stubs(/allow(\1).to receive(/g
s/\(\S\+\)\.expects(/expect(\1).to receive(/g
s/at_least_once/at_least(:once)/g
s/at_most_once/at_most(:once)/g
s/\.raises\>/.and_raise/g
s/\(allow\|expect\)(\(\S\+\)\.any_instance).to receive/\1_any_instance_of(\2).to receive/g
find spec -type f -exec sed -i'' -f mocha_to_rspec_mocks.sed \{\} \+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment