diff options
| author | mo khan <mo@mokhan.ca> | 2013-04-29 17:01:17 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-04-29 17:01:17 -0600 |
| commit | 1d23b7699061e92364c55184eb078addb5fc06e7 (patch) | |
| tree | 9962ac18b102fa568805e31ed55d61ee8337f8d3 | |
| parent | c107fc3cf43d1c669f05cf843e8d457e8ac334f9 (diff) | |
start to calculate total amount of cart
| -rw-r--r-- | lib/cart.rb | 4 | ||||
| -rw-r--r-- | lib/money.rb | 11 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 1 | ||||
| -rw-r--r-- | spec/unit/cart_spec.rb | 18 | ||||
| -rw-r--r-- | spec/unit/money_spec.rb | 18 |
5 files changed, 46 insertions, 6 deletions
diff --git a/lib/cart.rb b/lib/cart.rb index 1bfe562..20cd3a5 100644 --- a/lib/cart.rb +++ b/lib/cart.rb @@ -20,4 +20,8 @@ class Cart def total_items @items.count end + + def total_cost + Money.new(0.00) + end end diff --git a/lib/money.rb b/lib/money.rb new file mode 100644 index 0000000..b8ae962 --- /dev/null +++ b/lib/money.rb @@ -0,0 +1,11 @@ +class Money + attr_reader :amount + + def initialize(amount) + @amount = amount + end + + def ==(other) + @amount == other.amount + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7742723..abc988c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,3 +3,4 @@ require 'rspec-fakes' require_relative '../lib/cart.rb' require_relative '../lib/customer.rb' +require_relative '../lib/money.rb' diff --git a/spec/unit/cart_spec.rb b/spec/unit/cart_spec.rb index c77ea34..c31f6d1 100644 --- a/spec/unit/cart_spec.rb +++ b/spec/unit/cart_spec.rb @@ -8,14 +8,20 @@ describe Cart do let(:laptop) { fake } context "when there are no items in the cart" do - let(:result) { sut.includes?(crayons) } + 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 return false" do - result.should be_false + it "should calculate a total cost of $0.00" do + sut.total_cost.should == Money.new(0.00) end end - context "when adding a product" do + context "when there is a single item in the cart" do before { sut.add(crayons) } it "should increase the quanity of that product" do @@ -27,7 +33,7 @@ describe Cart do end end - context "when adding more then one of the same product" do + context "when there are multiples of a single product" do before :each do sut.add(crayons) sut.add(crayons) @@ -42,7 +48,7 @@ describe Cart do end end - context "when adding different products" do + context "when there is multiple products" do before :each do sut.add(crayons) sut.add(phone) diff --git a/spec/unit/money_spec.rb b/spec/unit/money_spec.rb new file mode 100644 index 0000000..0120c60 --- /dev/null +++ b/spec/unit/money_spec.rb @@ -0,0 +1,18 @@ +require "spec_helper" + +describe Money do + context "when comparing money" do + context "when the amount is the same" do + it "should return true" do + Money.new(1.00).should == Money.new(1.00) + Money.new(10.00).should eq(Money.new(10.00)) + end + end + context "when the amount is different" do + it "should return false" do + Money.new(1.00).should_not == Money.new(10.00) + Money.new(10.00).should_not eq(Money.new(1.00)) + end + end + end +end |
