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

My takeaway challenge #2232

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
34 changes: 34 additions & 0 deletions lib/takeaway-challenge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Takeaway

attr_reader :menu
attr_reader :customer_order


def initialize
@menu = [{dish_name: "1. lasagne", price: 8.90 },
{dish_name: "2. Jerk box", price: 12.90 } ,
{dish_name: "3. Paella", price: 11.00 },
{dish_name: "4. Seared Tuna rolls", price: 7.90 } ]
@customer_order = []
@total_bill = 0
end

def see_menu
puts @menu
end

def place_order(order_num)
puts "Please select your order number."
index = order_num - 1
order = @menu[index]
@customer_order << order
p @customer_order
end

def bill
@customer_order.each do | item_ordered |
@total_bill += item_ordered[:price]
return @total_bill
end
end
end
29 changes: 29 additions & 0 deletions spec/takeaway-challenge_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'takeaway-challenge'

describe Takeaway do
it { is_expected.to be_kind_of(Takeaway) }

describe 'Ordering' do
it 'allows a customer to see the menu' do
expect(subject.see_menu).to eq(@menu)
end

it 'allows a customer to add items from the menu to their order' do
expect(subject.place_order(1)).to include (subject.customer_order[0])
end
end

context 'places an order' do
before(:each) {subject.place_order(1)}

describe 'order confirmation' do
it 'Calculates the correct customers bill' do
expect(subject.bill).to eq(subject.menu[0][:price])
end
end
end
end

# As a customer
# So that I am reassured that my order will be delivered on time
# I would like to receive a text such as "Thank you! Your order was placed and will be delivered before 18:52" after I have ordered