[rspec-devel] [ rspec-Feature Requests-5435 ] mock#and_return should support multiple return values from passed in arguments

noreply at rubyforge.org noreply at rubyforge.org
Sun Oct 22 15:24:51 EDT 2006


Feature Requests item #5435, was opened at 2006-08-16 01:53
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=5435&group_id=797

Category: None
Group: None
Status: Open
Priority: 3
Submitted By: Brian Takita (btakita)
Assigned to: Aslak Hellesoy (aslak_hellesoy)
Summary: mock#and_return should support multiple return values from passed in arguments

Initial Comment:
mock.and_return(1,2,3) should return the next passed in value each time the mock in invoked.

For example,

the_mock.should_receive(:foo).and_return(1, 2, 3)

the_mock.foo # returns 1
the_mock.foo # returns 2
the_mock.foo # returns 3



----------------------------------------------------------------------

>Comment By: Aslak Hellesoy (aslak_hellesoy)
Date: 2006-10-22 15:24

Message:
I thought I hadd attached the patch, but realise I hadn't and now I've lost the patch and the code :-(

If my memory serves me right I changed the signature of Spec::Mocks::BaseExpectation#and_return from

def and_return(value=nil, &return_block)

to

def and_return(*values, &return_block)

And of course the implementation...

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-09-07 08:48

Message:
Aslak - can you go ahead and make a new patch for this?

Thanks,
David

----------------------------------------------------------------------

Comment By: Aslak Hellesoy (aslak_hellesoy)
Date: 2006-08-20 22:13

Message:
Just to clarify - consecutive return values are already implemented. This is a semantic change so that instead of saying and_return([1, 2, 3]) we'll be saying and_return(1, 2, 3).

I'm attaching a patch that implements the requested feature. The patch also makes the mock derive the implicitly expected invocation count (the number of args to and_return) and barfs if it's inconsistent with an explicit count.

I haven't checked it into trunk because it's a substantial change that will break backwards compatibility, and I'd like others to look at it and comment first (and I was too lazy to make a branch).

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=5435&group_id=797


More information about the rspec-devel mailing list