[rspec-users] specs on private methods
richard.conroy at gmail.com
Wed Jan 9 08:26:50 EST 2008
On Jan 8, 2008 7:14 PM, Daniel Tenner <daniel.ruby at tenner.org> wrote:
> Might be a personal thing, but my approach is that I try to test the
> public behaviour of the object. Testing private methods is, imho,
> getting dangerously close to specifying how the object does its
> business, rather than what it does.
> I would just spec the externally visible behaviour, where it occurs,
> and let the object implement it as it wants (using private methods or
> any other mechanism).
The trouble is that this makes it very difficult to get effective coverage.
There is usually a lot more setup involved. If your tests are more expensive
to write, because you are unit testing indirectly through public methods,
less testing will get done, and worse tests can end up getting very brittle.
I do like the idea though of during the unit test itself, you unseal the method.
You get the best of both worlds.
More information about the rspec-users