Skip to content

Instantly share code, notes, and snippets.

@aliang
Created December 12, 2013 20:35
Show Gist options
  • Save aliang/7934968 to your computer and use it in GitHub Desktop.
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
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