From: Robert Feldt Date: 2006-05-15T18:29:46+09:00 Subject: Re: Testing private methods On 5/15/06, Peter Hickman wrote: > I have a class with a lot of private utility methods that makes the code > a lot cleaner. However I want to test them with unit tests. How can I do > this if they are private? > In your test code do: class ClassUnderTest public :private_method1, :private_method2 # ... end as exemplified by: feldt:~$ irb irb(main):001:0> class T irb(main):002:1> private irb(main):003:1> def a; 1; end irb(main):004:1> end => nil irb(main):005:0> t = T.new => # irb(main):006:0> t.a NoMethodError: private method `a' called for # from (irb):6 from :0 irb(main):007:0> class T irb(main):008:1> public :a irb(main):009:1> end => T irb(main):010:0> t.a => 1 irb(main):011:0> /Robert Feldt