[rspec-users] How do you keep mocks updated without pain?
priit.tamboom at eesti.ee
Tue Aug 28 05:00:20 EDT 2007
I know you must be answering a lot of basic questions, sorry about that :-)
However I have not get it, how do you keep mocks updated without pain?
I reached to the point where mocking things for view. I spec
model-controller-view using "correct doc" way mocking-stubbing (plus I
should run integration test to be sure that everything really works
Now, when I want to change something in model then basically I have to
change mocks so many places, haven't I? It really feels a little too
messy for me as nuby rspecer. Or it's just my worry and you have to be
so good that you don't have to change things too much after specing
them? If so then I know that I should think much more when mocking(==
When I googled about this topic I have found similar worries out there
and I got two solutions, where David  suggest to write integration
tests (what should indicate that mocks are outdated) and Ryan 
suggest to fall bact to fixtures.
I feel I will fall back to fixtures, so no more designing fun with
mocks but things feels more lightweight and practical :-) Or perhaps
it's more up to project size and conditions... I don't know yet.
Priit at typical.nuby.reaction.to.mock.things
"Now the risk here is that you could build a model that doesn't have a
title field in it and your app will blow up! Admittedly, if you only
write isolated, granular specs like this that risk is real. So you
should be doing this in conjunction with integration testing."
"I took the past few hours and removed nearly all mocks from my specs.
I also merged the controller and view specs into one using
"integrate_views" in the controller spec. I am also loading all
fixtures for each controller spec so there's some test data to fill
The end result? My specs are shorter, simpler, more consistent, less
rigid, and they test the entire stack together (model, view,
controller) so no bugs can slip through the cracks.
I'm not saying this is the "right" way for everyone. If your project
requires a very strict spec case then it may not be for you, but in my
case this is worlds better than what I had before using mocks. I still
think stubbing is a good solution in a few spots so I'm still doing
More information about the rspec-users