From 87dcc727067d27f8af4d5570ea4aa0718efb519e Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:07:07 -0500 Subject: [PATCH 01/16] Add a failing test for Topping.initialize. --- spec/pizza_spec.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 2f30c05..89814ba 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -7,7 +7,16 @@ end describe Topping do - it "exists" do - expect(Topping).to be_a(Class) - end + + it "exists" do + expect(Topping).to be_a(Class) + end + + describe '.initialize' do + it "sets the name of the topping" do + topping = Topping.new('olives') + + expect(topping.name).to eq('olives') + end + end end From 2bdcc900be38b48b0ae285ec681805f2bd22467c Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:09:06 -0500 Subject: [PATCH 02/16] Add initialize method to Topping class. --- pizza.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pizza.rb b/pizza.rb index 49ff37a..e48ad48 100644 --- a/pizza.rb +++ b/pizza.rb @@ -2,4 +2,11 @@ class Pizza end class Topping + + attr_accessor :name + + def initialize(name) + @name = name + end + end From 54e78a0ee292ba58375029b672c2acecb50b10df Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:17:18 -0500 Subject: [PATCH 03/16] Add failing test for Topping vegeterian option --- spec/pizza_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 89814ba..0193f45 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -18,5 +18,11 @@ expect(topping.name).to eq('olives') end + + it "sets wether or not the topping is vegetarian" do + let(:topping) { Topping.new 'bell peppers', vegetarian: true } + + expect(topping.vegetarian).to eq(true) + end end end From 0c426cfb79a4c0227c7b98a77e8e53f15b7b74d3 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:23:32 -0500 Subject: [PATCH 04/16] Update method Topping initialize method to theck if vegetarian option is true --- pizza.rb | 5 +++-- spec/pizza_spec.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pizza.rb b/pizza.rb index e48ad48..a1f036e 100644 --- a/pizza.rb +++ b/pizza.rb @@ -3,10 +3,11 @@ class Pizza class Topping - attr_accessor :name + attr_accessor :name, :vegetarian - def initialize(name) + def initialize(name, vegetarian: false) @name = name + @vegetarian = vegetarian end end diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 0193f45..a8c0db7 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -20,7 +20,7 @@ end it "sets wether or not the topping is vegetarian" do - let(:topping) { Topping.new 'bell peppers', vegetarian: true } + topping = Topping.new 'olives', vegetarian: true expect(topping.vegetarian).to eq(true) end From 1de97e899dfe6bc479e36e4c7c1f4973655856ed Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:25:57 -0500 Subject: [PATCH 05/16] Add failing test for Pizza initialize --- pizza.rb | 2 ++ spec/pizza_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pizza.rb b/pizza.rb index a1f036e..83fddc1 100644 --- a/pizza.rb +++ b/pizza.rb @@ -11,3 +11,5 @@ def initialize(name, vegetarian: false) end end + + diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index a8c0db7..7a92f80 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -26,3 +26,21 @@ end end end + +describe Pizza do + + describe '.initialize' do + + it 'recoreds all of the toppings' do + toppings = [ + Topping.new('mushrooms', vegetarian: true), + Topping.new('pepperoni') + ] + + pizza = Pizza.new(toppings) + + expect(pizza.toppings).to eq(toppings) + + end + end +end From 71e427e70d16fdccf3398b6a9fe39bb42a75fe67 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:27:32 -0500 Subject: [PATCH 06/16] Add initialize method to Pizza class --- pizza.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pizza.rb b/pizza.rb index 83fddc1..f8d21a3 100644 --- a/pizza.rb +++ b/pizza.rb @@ -1,4 +1,11 @@ class Pizza + + attr_accessor :toppings + + def initialize(toppings) + @toppings = toppings + end + end class Topping From bdc91a094095c3c8caec939aa02e94f7e481e69c Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:30:34 -0500 Subject: [PATCH 07/16] Update Pizza initialize method to default a cheese topping --- pizza.rb | 2 +- spec/pizza_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pizza.rb b/pizza.rb index f8d21a3..42bcb1b 100644 --- a/pizza.rb +++ b/pizza.rb @@ -2,7 +2,7 @@ class Pizza attr_accessor :toppings - def initialize(toppings) + def initialize(toppings = [Topping.new('cheese', vegetarian: true)]) @toppings = toppings end diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 7a92f80..d4f255f 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -42,5 +42,14 @@ expect(pizza.toppings).to eq(toppings) end + + it 'defaults the toppings to cheese only, if the pizza has no toppings' do + pizza = Pizza.new + + expect(pizza.toppings.size).to eq(1) + expect(pizza.toppings.first.name).to eq('cheese') + + end + end end From d041c27fc07152053af5022915b19b4111ad5d87 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:49:29 -0500 Subject: [PATCH 08/16] Add failing test for vegeterian? method --- spec/pizza_spec.rb | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index d4f255f..d136dce 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -13,16 +13,18 @@ end describe '.initialize' do + let(:topping) { Topping.new('olives') } it "sets the name of the topping" do - topping = Topping.new('olives') + # topping = Topping.new('olives') expect(topping.name).to eq('olives') end + let(:vegetarian_topping) { Topping.new 'olives', vegetarian: true } it "sets wether or not the topping is vegetarian" do - topping = Topping.new 'olives', vegetarian: true + # topping = Topping.new 'olives', vegetarian: true - expect(topping.vegetarian).to eq(true) + expect(vegetarian_topping.vegetarian).to eq(true) end end end @@ -52,4 +54,36 @@ end end + + describe "vegetarian?" do + + context 'when there are all non vegeterian toppings' do + + let(:vegeterian_toppings) {[ + Topping.new('mushrooms', vegeterian: true), + Topping.new('olives', vegeterian: true) + ]} + + let(:vegeterian_pizza) {Pizza.new(vegeterian_toppings)} + + it 'returns true' do + expect(vegeterian_pizza.vegeterian?).to eq(true) + end + end + + context 'when there is a non vegeterian topping' do + + let(:non_vegetarian_toppings) {[ + Topping.new('pepperoni'), + Topping.new('mushrooms', vegetarian: true), + Topping.new('bell peppers', vegetarian: true ) + ]} + + let(:non_vegetarian_pizza) { Pizza.new(non_vegetarian_toppings)} + + it 'returns false' do + expect(non_vegetarian_pizza.vegetarian?).to eq(false) + end + end + end end From c7daee210935e5209fd54cdbd7c1be2d85cba0a9 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:53:17 -0500 Subject: [PATCH 09/16] Add vegetarian? method --- pizza.rb | 4 ++++ spec/pizza_spec.rb | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pizza.rb b/pizza.rb index 42bcb1b..683d1ff 100644 --- a/pizza.rb +++ b/pizza.rb @@ -6,6 +6,10 @@ def initialize(toppings = [Topping.new('cheese', vegetarian: true)]) @toppings = toppings end + def vegetarian? + toppings.all? {|topping| topping.vegetarian == true} + end + end class Topping diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index d136dce..5cd8213 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -60,14 +60,14 @@ context 'when there are all non vegeterian toppings' do let(:vegeterian_toppings) {[ - Topping.new('mushrooms', vegeterian: true), - Topping.new('olives', vegeterian: true) + Topping.new('mushrooms', vegetarian: true), + Topping.new('olives', vegetarian: true) ]} let(:vegeterian_pizza) {Pizza.new(vegeterian_toppings)} it 'returns true' do - expect(vegeterian_pizza.vegeterian?).to eq(true) + expect(vegeterian_pizza.vegetarian?).to eq(true) end end From fd2924f0817d68f70b3f47b9f5df867e3413c503 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:58:13 -0500 Subject: [PATCH 10/16] Add failing test for add_topping method --- spec/pizza_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 5cd8213..d97900b 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -86,4 +86,25 @@ end end end + + describe "add_topping" do + + context 'when a new topping is added' do + + let(:toppings) {[ + Topping.new('mushrooms', vegetarian: true), + Topping.new('olives', vegetarian: true) + ]} + + let(:topping) {Topping.new('pepperoni')} + + let(:pizza) {Pizza.new(toppings)} + + it 'should increase toppings count' do + pizza.add_topping(topping) + + expect(pizza.toppings.count).to eq(3) + end + end + end end From c274d12233033980176f6238ec28e74e46579920 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 14:59:55 -0500 Subject: [PATCH 11/16] Add method add_topping --- pizza.rb | 4 ++++ spec/pizza_spec.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/pizza.rb b/pizza.rb index 683d1ff..dc86fb6 100644 --- a/pizza.rb +++ b/pizza.rb @@ -10,6 +10,10 @@ def vegetarian? toppings.all? {|topping| topping.vegetarian == true} end + def add_topping(*new_toppings) + new_toppings.each {|topping| @toppings << topping} + end + end class Topping diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index d97900b..87f9c46 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -106,5 +106,6 @@ expect(pizza.toppings.count).to eq(3) end end + end end From 878f4797e71c3187584784627d50762b99500162 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 15:46:21 -0500 Subject: [PATCH 12/16] Update add toppings test to verify multipel toppings can pass --- pizza.rb | 2 +- spec/pizza_spec.rb | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pizza.rb b/pizza.rb index dc86fb6..c9f9331 100644 --- a/pizza.rb +++ b/pizza.rb @@ -10,7 +10,7 @@ def vegetarian? toppings.all? {|topping| topping.vegetarian == true} end - def add_topping(*new_toppings) + def add_topping(new_toppings) new_toppings.each {|topping| @toppings << topping} end diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 87f9c46..f3e1b3c 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -93,19 +93,35 @@ let(:toppings) {[ Topping.new('mushrooms', vegetarian: true), - Topping.new('olives', vegetarian: true) ]} - let(:topping) {Topping.new('pepperoni')} + let(:topping) {[Topping.new('pepperoni')]} let(:pizza) {Pizza.new(toppings)} it 'should increase toppings count' do pizza.add_topping(topping) - expect(pizza.toppings.count).to eq(3) + expect(pizza.toppings.count).to eq(2) end end + context 'when multiple toppings are added' do + + let(:new_toppings) {[ + Topping.new('mushrooms', vegetarian: true), + Topping.new('pepperoni') + ]} + + let(:new_topping) {[Topping.new('bacon')]} + + let(:new_pizza) {Pizza.new(new_topping)} + + it 'increases toppings count' do + new_pizza.add_topping(new_toppings) + + expect(new_pizza.toppings.count).to eq(3) + end + end end end From f2cdde1d6badc016cfaa14659187cb43983c68a0 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 15:51:38 -0500 Subject: [PATCH 13/16] Add faling test for delivery method --- spec/pizza_spec.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index f3e1b3c..a0b6d18 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -99,7 +99,7 @@ let(:pizza) {Pizza.new(toppings)} - it 'should increase toppings count' do + it 'increases toppings count by 1' do pizza.add_topping(topping) expect(pizza.toppings.count).to eq(2) @@ -117,11 +117,23 @@ let(:new_pizza) {Pizza.new(new_topping)} - it 'increases toppings count' do + it 'increases toppings count by count of toppings passed' do new_pizza.add_topping(new_toppings) expect(new_pizza.toppings.count).to eq(3) end end end + + describe "deliver!" do + + context 'when a new delivery is called' do + + let(:pizza) {Pizza.new} + + it 'creates a delivery time' do + expect(pizza.delivery_time).to not_be(nil) + end + end + end end From 022074856a8a598a1726a2d611011add8b722d57 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 15:54:54 -0500 Subject: [PATCH 14/16] git add deliver! method --- pizza.rb | 6 +++++- spec/pizza_spec.rb | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pizza.rb b/pizza.rb index c9f9331..630376c 100644 --- a/pizza.rb +++ b/pizza.rb @@ -1,6 +1,6 @@ class Pizza - attr_accessor :toppings + attr_accessor :toppings, :delivery_time def initialize(toppings = [Topping.new('cheese', vegetarian: true)]) @toppings = toppings @@ -14,6 +14,10 @@ def add_topping(new_toppings) new_toppings.each {|topping| @toppings << topping} end + def deliver! + @delivery_time = Time.now + (30 * 60) + end + end class Topping diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index a0b6d18..f31cd5b 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -132,7 +132,9 @@ let(:pizza) {Pizza.new} it 'creates a delivery time' do - expect(pizza.delivery_time).to not_be(nil) + pizza.deliver! + + expect(pizza.delivery_time).should_not be(nil) end end end From 9874a777429b54736eb071208731c6e1011d42a3 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 16:05:10 -0500 Subject: [PATCH 15/16] Add failing test for late? method --- pizza.rb | 4 ++-- spec/pizza_spec.rb | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pizza.rb b/pizza.rb index 630376c..54df631 100644 --- a/pizza.rb +++ b/pizza.rb @@ -14,8 +14,8 @@ def add_topping(new_toppings) new_toppings.each {|topping| @toppings << topping} end - def deliver! - @delivery_time = Time.now + (30 * 60) + def deliver!(now) + @delivery_time = now end end diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index f31cd5b..e19cd95 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -130,11 +130,28 @@ context 'when a new delivery is called' do let(:pizza) {Pizza.new} + let(:time) {Time.now + 30 * 60} it 'creates a delivery time' do - pizza.deliver! + pizza.deliver!(time) - expect(pizza.delivery_time).should_not be(nil) + expect(pizza.delivery_time).to eql(time) + end + end + end + + describe "late?" do + + context 'when a delivery is late' do + + let(:pizza) { Pizza.new } + let(:time) { Time.now + 30 * 60 } + let(:future_time) { Time.now + 30 * 70 } + + it 'returns true' do + pizza.deliver!(time) + + expect(pizza.late?(now)).to eq(true) end end end From 54d84fa325304b6a944732e2051a65d978108ab9 Mon Sep 17 00:00:00 2001 From: Canaan Davis Date: Wed, 23 Apr 2014 16:07:29 -0500 Subject: [PATCH 16/16] Add late? method --- pizza.rb | 4 ++++ spec/pizza_spec.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pizza.rb b/pizza.rb index 54df631..89ec590 100644 --- a/pizza.rb +++ b/pizza.rb @@ -18,6 +18,10 @@ def deliver!(now) @delivery_time = now end + def late?(now) + return true if now > @delivery_time + end + end class Topping diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index e19cd95..ae50c96 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -151,7 +151,7 @@ it 'returns true' do pizza.deliver!(time) - expect(pizza.late?(now)).to eq(true) + expect(pizza.late?(future_time)).to eq(true) end end end