Reputation:
I am trying to stub a method that returns multiple values. For example:
class Foo
def foo(a,b)
return a + 1, b + 2
end
end
I want to stub it but I'm having trouble with and_return with 2 value returns
f = Foo.new
f.stub!(:foo).and_return(3,56)
doesn't work. It basically returns 3 the first time it's called and 56 the second time. Does anyone know what the syntax would be to have it return 3,56 the first time it's called? Is this even possible with rspec?
thanks in advance... jd
Upvotes: 6
Views: 10262
Reputation: 160191
Multiple-value returns are arrays:
> def f; return 1, 2; end
> f.class
=> Array
So return an array:
f.stub!(:foo).and_return([3, 56])
Upvotes: 18