Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zachary Spector #6

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
19 changes: 19 additions & 0 deletions pizza.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
class Pizza
attr_accessor :toppings

def initialize(toppings=[Topping.new('cheese', vegetarian: true)])
@toppings = toppings
end

def vegetarian?
@toppings.all? { |topping| topping.vegetarian }
end

def add_topping(topping)
@toppings << topping
end
end

class Topping
attr_accessor :name, :vegetarian

def initialize(name, vegetarian: false)
@name = name
@vegetarian = vegetarian
end
end
70 changes: 70 additions & 0 deletions spec/pizza_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,83 @@
require './pizza'
#require 'pry-debugger'

describe Pizza do
it "exists" do
expect(Pizza).to be_a(Class)
end

describe '.initialize' do
let(:toppings) {[
Topping.new('mushrooms', vegetarian: true),
Topping.new('pepperoni')
]}
let(:pizza1) { Pizza.new(toppings) }

let(:pizza2) { Pizza.new }

it 'records all of the toppings' do

expect(pizza1.toppings).to eq(toppings)
end
it 'defaults the toppings to cheese only, if the pizza has no toppings' do

expect(pizza2.toppings.size).to eq(1)
expect(pizza2.toppings.first.name).to eq('cheese')
end
end

describe '.vegetarian?' do
let(:toppings) {[
Topping.new('bell peppers', vegetarian: true),
Topping.new('pepperoni')
]}
let(:pizza1) { Pizza.new(toppings) }
let(:pizza2) { Pizza.new }

it 'checks if a pizza is vegetarian' do

expect(pizza1.vegetarian?).to eq(false)
expect(pizza2.vegetarian?).to eq(true)
end
end

describe '.add_topping' do
let(:topping) {[
Topping.new('bell peppers', vegetarian: true),
Topping.new('pepperoni')
]}

let(:pizza) {Pizza.new(topping)}

it 'adds topping to existing pizza' do

#Adds another pizza topping
pizza.add_topping(Topping.new('mushrooms', vegetarian: true))

expect(pizza.toppings.size).to eq(3)
expect(pizza.toppings.last.name).to eq('mushrooms')
end
end
end

describe Topping do
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

expect(topping.name).to eq('olives')
end

let(:topping1) { Topping.new('bell peppers', vegetarian: true) }
let(:topping2) { Topping.new('pepperoni') }

it "sets whether or not the topping is vegetarian" do

expect(topping1.vegetarian).to eq(true)
expect(topping2.vegetarian).to eq(false)
end
end
end