Forum: RSpec [RSpec] Error when returning multiple values from a stub

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (nickh)
on 2009-01-27 17:12
(Received via mailing list)
Hey guys. I've just found some odd behaviour within RSpec 1.1.12 , and
would like to know whether this is a bug, or I'm doing something wrong.

When I give multiple return values to a stub, like this:
   SubtitleFile.stub!(:new).and_return @sf1, @sf2
RSpec complains:
   Mock 'SubtitleFile_1001' received unexpected message :size with (no
args)

However, if I break that into two stubs, like this:
   SubtitleFile.stub!(:new).and_return @sf1
   SubtitleFile.stub!(:new).and_return @sf2
the spec passes.

I've posted a more concrete example here:
http://gist.github.com/53389

In code pane #2, if I comment line 13 and uncomment lines 14 and 15,
the spec passes.

Any idea what's going on? Thanks for your help,
Nick
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (nickh)
on 2009-01-27 17:15
(Received via mailing list)
On 27/01/2009, at 11:03 AM, Nick Hoffman wrote:
> However, if I break that into two stubs, like this:
> Any idea what's going on? Thanks for your help,
> Nick

I just realised that breaking
   SubtitleFile.stub!(:new).and_return @sf1, @sf2
into two stubs causes the second call to #stub! to override the first,
which obviously causes problems, and thus doesn't provide an interim
solution.

-Nick
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (nickh)
on 2009-01-28 19:32
(Received via mailing list)
On 27/01/2009, at 11:03 AM, Nick Hoffman wrote:
> However, if I break that into two stubs, like this:
> Any idea what's going on? Thanks for your help,
> Nick

I've managed to cut even more code from the controller and specs while
continuing to reproduce the problem:
http://gist.github.com/53389

If I change this line:
   SubtitleFile.stub!(:new).and_return @sf1, @sf2
to this:
   SubtitleFile.stub!(:new).and_return @sf1
then the problem disappears.

Why does providing a second argument to #and_return cause #size to be
called on the "@sf1" mock?

Thanks in advance for any help with this, guys.
Nick
This topic is locked and can not be replied to.