Commit 1d23b76
Changed files (5)
spec
lib/cart.rb
@@ -20,4 +20,8 @@ class Cart
def total_items
@items.count
end
+
+ def total_cost
+ Money.new(0.00)
+ end
end
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
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)
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
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'