Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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