You should avoid testing private methods. The βgoalβ behind public / private / protected methods is to encapsulate logic and simplify changing parts of your code without worrying about how one function or class interacts with another.
If you still feel the need to test your personal methods, there are problems. I found this utility function through the Jay Field blog :
class Class
def publicize_methods
saved_private_instance_methods = self.private_instance_methods
self.class_eval { public *saved_private_instance_methods }
yield
self.class_eval { private *saved_private_instance_methods }
end
end
Check out the usage data link for a quick and easy way to do what you want to do.
source
share