Travis Whitton whitton@atlantic.net writes:
It seems that in order to be able to unit test a method it has to be
publicly accessible. Is there a way to use test/unit to test private methods
and instance variables?
You can use instance_eval to subvert “private.” Though when I run
into this, I usually skip testing them. After all, the private
methods do their job properly if all the public methods that use them
pass their tests.
class MyClass
def private_method
“private”
end
private :private_method
end
if $0 == FILE
require ‘test/unit’
class TestMyClass < Test::Unit::TestCase
def setup
@instance = MyClass.new
end
def test_private_method
assert_equal(“private”, @instance.instance_eval { private_method })
end
end
end
···
–
matt