[rspec-devel] Mocking in the past tense

Jay Levitt lists-rspec at shopwatch.org
Thu Nov 16 20:16:05 EST 2006

Jay Levitt wrote:
> David Chelimsky wrote:
>> The idea of past-tense mocking has come up before. The problem is that
>> it only provides value in a very limited subset of potential uses.
> [...]
>> So, for me, I'd rather absorb the subtle dampness of the do_get method
>> and keep the specs clear.
> Good point - there's no way to post-specify what a mock should have 
> returned!

More musing: I find myself mocking the same object over and over again, 
and having to explicitly specify "should_receives" for helper routines 
that I don't actually care about.

What if a mock's behavior were specified independently of (and prior to) 
its expectations?

Then I could, in a single place, specify:

u = mock("User")

Later, for a given transaction, I might say:


I'd want to be able to override the returns, to test my error conditions:


If may_receive is a synonym for stubs, and if a mock can override a stub 
today, then this may even work already.  But I like the may_receive 
syntax, since I'm not really stubbing - I'm just building the framework 
for a mock.


More information about the rspec-devel mailing list