From 6de610122a4fe6f15d4b34fb15b47d3a2069ce88 Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 29 Apr 2013 17:05:50 -0600 Subject: start to calculate price of items in cart with a single item in the cart' --- lib/cart.rb | 5 +++-- spec/unit/cart_spec.rb | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/cart.rb b/lib/cart.rb index 20cd3a5..81d6971 100644 --- a/lib/cart.rb +++ b/lib/cart.rb @@ -21,7 +21,8 @@ class Cart @items.count end - def total_cost - Money.new(0.00) + def total_price + return Money.new(0.00) if @items.empty? + @items.first.price end end diff --git a/spec/unit/cart_spec.rb b/spec/unit/cart_spec.rb index c31f6d1..eb77a36 100644 --- a/spec/unit/cart_spec.rb +++ b/spec/unit/cart_spec.rb @@ -7,6 +7,12 @@ describe Cart do let(:phone) { fake } let(:laptop) { fake } + before :each do + crayons.stub(:price).and_return(Money.new(1.99)) + phone.stub(:price).and_return(Money.new(199.99)) + laptop.stub(:price).and_return(Money.new(1999.99)) + end + context "when there are no items in the cart" do it "should indicate that no items are included" do sut.includes?(crayons).should be_false @@ -16,8 +22,8 @@ describe Cart do sut.total_items.should == 0 end - it "should calculate a total cost of $0.00" do - sut.total_cost.should == Money.new(0.00) + it "should calculate a total price of $0.00" do + sut.total_price.should == Money.new(0.00) end end @@ -31,6 +37,10 @@ describe Cart do it "should indicate the total number of unique items in the cart" do sut.total_items.should == 1 end + + it "should calculate a total price of $0.00" do + sut.total_price.should == crayons.price + end end context "when there are multiples of a single product" do -- cgit v1.2.3