Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

testing Cart with mocked out Products

  • Loading branch information...
commit 533bb26657259103e3e8512098aab75d5b35ce3c 1 parent 03260d0
@tomcz tomcz authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 spec/models/cart_spec.rb
View
38 spec/models/cart_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe Cart do
+
+ context 'with unique products' do
+ before(:each) do
+ @book1 = mock_model(Product, :price => 1)
+ @book2 = mock_model(Product, :price => 2)
+ @cart = Cart.new
+ @cart.add_product @book1
+ @cart.add_product @book2
+ end
+ it 'should report two items in cart' do
+ @cart.items.size.should == 2
+ @cart.total_items.should == 2
+ end
+ it 'should sum prices of both items in cart' do
+ @cart.total_price.should == 3
+ end
+ end
+
+ context 'with duplicate product' do
+ before(:each) do
+ @book1 = mock_model(Product, :price => 2)
+ @cart = Cart.new
+ @cart.add_product @book1
+ @cart.add_product @book1
+ end
+ it 'should contain one item in cart but report two' do
+ @cart.items.size.should == 1
+ @cart.total_items.should == 2
+ end
+ it 'should report price x quantity for item in cart' do
+ @cart.total_price.should == 4
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.