Testing private and protected methods with ruby

written by doug on April 18th, 2007 @ 01:48 PM

When I have to test my protected and private methods in ruby, I make the methods public for the scope of the test.


  MyClass.send(:public, *MyClass.protected_instance_methods)  
  MyClass.send(:public, *MyClass.private_instance_methods)

Just place this code in your testing class substituting your class name. Include the namespace if applicable.

Comments are closed

Options:

Size

Colors