Created
September 14, 2011 15:44
-
-
Save jodell/1216922 to your computer and use it in GitHub Desktop.
private method testing (if you have to)
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
# http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html | |
require 'rubygems' | |
require 'dust' | |
require 'test/unit' | |
class Ninja | |
private | |
def kill(num_victims) | |
"#{num_victims} victims are no longer with us." | |
end | |
end | |
class Class | |
def publicize_methods | |
saved_private_instance_methods = self.private_instance_methods | |
self.class_eval { public *saved_private_instance_methods } | |
yield | |
self.class_eval { private *saved_private_instance_methods } | |
end | |
end | |
unit_tests do | |
test "kill returns a murder string" do | |
Ninja.publicize_methods do | |
assert_equal '3 victims are no longer with us.', Ninja.new.kill(3) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment