Commit 6de6101

mo khan <mo@mokhan.ca>
2013-04-29 23:05:50
start to calculate price of items in cart with a single item in the cart'
1 parent 1d23b76
Changed files (2)
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
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