From 0909b5145a38578c2d1dc945bf3395e01f9896c7 Mon Sep 17 00:00:00 2001 From: Gawain Hewitt Date: Sat, 30 Apr 2022 08:51:46 +0100 Subject: [PATCH 1/6] step 1 working --- README.md | 77 +++++++---------------------------- diagramming_takewaway.odt | Bin 0 -> 15823 bytes instructions.md | 83 ++++++++++++++++++++++++++++++++++++++ lib/menu.rb | 16 ++++++++ lib/takeaway.rb | 13 ++++++ spec/menu_spec.rb | 18 +++++++++ spec/takeaway_spec.rb | 15 +++++++ 7 files changed, 159 insertions(+), 63 deletions(-) create mode 100644 diagramming_takewaway.odt create mode 100644 instructions.md create mode 100644 lib/menu.rb create mode 100644 lib/takeaway.rb create mode 100644 spec/menu_spec.rb create mode 100644 spec/takeaway_spec.rb diff --git a/README.md b/README.md index dbcb154e43..88587c089a 100644 --- a/README.md +++ b/README.md @@ -1,83 +1,34 @@ -Takeaway Challenge -================== -``` - _________ - r== | | - _ // | M.A. | )))) - |_)//(''''': | | - // \_____:_____.-------D ))))) - // | === | / \ - .:'//. \ \=| \ / .:'':./ ))))) - :' // ': \ \ ''..'--:'-.. ': - '. '' .' \:.....:--'.-'' .' - ':..:' ':..:' +# FAKE-AWAY - ``` +This is Gawain Hewitt's weekend challenge for Makers Academy week 2, the takeaway challenge. -Instructions -------- -* Feel free to use google, your notes, books, etc. but work on your own -* If you refer to the solution of another coach or student, please put a link to that in your README -* If you have a partial solution, **still check in a partial solution** -* You must submit a pull request to this repo with your code by 9am Monday morning +[Process Followed](#process-followed) -Task ------ +[Instructions For Use](#instructions-for-use). -* Fork this repo -* Run the command 'bundle' in the project directory to ensure you have all the gems -* Write a Takeaway program with the following user stories: -``` -As a customer -So that I can check if I want to order something -I would like to see a list of dishes with prices -As a customer -So that I can order the meal I want -I would like to be able to select some number of several available dishes -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 -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 -``` -* Hints on functionality to implement: - * Ensure you have a list of dishes with prices - * The text should state that the order was placed successfully and that it will be delivered 1 hour from now, e.g. "Thank you! Your order was placed and will be delivered before 18:52". - * The text sending functionality should be implemented using Twilio API. You'll need to register for it. It’s free. - * Use the twilio-ruby gem to access the API - * Use the Gemfile to manage your gems - * Make sure that your Takeaway is thoroughly tested and that you use mocks and/or stubs, as necessary to not to send texts when your tests are run - * However, if your Takeaway is loaded into IRB and the order is placed, the text should actually be sent - * Note that you can only send texts in the same country as you have your account. I.e. if you have a UK account you can only send to UK numbers. -* Advanced! (have a go if you're feeling adventurous): - * Implement the ability to place orders via text message. -* A free account on Twilio will only allow you to send texts to "verified" numbers. Use your mobile phone number, don't worry about the customer's mobile phone. -> :warning: **WARNING:** think twice before you push your **mobile number** or **Twilio API Key** to a public space like GitHub :eyes: -> -> :key: Now is a great time to think about security and how you can keep your private information secret. You might want to explore environment variables. +### Process Followed -* Finally submit a pull request before Monday at 9am with your solution or partial solution. However much or little amount of code you wrote please please please submit a pull request before Monday at 9am -In code review we'll be hoping to see: -* All tests passing -* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good) -* The code is elegant: every class has a clear responsibility, methods are short etc. -Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance will make the challenge somewhat easier. You should be the judge of how much challenge you want this at this moment. -Notes on Test Coverage ------------------- -You can see your [test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) when you run your tests. + + + + + + + +### Instructions For Use + diff --git a/diagramming_takewaway.odt b/diagramming_takewaway.odt new file mode 100644 index 0000000000000000000000000000000000000000..58ac364295bffffdf7bfd8746694fb97cdbd4941 GIT binary patch literal 15823 zcmeIZWmsI>wk=8^NPq-)3-0bta3^?h3Mt%zdxE<|aCdii_rij^ySrYp&s%3@?X%W? z@4jF6$L;kMHRk+AYr|&s>WtCbXDNucs9<0)U|~ zmAN&*($M@r;Qp?=)?clRz8c!v>H+>!cmJ+MTR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uL) z_IQEbdTE(6%owJ!!byhSpsU&bcm#)jS0C1?;X!icd$MV#Tf2Ojq|Sg)tMyMu@ew=I z&P>hP$kTyxjyx>)Z`L%gqC`|p!3sL|@tzqNE3mP@Q=C}1aosveE+J6qXQl7;^VT{F zOXsO03VEcs@6+G)zcc+0apgag{SrI=Y2B~I ze<%B0Z28YTe;wZA-|+lZeEH8zf9(<5>w^4ykA4?p{xi?7B=JAZ@^5&4jqJaKkN;m; zvj2wVPqF4dv;1{T^MAwgyLj`TdHy;kWbpqvH-Cyb|BL015bSrQ;xAR&pC :warning: **WARNING:** think twice before you push your **mobile number** or **Twilio API Key** to a public space like GitHub :eyes: +> +> :key: Now is a great time to think about security and how you can keep your private information secret. You might want to explore environment variables. + +* Finally submit a pull request before Monday at 9am with your solution or partial solution. However much or little amount of code you wrote please please please submit a pull request before Monday at 9am + + +In code review we'll be hoping to see: + +* All tests passing +* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good) +* The code is elegant: every class has a clear responsibility, methods are short etc. + +Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance will make the challenge somewhat easier. You should be the judge of how much challenge you want this at this moment. + +Notes on Test Coverage +------------------ + +You can see your [test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) when you run your tests. diff --git a/lib/menu.rb b/lib/menu.rb new file mode 100644 index 0000000000..cf6a0b4b8d --- /dev/null +++ b/lib/menu.rb @@ -0,0 +1,16 @@ +class Menu + attr_reader :contents + def initialize + @contents = [{food: :Chips, price: 1}, + {food: :Tofu, price: 2}, {food: :Broccoli, price: 1}, + {food: :Ice_cream, price: 2}] + end + + def show + @contents.each_with_index do |item, index| + puts "#{index+1}. #{item[:food]} - £#{item[:price]}" + end + end + +end + diff --git a/lib/takeaway.rb b/lib/takeaway.rb new file mode 100644 index 0000000000..cabab9911d --- /dev/null +++ b/lib/takeaway.rb @@ -0,0 +1,13 @@ +require './lib/menu.rb' + +class Takeaway + attr_reader :menu + def initialize + @menu = Menu.new + end + + def show_menu + @menu.show + end + +end \ No newline at end of file diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb new file mode 100644 index 0000000000..12c0c42c78 --- /dev/null +++ b/spec/menu_spec.rb @@ -0,0 +1,18 @@ +require 'menu' + +describe Menu do + it 'can hold dishes and prices' do + expect(subject.contents[0]).to eq({food: :Chips, price: 1}) + end + + it 'should respond to contents' do + expect(subject).to respond_to(:contents) + end + + it 'should display menu' do + expect do + subject.show + end.to output("1. Chips - £1\n2. Tofu - £2\n3. Broccoli - £1\n4. Ice_cream - £2\n").to_stdout + end + +end \ No newline at end of file diff --git a/spec/takeaway_spec.rb b/spec/takeaway_spec.rb new file mode 100644 index 0000000000..17ffc80fde --- /dev/null +++ b/spec/takeaway_spec.rb @@ -0,0 +1,15 @@ +require 'takeaway' + +describe Takeaway do + it 'should respond to show menu' do + expect(subject).to respond_to(:menu) + end + + it 'should call display method from Menu' do + expect(subject.menu).to receive(:show) + subject.show_menu + end + + +end + From 8883752308e10d153713c12aa8e534d0a9ba4c87 Mon Sep 17 00:00:00 2001 From: Gawain Hewitt Date: Sun, 1 May 2022 09:36:35 +0100 Subject: [PATCH 2/6] writing tests for user input --- lib/menu.rb | 13 ++++++------- lib/takeaway.rb | 14 +++++++++++--- spec/menu_spec.rb | 17 +++++------------ spec/takeaway_spec.rb | 28 ++++++++++++++++++++++------ 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/lib/menu.rb b/lib/menu.rb index cf6a0b4b8d..09d05d4e3d 100644 --- a/lib/menu.rb +++ b/lib/menu.rb @@ -1,16 +1,15 @@ class Menu - attr_reader :contents + def initialize - @contents = [{food: :Chips, price: 1}, - {food: :Tofu, price: 2}, {food: :Broccoli, price: 1}, - {food: :Ice_cream, price: 2}] + @dishes = [{ food: :Chips, price: 1 }, + { food: :Tofu, price: 2 }, { food: :Broccoli, price: 1 }, + { food: :Ice_cream, price: 2 }] end def show - @contents.each_with_index do |item, index| - puts "#{index+1}. #{item[:food]} - £#{item[:price]}" + @dishes.each_with_index do |item, index| + puts "#{index + 1}. #{item[:food]} - £#{item[:price]}" end end end - diff --git a/lib/takeaway.rb b/lib/takeaway.rb index cabab9911d..543c96d690 100644 --- a/lib/takeaway.rb +++ b/lib/takeaway.rb @@ -1,13 +1,21 @@ -require './lib/menu.rb' +require './lib/menu' class Takeaway attr_reader :menu - def initialize + def initialize(input: $stdin, output: $stdout) + @input = input + @output = output @menu = Menu.new + @dishes = [] end def show_menu @menu.show end + + def order + @output.puts "Please type each dish you require followed by return. When you have finished your order press return twice." + @dish = @input.gets.chomp + end -end \ No newline at end of file +end diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb index 12c0c42c78..a26a19bc97 100644 --- a/spec/menu_spec.rb +++ b/spec/menu_spec.rb @@ -1,18 +1,11 @@ require 'menu' describe Menu do - it 'can hold dishes and prices' do - expect(subject.contents[0]).to eq({food: :Chips, price: 1}) - end - - it 'should respond to contents' do - expect(subject).to respond_to(:contents) - end - it 'should display menu' do - expect do - subject.show - end.to output("1. Chips - £1\n2. Tofu - £2\n3. Broccoli - £1\n4. Ice_cream - £2\n").to_stdout + context '#show' do + it 'should display menu' do + expect { subject.show }.to output("1. Chips - £1\n2. Tofu - £2\n3. Broccoli - £1\n4. Ice_cream - £2\n").to_stdout + end end -end \ No newline at end of file +end diff --git a/spec/takeaway_spec.rb b/spec/takeaway_spec.rb index 17ffc80fde..54fa0b959e 100644 --- a/spec/takeaway_spec.rb +++ b/spec/takeaway_spec.rb @@ -1,15 +1,31 @@ require 'takeaway' +require 'stringio' describe Takeaway do - it 'should respond to show menu' do - expect(subject).to respond_to(:menu) + + context '#show menu' do + it 'should call #show from class instance of Menu' do + expect(subject.menu).to receive(:show) + subject.show_menu + end end - it 'should call display method from Menu' do - expect(subject.menu).to receive(:show) - subject.show_menu + context '#order' do + it 'this is my test' do + output = place_order_with_input("Broccoli") + + expect(output).to eq "Please type each dish you require followed by return. When you have finished your order press return twice.\n" + end end + def place_order_with_input(order) + input = StringIO.new(order) + output= StringIO.new -end + takeaway = Takeaway.new(input: input, output: output) + expect(takeaway.order).to eq input.string + output.string + end + +end From 9c5f6334494c8d601046cc6c1f4f529fa0f68bd3 Mon Sep 17 00:00:00 2001 From: Gawain Hewitt Date: Sun, 1 May 2022 12:43:41 +0100 Subject: [PATCH 3/6] working tests to check dishes against menu --- lib/menu.rb | 18 ++++++++++++++++-- lib/takeaway.rb | 12 ++++++++++-- spec/menu_spec.rb | 20 ++++++++++++++++++++ spec/takeaway_spec.rb | 17 ++++++++++------- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/lib/menu.rb b/lib/menu.rb index 09d05d4e3d..9cdd74db06 100644 --- a/lib/menu.rb +++ b/lib/menu.rb @@ -1,6 +1,8 @@ class Menu - def initialize + def initialize(input: $stdin, output: $stdout) + @input = input + @output = output @dishes = [{ food: :Chips, price: 1 }, { food: :Tofu, price: 2 }, { food: :Broccoli, price: 1 }, { food: :Ice_cream, price: 2 }] @@ -8,8 +10,20 @@ def initialize def show @dishes.each_with_index do |item, index| - puts "#{index + 1}. #{item[:food]} - £#{item[:price]}" + @output.puts "#{index + 1}. #{item[:food]} - £#{item[:price]}" end end + def check(dish) + _dish = dish.to_sym + @dishes.each do |dish| + "food #{dish[:food]}" + if _dish == dish[:food] + return true + end + end + return false + end + end + diff --git a/lib/takeaway.rb b/lib/takeaway.rb index 543c96d690..037c2c7cea 100644 --- a/lib/takeaway.rb +++ b/lib/takeaway.rb @@ -14,8 +14,16 @@ def show_menu end def order - @output.puts "Please type each dish you require followed by return. When you have finished your order press return twice." - @dish = @input.gets.chomp + loop do + @output.puts "Please type each dish you require followed by return. When you have finished your order press return twice." + dish = @input.gets.chomp + if menu.check(dish) + @output.puts "how many do you want?" + quantity = @input.gets.to_i + return true + @output.puts "Sorry, we don't have that dish - perhaps you've made a spelling mistake?" + end + end end end diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb index a26a19bc97..b98dcbcbda 100644 --- a/spec/menu_spec.rb +++ b/spec/menu_spec.rb @@ -4,8 +4,28 @@ context '#show' do it 'should display menu' do + # output = <<~MENU + # 1. Chips - £1 + # 2. Tofu - £2 + # 3. Broccoli - £1 + # 4. Ice_cream - £2 + # MENU + # expect { subject.show }.to output(output).to_stdout + expect { subject.show }.to output("1. Chips - £1\n2. Tofu - £2\n3. Broccoli - £1\n4. Ice_cream - £2\n").to_stdout end end + context '#check' do + it 'dish against menu and return false' do + wrong_spelling = "Brocoli" + expect(subject.check(wrong_spelling)).to eq false + end + it 'dish against menu and return true' do + right_spelling = "Broccoli" + expect(subject.check(right_spelling)).to eq true + end + end + end + diff --git a/spec/takeaway_spec.rb b/spec/takeaway_spec.rb index 54fa0b959e..9522f2b204 100644 --- a/spec/takeaway_spec.rb +++ b/spec/takeaway_spec.rb @@ -11,19 +11,22 @@ end context '#order' do - it 'this is my test' do - output = place_order_with_input("Broccoli") + it 'can order one item from menu' do + output = place_order_with_input("Broccoli", 1) - expect(output).to eq "Please type each dish you require followed by return. When you have finished your order press return twice.\n" - end + expect(output).to eq <<~OUTPUT + Please type each dish you require followed by return. When you have finished your order press return twice. + how many do you want? + OUTPUT + end end - def place_order_with_input(order) - input = StringIO.new(order) + def place_order_with_input(*order) + input = StringIO.new(order.join("\n") + "\n") output= StringIO.new takeaway = Takeaway.new(input: input, output: output) - expect(takeaway.order).to eq input.string + expect(takeaway.order).to eq true output.string end From ca00cf9a9d0c6cf5165d2726a3a6a394b53be3c3 Mon Sep 17 00:00:00 2001 From: Gawain Hewitt Date: Sun, 1 May 2022 20:00:25 +0100 Subject: [PATCH 4/6] tdd 1 order and mispelt, stuck on many orders --- lib/takeaway.rb | 17 +++++++++++++++-- spec/feature_test_spec.rb | 26 ++++++++++++++++++++++++++ spec/takeaway_spec.rb | 19 ++++++++++++++++--- 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 spec/feature_test_spec.rb diff --git a/lib/takeaway.rb b/lib/takeaway.rb index 037c2c7cea..a47c213a84 100644 --- a/lib/takeaway.rb +++ b/lib/takeaway.rb @@ -1,7 +1,7 @@ require './lib/menu' class Takeaway - attr_reader :menu + def initialize(input: $stdin, output: $stdout) @input = input @output = output @@ -9,6 +9,10 @@ def initialize(input: $stdin, output: $stdout) @dishes = [] end + def menu + @menu + end + def show_menu @menu.show end @@ -17,13 +21,22 @@ def order loop do @output.puts "Please type each dish you require followed by return. When you have finished your order press return twice." dish = @input.gets.chomp + # return true if dish == "" if menu.check(dish) @output.puts "how many do you want?" quantity = @input.gets.to_i - return true + return true + else @output.puts "Sorry, we don't have that dish - perhaps you've made a spelling mistake?" end end end end + + +# need to get the method order looping to keep asking until double return +# line 24 and removing line 28 does this for an irb test but it breaks +# the rspec tests. Until this is fixed we can't run the 3 items test +# also the order is not being put anywhere yet - needs to be added to a +# hash - and perhaps to and order class \ No newline at end of file diff --git a/spec/feature_test_spec.rb b/spec/feature_test_spec.rb new file mode 100644 index 0000000000..485b3f0bc7 --- /dev/null +++ b/spec/feature_test_spec.rb @@ -0,0 +1,26 @@ +require 'takeaway' + +describe 'Featuretest' do + context '#order' do + it 'will ask again if item mispelt' do + output = place_order_with_input("Brocoli", "Broccoli") + + expect(output).to eq <<~OUTPUT + Please type each dish you require followed by return. When you have finished your order press return twice. + Sorry, we don't have that dish - perhaps you've made a spelling mistake? + Please type each dish you require followed by return. When you have finished your order press return twice. + how many do you want? + OUTPUT + end + end + + def place_order_with_input(*order) + input = StringIO.new(order.join("\n") + "\n") + output= StringIO.new + + takeaway = Takeaway.new(input: input, output: output) + expect(takeaway.order).to eq true + + output.string + end +end diff --git a/spec/takeaway_spec.rb b/spec/takeaway_spec.rb index 9522f2b204..e3523e4a0a 100644 --- a/spec/takeaway_spec.rb +++ b/spec/takeaway_spec.rb @@ -12,13 +12,25 @@ context '#order' do it 'can order one item from menu' do - output = place_order_with_input("Broccoli", 1) - + output = place_order_with_input("Broccoli") + expect(output).to eq <<~OUTPUT Please type each dish you require followed by return. When you have finished your order press return twice. how many do you want? OUTPUT - end + end + xit 'can order three items from menu' do + output = place_order_with_input("Broccoli", 2, "Chips", 1, "Ice_cream", 1) + + expect(output).to eq <<~OUTPUT + Please type each dish you require followed by return. When you have finished your order press return twice. + how many do you want? + Please type each dish you require followed by return. When you have finished your order press return twice. + how many do you want? + Please type each dish you require followed by return. When you have finished your order press return twice. + how many do you want? + OUTPUT + end end def place_order_with_input(*order) @@ -26,6 +38,7 @@ def place_order_with_input(*order) output= StringIO.new takeaway = Takeaway.new(input: input, output: output) + allow(takeaway.menu).to receive(:check).and_return(true) expect(takeaway.order).to eq true output.string From 00e89d8363e21448bacbf168f51ea68e1aaf50ca Mon Sep 17 00:00:00 2001 From: Gawain Hewitt Date: Mon, 2 May 2022 08:19:26 +0100 Subject: [PATCH 5/6] order can be made, user story 2 complete --- lib/menu.rb | 6 ++--- lib/takeaway.rb | 57 ++++++++++++++++++++++++++------------- spec/feature_test_spec.rb | 12 ++++++--- spec/menu_spec.rb | 1 - spec/takeaway_spec.rb | 51 +++++++++++++++++++++++++++-------- 5 files changed, 88 insertions(+), 39 deletions(-) diff --git a/lib/menu.rb b/lib/menu.rb index 9cdd74db06..62fedef6b3 100644 --- a/lib/menu.rb +++ b/lib/menu.rb @@ -15,10 +15,9 @@ def show end def check(dish) - _dish = dish.to_sym + the_dish = dish.to_sym @dishes.each do |dish| - "food #{dish[:food]}" - if _dish == dish[:food] + if the_dish == dish[:food] return true end end @@ -26,4 +25,3 @@ def check(dish) end end - diff --git a/lib/takeaway.rb b/lib/takeaway.rb index a47c213a84..045bc022c8 100644 --- a/lib/takeaway.rb +++ b/lib/takeaway.rb @@ -1,16 +1,14 @@ require './lib/menu' class Takeaway - + attr_reader :menu, :summary + def initialize(input: $stdin, output: $stdout) @input = input @output = output @menu = Menu.new @dishes = [] - end - - def menu - @menu + @summary = [] end def show_menu @@ -19,24 +17,45 @@ def show_menu def order loop do - @output.puts "Please type each dish you require followed by return. When you have finished your order press return twice." - dish = @input.gets.chomp - # return true if dish == "" + dish = ask_for_order + return true if dish == "" if menu.check(dish) - @output.puts "how many do you want?" - quantity = @input.gets.to_i - return true + quantity = ask_for_quantity + log_order(dish, quantity) else - @output.puts "Sorry, we don't have that dish - perhaps you've made a spelling mistake?" + clarify_order end end end - -end + private + + def confirm_order + true + end -# need to get the method order looping to keep asking until double return -# line 24 and removing line 28 does this for an irb test but it breaks -# the rspec tests. Until this is fixed we can't run the 3 items test -# also the order is not being put anywhere yet - needs to be added to a -# hash - and perhaps to and order class \ No newline at end of file + def ask_for_order + @output.puts <<~ORDER + Please type each dish you require followed by return. + When you have finished your order press return twice. + ORDER + dish = @input.gets.chomp + end + + def clarify_order + @output.puts "Sorry, we don't have that dish - perhaps you've made a spelling mistake?" + end + + def ask_for_quantity + @output.puts "how many do you want?" + quantity = @input.gets.to_i + end + + def log_order(dish, quantity) + order_item = {} + order_item[:food] = dish + order_item[:quantity] = quantity + @summary << order_item + end + +end diff --git a/spec/feature_test_spec.rb b/spec/feature_test_spec.rb index 485b3f0bc7..07912fd57f 100644 --- a/spec/feature_test_spec.rb +++ b/spec/feature_test_spec.rb @@ -6,17 +6,21 @@ output = place_order_with_input("Brocoli", "Broccoli") expect(output).to eq <<~OUTPUT - Please type each dish you require followed by return. When you have finished your order press return twice. + Please type each dish you require followed by return. + When you have finished your order press return twice. Sorry, we don't have that dish - perhaps you've made a spelling mistake? - Please type each dish you require followed by return. When you have finished your order press return twice. + Please type each dish you require followed by return. + When you have finished your order press return twice. how many do you want? + Please type each dish you require followed by return. + When you have finished your order press return twice. OUTPUT end end def place_order_with_input(*order) - input = StringIO.new(order.join("\n") + "\n") - output= StringIO.new + input = StringIO.new(order.join("\n") + "\n" + "\n" + "\n") + output = StringIO.new takeaway = Takeaway.new(input: input, output: output) expect(takeaway.order).to eq true diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb index b98dcbcbda..871cfbb4ab 100644 --- a/spec/menu_spec.rb +++ b/spec/menu_spec.rb @@ -28,4 +28,3 @@ end end - diff --git a/spec/takeaway_spec.rb b/spec/takeaway_spec.rb index e3523e4a0a..a6c4bb0438 100644 --- a/spec/takeaway_spec.rb +++ b/spec/takeaway_spec.rb @@ -11,31 +11,49 @@ end context '#order' do - it 'can order one item from menu' do - output = place_order_with_input("Broccoli") + it 'can ask for one order from menu' do + output = place_order_with_input_and_return_output("Broccoli") expect(output).to eq <<~OUTPUT - Please type each dish you require followed by return. When you have finished your order press return twice. + Please type each dish you require followed by return. + When you have finished your order press return twice. how many do you want? + Please type each dish you require followed by return. + When you have finished your order press return twice. OUTPUT end - xit 'can order three items from menu' do - output = place_order_with_input("Broccoli", 2, "Chips", 1, "Ice_cream", 1) + it 'can ask for three orders from menu' do + output = place_order_with_input_and_return_output("Broccoli", 2, "Chips", 1, "Ice_cream", 1) expect(output).to eq <<~OUTPUT - Please type each dish you require followed by return. When you have finished your order press return twice. + Please type each dish you require followed by return. + When you have finished your order press return twice. how many do you want? - Please type each dish you require followed by return. When you have finished your order press return twice. + Please type each dish you require followed by return. + When you have finished your order press return twice. how many do you want? - Please type each dish you require followed by return. When you have finished your order press return twice. + Please type each dish you require followed by return. + When you have finished your order press return twice. how many do you want? + Please type each dish you require followed by return. + When you have finished your order press return twice. OUTPUT end + it 'stores an order of one dish' do + takeaway = place_order_with_input_and_return_class("Chips", 1) + expect(takeaway.summary).to eq([{ food: "Chips", quantity: 1 }]) + end + it 'stores an order of four dishes' do + takeaway = place_order_with_input_and_return_class("Chips", 1, "Broccoli", 3, "Tofu", 1, "Ice_cream", 4) + expect(takeaway.summary).to eq([{ food: "Chips", quantity: 1 }, + { food: "Broccoli", quantity: 3 }, { food: "Tofu", quantity: 1 }, + { food: "Ice_cream", quantity: 4 }]) + end end - def place_order_with_input(*order) - input = StringIO.new(order.join("\n") + "\n") - output= StringIO.new + def place_order_with_input_and_return_output(*order) + input = StringIO.new(order.join("\n") + "\n" + "\n" + "\n") + output = StringIO.new takeaway = Takeaway.new(input: input, output: output) allow(takeaway.menu).to receive(:check).and_return(true) @@ -44,4 +62,15 @@ def place_order_with_input(*order) output.string end + def place_order_with_input_and_return_class(*order) + input = StringIO.new(order.join("\n") + "\n" + "\n" + "\n") + output = StringIO.new + + takeaway = Takeaway.new(input: input, output: output) + allow(takeaway.menu).to receive(:check).and_return(true) + expect(takeaway.order).to eq true + + takeaway + end + end From 124e7f0c25ebf02d1cbcc7583f0edb5e3d5068ca Mon Sep 17 00:00:00 2001 From: Gawain Hewitt Date: Mon, 2 May 2022 09:55:33 +0100 Subject: [PATCH 6/6] Completed user story 3 --- README.md | 21 +++++++++++++++++++-- lib/menu.rb | 10 ++++++++++ lib/takeaway.rb | 14 ++++++++++---- spec/feature_test_spec.rb | 4 +++- spec/menu_spec.rb | 5 +++++ spec/takeaway_spec.rb | 28 ++++++++++++++++++++++++---- 6 files changed, 71 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 88587c089a..0bb87737a8 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,11 @@ This is Gawain Hewitt's weekend challenge for Makers Academy week 2, the takeawa [Process Followed](#process-followed) -[Instructions For Use](#instructions-for-use). - +[Instructions For Use](#instructions-for-use) +[Things I enjoyed](#things-i-enjoyed) +[Things I struggled with](#things-i-struggled-with) @@ -32,3 +33,19 @@ This is Gawain Hewitt's weekend challenge for Makers Academy week 2, the takeawa ### Instructions For Use + + +### Things I enjoyed + +The challenge of writing tests for puts and user input. + +Trying to keep my tests discreet in each class. + +### Things I struggled with + +The sheer amount of work when writing tests for puts and user input. + +Stubbing a test to check totals on #confirm_order in class Takeaway + +Why a heredoc wouldn't work in my "it should display menu" test + diff --git a/lib/menu.rb b/lib/menu.rb index 62fedef6b3..dd5f4e2966 100644 --- a/lib/menu.rb +++ b/lib/menu.rb @@ -24,4 +24,14 @@ def check(dish) return false end + def price(dish) + the_dish = dish.to_sym + @dishes.each do |dish| + if the_dish == dish[:food] + return dish[:price] + end + end + return false + end + end diff --git a/lib/takeaway.rb b/lib/takeaway.rb index 045bc022c8..2224e5c449 100644 --- a/lib/takeaway.rb +++ b/lib/takeaway.rb @@ -9,6 +9,7 @@ def initialize(input: $stdin, output: $stdout) @menu = Menu.new @dishes = [] @summary = [] + @total = 0 end def show_menu @@ -18,7 +19,7 @@ def show_menu def order loop do dish = ask_for_order - return true if dish == "" + return confirm_order if dish == "" if menu.check(dish) quantity = ask_for_quantity log_order(dish, quantity) @@ -28,12 +29,17 @@ def order end end - private - def confirm_order - true + @summary.each do |dish| + @output.puts "#{dish[:quantity]} order of #{dish[:food]} at £#{menu.price(dish[:food])} each" + @total += menu.price(dish[:food]) + end + @output.puts "Total order is £#{@total}" end + private + + def ask_for_order @output.puts <<~ORDER Please type each dish you require followed by return. diff --git a/spec/feature_test_spec.rb b/spec/feature_test_spec.rb index 07912fd57f..25c23df74b 100644 --- a/spec/feature_test_spec.rb +++ b/spec/feature_test_spec.rb @@ -14,6 +14,8 @@ how many do you want? Please type each dish you require followed by return. When you have finished your order press return twice. + 0 order of Broccoli at £1 each + Total order is £1 OUTPUT end end @@ -23,7 +25,7 @@ def place_order_with_input(*order) output = StringIO.new takeaway = Takeaway.new(input: input, output: output) - expect(takeaway.order).to eq true + takeaway.order output.string end diff --git a/spec/menu_spec.rb b/spec/menu_spec.rb index 871cfbb4ab..06223cdf18 100644 --- a/spec/menu_spec.rb +++ b/spec/menu_spec.rb @@ -27,4 +27,9 @@ end end + context '#price' do + it 'returns the price of an item' do + expect(subject.price("Broccoli")).to eq 1 + end + end end diff --git a/spec/takeaway_spec.rb b/spec/takeaway_spec.rb index a6c4bb0438..32cb644012 100644 --- a/spec/takeaway_spec.rb +++ b/spec/takeaway_spec.rb @@ -11,7 +11,7 @@ end context '#order' do - it 'can ask for one order from menu' do + it 'can ask for one order from menu and return summary and total' do output = place_order_with_input_and_return_output("Broccoli") expect(output).to eq <<~OUTPUT @@ -20,9 +20,11 @@ how many do you want? Please type each dish you require followed by return. When you have finished your order press return twice. + 0 order of Broccoli at £1 each + Total order is £1 OUTPUT end - it 'can ask for three orders from menu' do + it 'can ask for three orders from menu and return summary and total' do output = place_order_with_input_and_return_output("Broccoli", 2, "Chips", 1, "Ice_cream", 1) expect(output).to eq <<~OUTPUT @@ -37,6 +39,10 @@ how many do you want? Please type each dish you require followed by return. When you have finished your order press return twice. + 2 order of Broccoli at £1 each + 1 order of Chips at £1 each + 1 order of Ice_cream at £1 each + Total order is £3 OUTPUT end it 'stores an order of one dish' do @@ -51,13 +57,24 @@ end end + context '#confirm order' do + it 'confirms order' do + output = StringIO.new + takeaway = Takeaway.new(output: output) + takeaway.confirm_order + expect(output.string).to eq "Total order is £0\n" + end + end + def place_order_with_input_and_return_output(*order) input = StringIO.new(order.join("\n") + "\n" + "\n" + "\n") output = StringIO.new + test_price = 1 takeaway = Takeaway.new(input: input, output: output) allow(takeaway.menu).to receive(:check).and_return(true) - expect(takeaway.order).to eq true + allow(takeaway.menu).to receive(:price).and_return(test_price) + takeaway.order output.string end @@ -65,10 +82,13 @@ def place_order_with_input_and_return_output(*order) def place_order_with_input_and_return_class(*order) input = StringIO.new(order.join("\n") + "\n" + "\n" + "\n") output = StringIO.new + test_price = 1 takeaway = Takeaway.new(input: input, output: output) allow(takeaway.menu).to receive(:check).and_return(true) - expect(takeaway.order).to eq true + allow(takeaway.menu).to receive(:price).and_return(test_price) + + takeaway.order takeaway end