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
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to