[rspec-devel] Mocking in the past tense

David Chelimsky dchelimsky at gmail.com
Sun Nov 19 23:19:12 EST 2006

On 11/16/06, Jay Levitt <lists-rspec at shopwatch.org> wrote:
> 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")
> u.may_receive(:get).and_return(users(:sample))
> u.may_receive(:save).and_return(true)
> Later, for a given transaction, I might say:
> u.should_receive(:get).at_least(:once)
> I'd want to be able to override the returns, to test my error conditions:
> u.should_receive(:save).and_return(false)
> If may_receive is a synonym for stubs, and if a mock can override a stub
> today, then this may even work already.

It does. Check out

> But I like the may_receive
> syntax, since I'm not really stubbing - I'm just building the framework
> for a mock.

I think that depends on what your view of a stub is. To me, it's the
same as what you're describing as may_receive. Read the blog and let
me know what you think?

> Jay
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel

More information about the rspec-devel mailing list