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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
My first challenge submission. I couldn't get an account and phone number working with Twilio so this aspect of the challenge hasn't been implemented at all. This is a basic series of tests on basic code. I'm hoping to learn from it.

Nothing is needed to run it. There is no front-end app.

I'm also very aware that I didn't commit enough. I was concentrating hard on the problem of the Ruby code so this is an omission, I know.

Thanks.




Takeaway Challenge
==================
```
Expand Down
13 changes: 13 additions & 0 deletions lib/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Menu
def initialize
menu = [
{ "Pizza" => 7 },
{ "Fish and Chips" => 9 },
{ "Pancakes with Bacon and Maple Syrup" => 6 },
{ "Vegetable Stir Fry with Gyoza" => 8 },
{ "Cheese and Pickle Sandwich" => 4 },
{ "Ramen" => 6 },
{ "Beef Pho" => 9 }
]
end
end
23 changes: 23 additions & 0 deletions lib/order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Order
def initialize
@order = []
@notified = false
end

def add(item)
@order << item
end

def order_complete
return @order
end

def order_total
order_total = 0
@order.each do |food|
order_total += food.values.reduce
end

return "Your order was received and its total is #{order_total}!"
end
end
65 changes: 65 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'menu'
require 'order'

def menu
menu = [
{ "Pizza" => 7 },
{ "Fish and Chips" => 9 },
{ "Pancakes with Bacon and Maple Syrup" => 6 },
{ "Vegetable Stir Fry with Gyoza" => 8 },
{ "Cheese and Pickle Sandwich" => 4 },
{ "Ramen" => 6 },
{ "Beef Pho" => 9 }
]
end

RSpec.describe 'integration' do
it "returns the menu" do
expect(menu).to eq ([
{ "Pizza" => 7 },
{ "Fish and Chips" => 9 },
{ "Pancakes with Bacon and Maple Syrup" => 6 },
{ "Vegetable Stir Fry with Gyoza" => 8 },
{ "Cheese and Pickle Sandwich" => 4 },
{ "Ramen" => 6 },
{ "Beef Pho" => 9 }
])
end

it "initially has empty order" do
order = Order.new
expect(order.order_complete).to eq ([])
end

it "can have an item added to it" do
order = Order.new
item = menu[0]
order.add(item)
expect(order.order_complete).to eq ([{ "Pizza" => 7 }])
end

it "can have more than one item added to it" do
order = Order.new
item1 = menu[0]
item2 = menu[1]
order.add(item1)
order.add(item2)
expect(order.order_complete).to eq ([{ "Pizza" => 7 }, { "Fish and Chips" => 9 }])
end

it "can return the total of an ordered item" do
order = Order.new
item = menu[0]
order.add(item)
expect(order.order_total).to eq "Your order was received and its total is 7!"
end

it "can return the total when more than one item added" do
order = Order.new
item1 = menu[0]
item2 = menu[1]
order.add(item1)
order.add(item2)
expect(order.order_total).to eq "Your order was received and its total is 16!"
end
end
24 changes: 24 additions & 0 deletions spec/menu_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'menu'

def menu
menu = [
{ "Pizza" => 7 },
{ "Fish and Chips" => 9 },
{ "Pancakes with Bacon and Maple Syrup" => 6 },
{ "Vegetable Stir Fry with Gyoza" => 8 },
{ "Cheese and Pickle Sandwich" => 4 },
{ "Ramen" => 6 },
{ "Beef Pho" => 9 }
]
end

RSpec.describe 'menu' do
it "returns the menu" do
expect(menu).to eq (menu)
end

it "returns one item from the menu" do
menu_item = menu[0]
expect(menu_item).to eq ({ "Pizza" => 7 })
end
end
37 changes: 37 additions & 0 deletions spec/order_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'menu'
require 'order'

def menu
menu = [
{ "Pizza" => 7 },
{ "Fish and Chips" => 9 },
{ "Pancakes with Bacon and Maple Syrup" => 6 },
{ "Vegetable Stir Fry with Gyoza" => 8 },
{ "Cheese and Pickle Sandwich" => 4 },
{ "Ramen" => 6 },
{ "Beef Pho" => 9 }
]
end

RSpec.describe 'order' do
it "is initially empty" do
order = Order.new
expect(order.order_complete).to eq ([])
end

it "can have an item added to it" do
order = Order.new
item = menu[2]
order.add(item)
expect(order.order_complete).to eq ([{ "Pancakes with Bacon and Maple Syrup" => 6 }])
end

it "can have more than one item added to it" do
order = Order.new
item1 = menu[0]
item2 = menu[1]
order.add(item1)
order.add(item2)
expect(order.order_complete).to eq ([{ "Pizza" => 7 }, { "Fish and Chips" => 9 }])
end
end