[rspec-users] RSpec whines when I set the value of an object

Nick Hoffman nick at deadorange.com
Wed Nov 5 15:32:47 EST 2008

On 2008-11-05, at 15:23, Fernando Perez wrote:
> This throws the error: expected 50, got 0 (using .eql?)

This is because you told @cart to return 0 when #amount is called on it:
   @cart = mock_model(Order, :id => 1, :amount => 0, :tax => 0)

I think maybe you're confusing what the arguments to #mock_model do.  
They don't set attributes' values in the mock object. The first  
argument specifies which class is being mocked. In this case, Order.  
The other arguments tell the mock what value to return for a given  
method. So this:
   @cart = mock_model Order, :amount => 0
tells the mock object in @cart to respond to #amount , and return the  
value 0 (zero).

Does that make things a bit clearer? Cheers,

More information about the rspec-users mailing list