[rspec-users] Mocks and Refactoring - doing it wrong?

Matt Wynne matt at mattwynne.net
Thu Oct 30 06:26:11 EDT 2008

> I'd rather have it be a known problem, but a consistent problem, then
> a partially solved problem that will inevitably cause more pain that
> it does today :)


This is one of the down-sides of working in a dynamic language. We  
have to suck it up, IMO.

> Now, here's what I don't understand: suppose I refactor the Engine  
> class
> and rename the "ignite" method to "turn_on". If I re-run the example
> from above, the test is still green - but it shouldn't be, since the
> "ignite" method doesn't exist on the Engine class anymore.
> So I'm wondering...what am I doing wrong? I feel like my tests should
> help catch these sorts of things when I do a refactoring - my hunch is
> that I'm missing a step here.

I asked Steve Freeman (author of the original JMock) about this very  
question the other week. His reply was straightfowrard - "that's just  
crap testing!". In other words, as Scott said, if you're using mocks  
for your unit tests, you have to also use acceptance tests to prove  
that the whole stack integrates.

Thanks goodness for cucumber. I have already found it a massive  
blessing when refactoring.

More information about the rspec-users mailing list