[rspec-users] specs on private methods
dchelimsky at gmail.com
Tue Jan 8 20:41:29 EST 2008
On Jan 8, 2008 1:25 PM, Matt Patterson <matt-lists at reprocessed.org> wrote:
> On 8 Jan 2008, at 19:14, Daniel Tenner 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.
> If you're a proponent of many-skinny-methods then you wind up with a
> lot of public methods which should never need to be called by another
> object, so making them private can be a good thing for general users
> of the object.
Keep in mind that if you're specifying object behaviour with the
prescribed granular red/green/refactor cycle, then the examples are
all against public methods. Private methods should only ever appear as
a result of refactoring. Those are the many-skinny that you are
> > 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).
> If the object were to implement it itself, that would be great ;-)
> Unfortunately, I have to implement the innards, and I'm rubbish so I
> like to test things...
You should check out the bowling kata
(http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata) if you
haven't. At the end there are just a few tests and they all touch only
2 public methods, but there are many, many smaller methods that appear
through refactoring. They are all thoroughly tested, though not
More information about the rspec-users