[rspec-users] How to keep mocks consistent?

Coda Hale coda.hale at gmail.com
Mon Dec 18 17:28:45 EST 2006

Hey all,

Here's a question for everyone: how do you keep your mocks and stubs
consistent with your real objects?

I'm dipping my toes into the RSpec world, and it's absolutely
delightful (running dozens of tests in less than a second is nice as
well), but I'm concerned about my ability to keep the mocks in my
specs consistent with the behavior of their real-world equivalents.

I'm writing specs for a controller in a Rails application, and I've
got stuff like this:


If I change ComplicatedObject.execute down the line to return
something besides a float, this spec will still pass, and the
controller will only fail in real life. So I could have full test
coverage, green lights across the board, and massive amounts of bugs
in the way my classes interact.

Is there any mechanism in RSpec to keep this from happening? Any
methodology beyond "be careful"? Should I even be mocking my own

How do you manage this?

Coda Hale

More information about the rspec-users mailing list