Doug Bryant

Tech thoughts and notes

Testing Private and Protected Methods With Ruby

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.