[rspec-users] should_receive_chain

Justin Ko jko170 at gmail.com
Tue Feb 21 09:03:22 UTC 2012


Do you often find yourself doing this:

active = double('active')
active.should_receive(:first)
users = double('users', active: active)
account.should_receive(:users).and_return(users)

for this:

account.users.active.first

?

Of course, we could use stub_chain, but that doesn't let us know
*where* the chain broke.

Would you like to do this?

account.should_receive_chain(:users, :active, :first)

Under the hood, it would create something like this:

users = double('user')
active = double('active')
first = double('first')
users.should_receive(:active).and_return(active)
active.should_receive(:first).and_return(first)

Note, this would *not* be part of RSpec, but rather a separate gem.

Would this alleviate any pain for you?


More information about the rspec-users mailing list