Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Expose private methods for testing. Can accept a block, or just call in RSpec before/after blocks
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
You can’t perform that action at this time.