forked from tomcz/pragprog-depot-prg
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing Cart with mocked out Products
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |