Sławosz
Sławosz

Reputation: 11697

Long method and testing private methods - design problem

I have a quite long method. It copy an ActiveRecord object with all relations, and changes relations in some cases. To make code more readable, I use private methods. I would like to test them. Technicaly, in Ruby it is no problem, but I suspect, I have bad design. Do you have any advices how to deal with such case?

Upvotes: 1

Views: 115

Answers (1)

Lieven Keersmaekers
Lieven Keersmaekers

Reputation: 58491

One school of thought is that each and every private method that matters should be tested implicitly by testing a class's public interface. If a private method didn't get called through the public interface, it is redundant. If your private method is that complex to require its own tests, you should consider putting it in a class of its own and test that class.

In short, it shouldn't be necesary to explicitly test your private methods.

as the saying go's: "Don't touch your privates."

Upvotes: 4

Related Questions