Created
December 29, 2011 10:29
-
-
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
This file contains hidden or 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
| 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