How to spec a private method

I always take this approach: I want to test the public API my class exposes.

If you have private methods, you only call them from the public methods you expose to other classes. Hence, if you test that those public methods work as expected under all conditions, you have also proven that the private methods they use work as well.

I’ll admit that I’ve come across some especially complex private methods. In that extreme case you want to test them, you can do this:

@obj.send(:private_method)

Leave a Comment