[rspec-users] #stub! and #should_receive on the same method

David Chelimsky dchelimsky at gmail.com
Thu Sep 25 14:09:30 EDT 2008

On Thu, Sep 25, 2008 at 1:04 PM, Nick Hoffman <nick at deadorange.com> wrote:
> On 2008-09-25, at 13:58, Tero Tilus wrote:
>> 2008-09-25 13:47, Nick Hoffman:
>>> I'm calling #stub! and #should_receive on the same method within a
>>> class, and am finding that the method doesn't return the value given
>>> to #stub!
>> How about GMarker.should_receive(:new).with(foo).and_return mock_marker
> I knew there was a dead simple answer to the question. Thanks, Tero.

That should work too, but recent changes support returning a
previously defined stub value when you don't specify a return value in
a mock expectation:

  foo = mock('foo')
  foo.stub!(:bar).and_return('stub value')
  => 'stub value'

> Apologies for the brain fart.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list