Skip to content

Instantly share code, notes, and snippets.

@remvee
Created December 29, 2011 10:29
Show Gist options
  • Select an option

  • Save remvee/1533382 to your computer and use it in GitHub Desktop.

Select an option

Save remvee/1533382 to your computer and use it in GitHub Desktop.
Helper to gut a const/class in a spec to avoid having "expects" "never" on all methods
module MochaHelper
def with_mocked_const(name, &block)
original = Object.const_get(name)
Object.instance_eval do
remove_const(name)
const_set(name, Mocha::Mock.new(name))
end
yield
ensure
Object.instance_eval do
remove_const(name)
const_set(name, original)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment