Skip to content

Instantly share code, notes, and snippets.

@jodell
Created September 14, 2011 15:44
Show Gist options
  • Save jodell/1216922 to your computer and use it in GitHub Desktop.
Save jodell/1216922 to your computer and use it in GitHub Desktop.
private method testing (if you have to)
# 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