From bcbb069ecd36720422fae17991244cc4c6afb4fb Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:07:10 -0500 Subject: [PATCH 01/11] Add a failed test to Topping.initialize --- spec/pizza_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 2f30c05..1c52464 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -1,4 +1,5 @@ -require './pizza' +require"rspec" +require_relative '../pizza' describe Pizza do it "exists" do @@ -10,4 +11,11 @@ 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 00122a4d9767b507b2b6631f4e3b4fd4348917c6 Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:15:04 -0500 Subject: [PATCH 02/11] Add a second failed test to Topping.initialize about vegetarian status --- pizza.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pizza.rb b/pizza.rb index 49ff37a..7db0add 100644 --- a/pizza.rb +++ b/pizza.rb @@ -2,4 +2,9 @@ class Pizza end class Topping + attr_accessor :name + + def initialize(name) + @name = name + end end From 06cf587aeb44c0c2b724d07b8cf6a6e6f2c85104 Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:20:36 -0500 Subject: [PATCH 03/11] passes vegetarian status test --- pizza.rb | 5 +++-- spec/pizza_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pizza.rb b/pizza.rb index 7db0add..f50096d 100644 --- a/pizza.rb +++ b/pizza.rb @@ -2,9 +2,10 @@ class Pizza end 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 1c52464..3c8bbc2 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -17,5 +17,10 @@ expect(topping.name).to eq('olives') end + it "sets whether or not the topping is vegetarian" do + topping = Topping.new("bell peppers", vegetarian: true) + + expect(topping.vegetarian).to eq(true) + end end end From 1b64a5e0ff62554ca291dd14591919606a37041d Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:26:55 -0500 Subject: [PATCH 04/11] added failing pizza toppings test --- spec/pizza_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 3c8bbc2..0c88455 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -5,6 +5,17 @@ it "exists" do expect(Pizza).to be_a(Class) end + describe '.initialize' do + it 'records 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 describe Topping do From a056bf9e9de03c0b7958c6147643203dc26ad0e3 Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:28:44 -0500 Subject: [PATCH 05/11] passes pizza topping test --- pizza.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pizza.rb b/pizza.rb index f50096d..18d89bd 100644 --- a/pizza.rb +++ b/pizza.rb @@ -1,4 +1,9 @@ class Pizza + attr_accessor :toppings + + def initialize(toppings) + @toppings = toppings + end end class Topping From b61075ec2abd80c5da3ac4bbbe12903ade1314fa Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:32:47 -0500 Subject: [PATCH 06/11] added fail test for if user doesnt add topping at beginning to default to cheese --- spec/pizza_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 0c88455..4df8568 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -15,6 +15,12 @@ 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 8dafc935c26c8861b45f69d830453458c42d89ad Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:40:32 -0500 Subject: [PATCH 07/11] passed final test --- pizza.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pizza.rb b/pizza.rb index 18d89bd..eb76b8f 100644 --- a/pizza.rb +++ b/pizza.rb @@ -1,7 +1,7 @@ class Pizza attr_accessor :toppings - def initialize(toppings) + def initialize(toppings=[Topping.new("cheese")]) @toppings = toppings end end From 8cabd27cad867afedb632e35f14e22330b4a2613 Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:46:31 -0500 Subject: [PATCH 08/11] used let in spec file --- spec/pizza_spec.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 4df8568..35d4ac0 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -5,16 +5,18 @@ it "exists" do expect(Pizza).to be_a(Class) end + describe '.initialize' do it 'records all of the toppings' do toppings = [ Topping.new("mushrooms", vegetarian: true), Topping.new("pepperoni") ] - pizza =Pizza.new(toppings) + pizza = Pizza.new(toppings) expect(pizza.toppings).to eq(toppings) end + it 'defaults the toppings to cheese only, if the pizza has no toppings' do pizza = Pizza.new @@ -28,16 +30,21 @@ it "exists" do expect(Topping).to be_a(Class) 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("bell peppers", vegetarian: true) } it "sets whether or not the topping is vegetarian" do - topping = Topping.new("bell peppers", vegetarian: true) + # topping = Topping.new("bell peppers", vegetarian: true) - expect(topping.vegetarian).to eq(true) + expect(vegetarian_topping.vegetarian).to eq(true) end end end From a6cb7398fd6c7f5306381d1dda0e0c062672e1be Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 14:56:46 -0500 Subject: [PATCH 09/11] checks to see if all toppings are vegetarian --- pizza.rb | 4 ++++ spec/pizza_spec.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pizza.rb b/pizza.rb index eb76b8f..197e9be 100644 --- a/pizza.rb +++ b/pizza.rb @@ -4,6 +4,10 @@ class Pizza def initialize(toppings=[Topping.new("cheese")]) @toppings = toppings end + + def vegetarian? + @toppings.all? {|x| x.vegetarian == true} + end end class Topping diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 35d4ac0..0fb2982 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -24,6 +24,19 @@ expect(pizza.toppings.first.name).to eq('cheese') end end + + decribe ".vegetarian?" do + let(:toppings){[ + Topping.new("mushrooms", vegetarian: true), + Topping.new("pepperoni") + ]} + let(:pizza){Pizza.new(toppings)} + it "checks to see that all the toppings are vegetarian" do + + expect(pizza.vegetarian?).to eq(false) + end + end + end describe Topping do From 1489871ec433cf474a242e2d3c658a57110f2eae Mon Sep 17 00:00:00 2001 From: Tony Fazio Date: Wed, 23 Apr 2014 15:08:32 -0500 Subject: [PATCH 10/11] passes add a topping method test --- pizza.rb | 6 +++++- spec/pizza_spec.rb | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pizza.rb b/pizza.rb index 197e9be..8a5ba7a 100644 --- a/pizza.rb +++ b/pizza.rb @@ -1,13 +1,17 @@ class Pizza attr_accessor :toppings - def initialize(toppings=[Topping.new("cheese")]) + def initialize(toppings=[Topping.new("cheese", vegetarian: true)]) @toppings = toppings end def vegetarian? @toppings.all? {|x| x.vegetarian == true} end + + def add_topping(new_topping) + @toppings< Date: Wed, 23 Apr 2014 15:11:27 -0500 Subject: [PATCH 11/11] added another add_topping test and it passes --- spec/pizza_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/pizza_spec.rb b/spec/pizza_spec.rb index 268edab..9f95390 100644 --- a/spec/pizza_spec.rb +++ b/spec/pizza_spec.rb @@ -47,6 +47,7 @@ new_topping = Topping.new("onions", vegetarian: true) pizza.add_topping(new_topping) + expect(pizza.toppings.last).to eq(new_topping) expect(pizza.toppings.count).to eq(3) end end