[rspec-users] mocking successive return values
Doug Bryant
doug+rspecuser at netinlet.com
Wed Mar 5 13:36:44 EST 2008
Thanks Ben. I appreciate it.
Doug
On Wed, Mar 5, 2008 at 1:25 PM, Ben Mabey <ben at benmabey.com> wrote:
> Doug Bryant wrote:
> > I'm having a problems mocking successive return values. I don't know
> > if I'm doing something wrong or if this is a limitation of rspec
> > mocks. Any ideas of what I may be doing wrong?
> >
> >
> > For the test, I simply lookup 3 existing quote numbers, append nil to
> > the end (for a total of 4)
> > ## The test
> > it "should not generate a duplicate quote number" do
> > existing_quote_numbers = Policy.find(:all).map{|p|
> > p.quote_number}[0,3]
> >
> >
> @policy_service.should_receive(:random_string).with(:no_args).exactly(4).times.and_return(existing_quote_numbers.concat([nil]))
> > @policy_service.generate_quote_number
> > end
> >
>
> You will need to have one expectation per return. Try this:
>
> it "should not generate a duplicate quote number" do
> #expect
> Policy.find(:all).map{|p| p.quote_number}[0,3].concat([nil]).each do
> |existing_quote_number|
>
>
> @policy_service.should_receive(:random_string).with(:no_args).once.and_return(existing_quote_number))
> end
> #when
> @policy_service.generate_quote_number
> end
>
>
>
> -Ben
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/24144d0d/attachment.html
More information about the rspec-users
mailing list