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

2008-11-05 Thread Fernando Perez
> This expectation: >@cart.should_receive(:amount=).with(50) > is what you really want, because it's ensuring that Order#amount= is > being called with the correct value. > > So, just remove the "should eql(50)" expectation, and you're all set! > -Nick You are perfectly right Nick, I had just

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

2008-11-05 Thread Nick Hoffman
On 2008-11-05, at 15:23, Fernando Perez wrote: Hmmm, I don't have this problem as I am using ruby-forum.com to browse threads, it is x100 times more readable with basic color highlighting. I'll do my best to include quotes for people who use regular mail clients. So here is my controller code: -

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

2008-11-05 Thread Nick Hoffman
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 #m

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

2008-11-05 Thread Fernando Perez
> Please make sure, when you ask a question, that you quote enough of > the thread so that the readers can understand what you're asking. Hmmm, I don't have this problem as I am using ruby-forum.com to browse threads, it is x100 times more readable with basic color highlighting. I'll do my best t

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

2008-11-05 Thread David Chelimsky
On Wed, Nov 5, 2008 at 2:08 PM, Fernando Perez <[EMAIL PROTECTED]> wrote: >> @cart.should_receive(:amount=).with(50) >> >> amount and amount= are two different methods :) > > Thanks Dave! > > So now if I test for: @cart.amount.should eql(50) > > Why do I get this error: expected 50, got 0 (using .e

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

2008-11-05 Thread Nick Hoffman
On 2008-11-05, at 14:55, Fernando Perez wrote: And I get the following error message: -- Mock 'Order_1' received unexpected message :amount= with (50) -- Well I know that @cart.amount will be set to 50, but why is RSpec complaining about that? If I put @cart.should_receive(:amount).with(50), r

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

2008-11-05 Thread Fernando Perez
> @cart.should_receive(:amount=).with(50) > > amount and amount= are two different methods :) Thanks Dave! So now if I test for: @cart.amount.should eql(50) Why do I get this error: expected 50, got 0 (using .eql?) I have to add that the @cart is not saved in DB after its amount attribute is

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

2008-11-05 Thread David Chelimsky
On Wed, Nov 5, 2008 at 1:55 PM, Fernando Perez <[EMAIL PROTECTED]> wrote: > In have the following code: > > def index > @items = Item.find_for_payment(session[:order_id], @site.id) > @cart.amount = @items.sum { |item| item.price.to_i * > item.quantity.to_i } > end > > @cart is set by a before_fil

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

2008-11-05 Thread Fernando Perez
To make RSpec happy, I tried to test for the following: -- @cart.amount.should eql(50) -- And now I get: -- FAILED expected 50, got 0 (using .eql?) -- So is @cart.amount being set to 50 or not in the spec? When I test manually it works fine. -- Posted via http://www.ruby-forum.com/. __

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

2008-11-05 Thread Fernando Perez
In have the following code: def index @items = Item.find_for_payment(session[:order_id], @site.id) @cart.amount = @items.sum { |item| item.price.to_i * item.quantity.to_i } end @cart is set by a before_filter called find_cart which I stub. find_for_payment is stubbed too. In my spec I simply