On Mon, Feb 11, 2013 at 2:55 PM, clay s <[email protected]> wrote:

> Why does RSpec allow you set a return value on a mocked method? If the
> method returns a value, then the dependent code will already have testable
> behavioral differences based on the return value, making the mocking
> superfluous.


We use mocks to specify that an interaction is supposed to happen: I expect
x to receive the message foo. When you express this in rspec, or pretty
much any other mocking tool, when x receives foo it will return nil by
default. If another part of the code requires a return value from x.foo in
order to continue working, you have to tell x to return a reasonable value
when it receives foo. Hence:

x.should_receive(:foo).and_return(:a_reasonable_value)

If you don't care about specifying that x receives foo, then sure, you can
just use a stub. But it really depends on what you're trying to express.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to