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 test for the following:
--
it "should display cart" do
@items = []
1.upto(2) do |i|
@items << mock_model(Item, :id => i, :price => 10 * i, :quantity
=> i, :order_id => 1)
end
Item.stub!(:find_for_payment).and_return(@items)
@cart = mock_model(Order, :id => 1, :amount => 0, :tax => 0)
Order.stub!(:find_cart).and_return(@cart)
Item.should_receive(:find_for_payment).with(1, 1).and_return(@items)
get :index
end
--
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), rspec still throws an
error message. What to do?
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users