Skip to content

Instantly share code, notes, and snippets.

@peter
Created November 1, 2010 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter/658203 to your computer and use it in GitHub Desktop.
Save peter/658203 to your computer and use it in GitHub Desktop.
Avoid Stubbing Non-Existent Methods with Mocha
# In spec_helper.rb or test_helper.rb:
Mocha::Configuration.prevent(:stubbing_non_existent_method)
module MochaExtensions
module ObjectMethods
def expects_message(*args, &block)
Mocha::Configuration.allow(:stubbing_non_existent_method) { expects(*args, &block) }
end
def stubs_message(*args, &block)
Mocha::Configuration.allow(:stubbing_non_existent_method) { stubs(*args, &block) }
end
end
end
class Object
include MochaExtensions::ObjectMethods
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment