master
 1require "spec_helper"
 2
 3describe Cart do
 4  let(:sut) { Cart.new }
 5
 6  let(:crayons) { fake  }
 7  let(:phone) { fake }
 8  let(:laptop) { fake }
 9
10  before :each do
11    crayons.stub(:price).and_return(Money.new(1.99))
12    phone.stub(:price).and_return(Money.new(199.99))
13    laptop.stub(:price).and_return(Money.new(1999.99))
14  end
15
16  context "when there are no items in the cart"  do
17    it "should indicate that no items are included" do
18      sut.includes?(crayons).should be_false
19    end
20
21    it "should indicate that there are no items in the cart" do
22      sut.total_items.should == 0
23    end
24
25    it "should calculate a total price of $0.00" do
26      sut.total_price.should == Money.new(0.00)
27    end
28  end
29
30  context "when there is a single item in the cart" do
31    before { sut.add(crayons) }
32
33    it "should increase the quanity of that product" do
34      sut.quantity_of(crayons).should == 1
35    end
36
37    it "should indicate the total number of unique items in the cart" do
38      sut.total_items.should == 1
39    end
40
41    it "should calculate a total price" do
42      sut.total_price.should == crayons.price
43    end
44  end
45
46  context "when there are multiples of a single product" do
47    before :each do
48      sut.add(crayons)
49      sut.add(crayons)
50    end
51
52    it "should indicate the total quanity of that product" do
53      sut.quantity_of(crayons).should == 2
54    end
55
56    it "should indicate the total number of items in the cart" do
57      sut.total_items.should == 2
58    end
59
60    it "should calculate the total price" do
61      sut.total_price.should == crayons.price + crayons.price
62    end
63  end
64
65  context "when there is multiple products" do
66    before :each do
67      sut.add(crayons)
68      sut.add(phone)
69      sut.add(laptop)
70    end
71
72    it "should indicate the total number of items in the cart" do
73      sut.total_items.should == 3
74    end
75
76    it "should calculate the total price" do
77      sut.total_price.should == crayons.price + phone.price + laptop.price
78    end
79  end
80
81end