Skip to content

Commit 7fde0c3

Browse files
committed
Removed Chef for simplicity at this point
added some tests and refactored mood for the customer now use instance_variable_set instead of using attr_accessor to make a setter
1 parent a494a1f commit 7fde0c3

File tree

5 files changed

+20
-54
lines changed

5 files changed

+20
-54
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
/tmp/

Diff for: Rakefile

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ desc 'Run Minitest Tests'
1414
Rake::TestTask.new(:test) do |t|
1515
end
1616

17-
#desc 'Storm test'
18-
#Rake::TestTask.new(:storm) do |t|
19-
#end
20-
2117
Cucumber::Rake::Task.new(:features) do |t|
2218
t.cucumber_opts = "features --format pretty"
2319
end

Diff for: features/step_definitions/restaurant_steps.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
Before do
44
@w=Waiter.new
5-
@chef=Chef.new
65
@c=Customer.new
76
end
87

@@ -102,7 +101,7 @@
102101
# but since I don;t know how to do that and don't want to spend hours figuring it out
103102
# since there are not a lot of great examples out there or useful documentation
104103
# I added a setter for mood (bad idea) just so I can run this test....
105-
@c.mood=arg1
104+
@c.instance_variable_set(:@mood, arg1)
106105
end
107106

108107
When /^I greet him with "(.*)"$/ do |arg1|

Diff for: lib/restaurant.rb

+3-19
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ def initialize
1313

1414
# check item on menu
1515
def take_order(item)
16-
!$menu[item].nil?
16+
$menu[item].nil? ? "So sorry we don't have #{item}" : "I will take your order straight to the kitchen"
1717
end
1818

1919
def place_order(order)
20+
"Dear chef can you please prepare this order?"
2021
end
2122

2223
def serve_order(order)
@@ -36,7 +37,7 @@ def take_money
3637

3738

3839
class Customer
39-
attr_accessor :mood # don't really want mood up here - need it for testing
40+
# attr_accessor :mood # don't really want mood up here - need it for testing - now using instance_variable_set
4041
attr_reader :order, :mood, :tip
4142

4243
def initialize
@@ -68,23 +69,6 @@ def leave
6869
end
6970

7071

71-
class Chef
72-
def initialize
73-
end
74-
75-
def cook(item)
76-
end
77-
78-
def prepare (ingrediant)
79-
end
80-
81-
def manage(orders)
82-
end
83-
84-
def ready_order(order)
85-
end
86-
end
87-
8872
class Order
8973
# something funky going on with the names in here. too many 'orders'
9074
# probably not a good practice- can cause confusion...

Diff for: test/restaurant_test.rb

+14-29
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,41 @@
33
before do
44
@w=Waiter.new
55
end
6+
67
it 'should take orders' do
78
assert_respond_to @w, :take_order
89
end
910

1011
it 'should only accept order on menu' do
11-
assert @w.take_order(:pizza)
12-
refute @w.take_order(1)
13-
assert !@w.take_order(:flanksteak)
12+
assert_equal "I will take your order straight to the kitchen", @w.take_order(:pizza) # these tests makes my skin crawl! So hard coded.
13+
assert_equal "So sorry we don't have 1", @w.take_order(1)
14+
refute_equal "I will take your order straight to the kitchen", @w.take_order(:flanksteak)
1415
end
1516

1617
it 'should place order' do
17-
assert_respond_to @w, :place_order
18-
18+
assert_respond_to @w, :place_order
19+
@mo=MiniTest::Mock.new
20+
@mo.expect(:order, [:pizza, :plankton])
21+
assert_equal "Dear chef can you please prepare this order?", @w.place_order(@mo.order)
1922
end
2023

2124
it 'should serve order' do
2225
assert_respond_to @w, :serve_order
26+
2327
end
2428

2529
it 'should greet customer' do
2630
assert_respond_to @w, :greet
2731
refute_nil @w.greet
32+
assert_includes($greetings.keys, @w.greet)
33+
# refute_includes($menu.keys, @w.greet) # this is a bad test because theoretically the greeting could also be on the menu. E.g.,the waiter could greet the customer by saying 'plankton'
2834
end
2935

3036

3137
it 'should deliver check' do
3238
assert_respond_to @w, :deliver_check
3339
end
40+
3441
it 'should take money' do
3542
assert_respond_to @w, :take_money
3643
end
@@ -55,7 +62,7 @@
5562

5663

5764
it 'should pay the bill'do
58-
assert_respond_to @c, :pay
65+
assert_respond_to @c, :pay
5966
end
6067

6168

@@ -66,28 +73,6 @@
6673
it 'should tip based on its mood' do
6774
# this should be mocked?
6875
# or it could be a feature?
69-
70-
end
71-
end
72-
73-
describe Chef do
74-
before do
75-
@chef=Chef.new
7676
end
77-
it 'should cook the item ordered' do
78-
assert_respond_to @chef, :cook
79-
end
80-
81-
it 'should prepare ingrediants'do
82-
assert_respond_to @chef, :prepare
83-
end
84-
85-
it 'should manage multiple orders' do
86-
assert_respond_to @chef, :manage
87-
# not sure about this one...
8877
end
89-
it 'should ready an order' do
90-
assert_respond_to @chef, :ready_order
91-
end
92-
93-
end
78+

0 commit comments

Comments
 (0)