Created
December 12, 2013 20:35
-
-
Save aliang/7934968 to your computer and use it in GitHub Desktop.
Expose private methods for testing. Can accept a block, or just call in RSpec before/after blocks
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
class Class | |
def publicize_methods | |
@_saved_private_instance_methods = self.private_instance_methods | |
self.class_eval { public *@_saved_private_instance_methods } | |
if block_given? | |
yield | |
reprivatize_methods | |
end | |
end | |
def reprivatize_methods | |
if @_saved_private_instance_methods | |
self.class_eval { private *@_saved_private_instance_methods } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment