What\'s the best way to unit test protected and private methods in Ruby, using the standard Ruby Test::Unit
framework?
I\'m sure somebody will pipe up a
Just reopen the class in your test file, and redefine the method or methods as public. You don't have to redefine the guts of the method itself, just pass the symbol into the public
call.
If you original class is defined like this:
class MyClass
private
def foo
true
end
end
In you test file, just do something like this:
class MyClass
public :foo
end
You can pass multiple symbols to public
if you want to expose more private methods.
public :foo, :bar