Testing Private Methods

Friday, March 09, 2007 by Nate Murray.  

This probably isn't news to most of you, but it might help someone. Sometimes you want to test private methods. If you want you can just set the method to be public from within a #class_eval. Then call it in your test. For example:

def test_private_method
  product = products(:first) # grab our fixture
  product.class.class_eval do
    public :some_private_method

  assert product.some_private_method

Labels: , ,

» Post a Comment

Who we are:
The Pasadena Ruby Brigade is a group of programmers who are interested in Ruby. We enjoy sharing our ideas and code with anyone who is interested in this wonderful programming language.

Who can join:
Anyone! Just head over to our mailing list and drop us an email.

What we do:
We recently started a project over at RubyForge. This project is a group of programs written and maintained by our members that we thought could be beneficial to the whole community.



Recent Posts