summaryrefslogtreecommitdiff
path: root/spec/unit/cart_spec.rb
blob: 34590480e023eaef67a98694667f9301a4f2d1bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require "spec_helper"

describe Cart do
  let(:sut) { Cart.new }

  let(:crayons) { fake  }
  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
    end

    it "should indicate that there are no items in the cart" do
      sut.total_items.should == 0
    end

    it "should calculate a total price of $0.00" do
      sut.total_price.should == Money.new(0.00)
    end
  end

  context "when there is a single item in the cart" do
    before { sut.add(crayons) }

    it "should increase the quanity of that product" do
      sut.quantity_of(crayons).should == 1
    end

    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" do
      sut.total_price.should == crayons.price
    end
  end

  context "when there are multiples of a single product" do
    before :each do
      sut.add(crayons)
      sut.add(crayons)
    end

    it "should indicate the total quanity of that product" do
      sut.quantity_of(crayons).should == 2
    end

    it "should indicate the total number of items in the cart" do
      sut.total_items.should == 2
    end

    it "should calculate the total price" do
      sut.total_price.should == crayons.price + crayons.price
    end
  end

  context "when there is multiple products" do
    before :each do
      sut.add(crayons)
      sut.add(phone)
      sut.add(laptop)
    end

    it "should indicate the total number of items in the cart" do
      sut.total_items.should == 3
    end

    it "should calculate the total price" do
      sut.total_price.should == crayons.price + phone.price + laptop.price
    end
  end

end