summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-04-29 16:41:26 -0600
committermo khan <mo@mokhan.ca>2013-04-29 16:41:26 -0600
commita20e73ab895f3ea7aef2e19671dbc85a546cb2ed (patch)
tree3095545820aaeb88e8b8a793c9ec0ef7664ada70
parentb74e8632e8defe3015332bff064285bf3e0b970f (diff)
start to build cart
-rw-r--r--spec/unit/cart_spec.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/unit/cart_spec.rb b/spec/unit/cart_spec.rb
new file mode 100644
index 0000000..80809f6
--- /dev/null
+++ b/spec/unit/cart_spec.rb
@@ -0,0 +1,60 @@
+require "spec_helper"
+
+class Cart
+ def initialize(items = [])
+ @items = items
+ end
+
+ def add(product)
+ @items.push(product)
+ end
+
+ def includes?(product)
+ @items.include?(product)
+ end
+
+ def quantity_of(product)
+ @items.find_all do |item|
+ item == product
+ end.count
+ end
+end
+
+describe Cart do
+ let(:sut) { Cart.new }
+
+ context "when there are no items in the cart" do
+ let(:product) { fake }
+ let(:result) { sut.includes?(product) }
+
+ it "should return false" do
+ result.should be_false
+ end
+ end
+
+ context "when adding a product" do
+ let(:product) { fake }
+
+ let(:result) do
+ sut.add(product)
+ sut.quantity_of(product)
+ end
+
+ it "should increase the quanity of that product" do
+ result.should == 1
+ end
+ end
+
+ context "when adding more then one of the same product" do
+ let(:product) { fake }
+
+ let(:result) do
+ sut.add(product)
+ sut.add(product)
+ sut.quantity_of(product)
+ end
+ it "should indicate the total quanity of that product" do
+ result.should == 2
+ end
+ end
+end