-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathzoo_spec.rb
More file actions
143 lines (120 loc) · 3.3 KB
/
zoo_spec.rb
File metadata and controls
143 lines (120 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Zoo spec file
require "./zoo"
require "rspec"
require '../../spec_helper'
class Grasshoppers < Food; end
class Salad < Food; end
describe Tacos do
it "should know all tacos are equal" do
(Tacos.new == Tacos.new).should be_true
end
end
describe Panda do
it "should like bamboo" do
Panda.new.likes?(Bamboo.new).should eq(true)
end
it "should not like grasshoppers" do
Panda.new.likes?(Grasshoppers.new).should eq(false)
end
it "should be able to eat the food" do
Panda.new.eat(Bamboo.new).should be_true
end
it "should be full after eating 30 bamboo" do
panda = Panda.new
31.times do
panda.eat(Bamboo.new)
end
panda.should be_full
end
it "should not be full after 1" do
panda = Panda.new
panda.eat(Bamboo.new)
panda.should_not be_full
end
end
describe Lion do
it "should like wildebeests" do
Lion.new.likes?(Wildebeests.new).should eq(true)
end
it "should like zeebras" do
Lion.new.likes?(Zeebras.new).should eq(true)
end
it "should not like salad" do
Lion.new.likes?(Salad.new).should eq(false)
end
it "should take 11 meals to be full" do
lion = Lion.new
lion.eat(Zeebras.new)
lion.should_not be_full
end
it "should take 11 meals to be full" do
lion = Lion.new
11.times do
lion.eat(Zeebras.new)
end
lion.should be_full
end
end
describe Zookeeper do
it "should be able to feed bamboo to the pandas" do
panda = Panda.new
panda.should_receive(:eat).with(:bamboo)
Zookeeper.new.feed(food: :bamboo, to: panda)
end
it "should be able to feed zeebras to the lions" do
lion = Lion.new
lion.should_receive(:eat).with(:zeebras)
Zookeeper.new.feed(food: :zeebras, to: lion)
end
it "should feed the panda the bamboo when foodbarge is received" do
foodbarge = FoodBarge.new
zookeeper = Zookeeper.new
panda = Panda.new
bamboo = Bamboo.new
foodbarge.food_for(food: bamboo, to: zookeeper, animal: panda)
expect(panda.eat(bamboo)).to eq(true)
end
it "should feed the lion the zeebras when foodbarge is received" do
foodbarge = FoodBarge.new
zookeeper = Zookeeper.new
lion = Lion.new
zeebras = Zeebras.new
foodbarge.food_for(food: zeebras, to: zookeeper, animal: lion)
expect(lion.eat(zeebras)).to eq(true)
end
it "should not feed the lion the bamboo when foodbarge is received" do
foodbarge = FoodBarge.new
zookeeper = Zookeeper.new
lion = Lion.new
bamboo = Bamboo.new
foodbarge.food_for(food: bamboo, to: zookeeper, animal: lion)
expect(lion.eat(bamboo)).to eq(false)
end
end
describe Human do
it "should like bacon" do
expect(Human.new.likes?(Bacon.new)).to eq(true)
end
it "should like tacos" do
expect(Human.new.likes?(Tacos.new)).to eq(true)
end
it "should not like bamboo" do
expect(Human.new.likes?(Bamboo.new)).to eq(false)
end
end
describe FoodBarge do
it "should be sent to zookeeper with bamboo for a panda" do
zookeeper = Zookeeper.new
bamboo = Bamboo.new
panda = Panda.new
expect(zookeeper).to receive(:receive).with(food: bamboo, to: panda)
expect(FoodBarge.new.food_for(food: bamboo, to: zookeeper, animal: panda))
end
it "should be sent to zookeeper with zeebras for a lion" do
zookeeper = Zookeeper.new
zeebras = Zeebras.new
lion = Lion.new
expect(zookeeper).to receive(:receive).with(food: zeebras, to: lion)
expect(FoodBarge.new.food_for(food: zeebras, to: zookeeper, animal: lion))
end
end