[rspec-users] Testing with has_many associations

Chris Parsons chris at edendevelopment.co.uk
Wed Apr 9 09:25:15 EDT 2008


On 9 Apr 2008, at 12:22, Andy Croll wrote:

>  it "should increment quantity when it does find a product" do
>     
> @cart_item1 
> .should_receive(:increment_quantity).once.with(:no_args).and_return(2)
>    @cart.should_receive(:find_item_by_name).twice.with("Brown
> Trousers").and_return(nil, @cart_item1)
>    @cart.add_product(@product1)
>    @cart.add_product(@product1)
>    @cart.items.should have(1).item
>  end
> end
>
> Which seems to work. I'm right?

Looks good. Don't forget that with that extra mocking your coverage  
has dropped on CartItem so you'll need to ensure that it's correctly  
tested also.

Cheers
Chris


More information about the rspec-users mailing list