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

Steven Spiegl #2230

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions lib/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ def initialize
def view_menu
@items
end
#is this method necessary? Taking it out doesn't break tests...
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this method necessary? Taking it out doesn't break tests...

end
18 changes: 14 additions & 4 deletions lib/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ class Order

attr_reader :selection, :items, :total

def initialize
def initialize(items = Menu.new.items)
@selection = []
@items = Menu.new.items
@items = items
@total = 0
end

def view_menu
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have implemented suggestion to move this to initialize, but have a question:

Which is better? The implemented initialize or the one below?

def initialize(items = Menu.new)
   @selection = []
   @items = items.items
   @total = 0
end

Both seem to get the same results... The first reads more clearly but makes for a longer argument

Menu.new
@items
end

def add(item_index)

fail 'item not available' if @items[item_index - 1][:available] == false
@selection << @items[item_index - 1]
@total += @items[item_index - 1][:price]
Expand All @@ -33,6 +33,13 @@ def check_order_prompt
"Please check your order against your total:"
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did I understand User Story 3 correctly or did I go overboard?

As a customer
So that I can verify that my order is correct
I would like to check that the total I have been given matches the sum of the various dishes in my order'

did I satisfy this condition simply by giving the customer a 'total' method?

#did I understand User Story 3 correctly or did I go overboard?
# 'As a customer
# So that I can verify that my order is correct
# I would like to check that the total I have been given matches
# the sum of the various dishes in my order'
#did I satisfy this condition simply by giving the customer a 'total' method?

def selection_summary
@selection
end
Expand All @@ -49,3 +56,6 @@ def complete_order(phone_number)
SMS.new.send_sms(phone_number)
end
end

#complete_order is failing its tests, saying that it expected 1 argument
#and got 0, even
7 changes: 5 additions & 2 deletions spec/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@
it 'should call the SMS class' do
subject.add(1)
subject.checkout
expect(subject).to respond_to(subject.complete_order).with(SMS.new.send_sms(ENV['MY_PHONE']))
expect(subject).to respond_to(:complete_order).with(1).argument
end
end

Copy link
Author

@S-Spiegl S-Spiegl May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to actually check that complete_order((ENV['MY_PHONE'])) calls SMS.new.send_sms? I realised I was misusing respond_to above and below comment so changed it above, but now all the test does is check that the method takes one argument. I want to implement a test to make sure that when someone enters their phone number it calls the SMS class...

#how to actually check that the complete_order((ENV['MY_PHONE'])) calls
# SMS.new.send_sms?

context 'when a customer has checked their summary and enters complete_order' do
it 'should be instance of SMS' do
subject.add(1)
subject.checkout
expect(subject.complete_order).to_(SMS.new.send_sms)
expect(subject.complete_order).to respond_to(SMS.new.send_sms)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/sms_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'SMS'
# require 'dotenv/load'

describe SMS do

subject(:sms) { described_class.new }
Expand All @@ -19,7 +16,7 @@
expect(subject).to respond_to(:send_sms).with(1).argument
end
end

it 'changes the status of sent? to true when a message is sent' do
expect { subject.send_sms(ENV['MY_PHONE']) }.to change(subject, :sent?).to true
end
Expand All @@ -28,3 +25,6 @@
expect(subject.sms_sent_confirmation).to eq('A confirmation message has been sent to the number you provided')
end
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these tests actually check an sms has been sent, or just that the class acts as though a message has been sent (e.g. changes sent_confirmation)

#do these tests actually check an sms has been sent, or just that
#the class acts as though a message has been sent (e.g. changes sent_confirmation)