@@ -131,26 +131,47 @@ class Flea < BaseTestClass
131
131
132
132
end
133
133
134
- context 'when a flea jumps between dogs' do
134
+ context 'when fleas jump between dogs' do
135
135
136
136
let ( :small_dog ) { Dog . new ( 'Small dog' ) }
137
137
138
138
it 'cannot be in two dogs at the same time' do
139
139
flea_a . dog = big_dog
140
+ flea_b . dog = big_dog
140
141
expect ( flea_a . dog ) . to eq ( big_dog )
141
- expect ( big_dog . fleas ) . to eq ( [ flea_a ] )
142
+ expect ( flea_b . dog ) . to eq ( big_dog )
143
+ expect ( big_dog . fleas ) . to eq ( [ flea_a , flea_b ] )
142
144
143
- # flea jumps from big dog to small dog
145
+ # flea A jumps from big dog to small dog
144
146
flea_a . dog = small_dog
145
147
expect ( flea_a . dog ) . to eq ( small_dog )
146
148
expect ( small_dog . fleas ) . to eq ( [ flea_a ] )
147
149
148
150
# flea A no longer in big dog
149
151
expect ( big_dog . fleas ) . to_not include ( flea_a )
150
- expect ( big_dog . fleas ) . to be_empty # sanity check
152
+ expect ( big_dog . fleas ) . to eq ( [ flea_b ] ) # sanity check
153
+ end
154
+
155
+ end
156
+
157
+ context 'when a dog catches some fleas from another dog' do
158
+
159
+ let ( :small_dog ) { Dog . new ( 'Small dog' ) }
160
+
161
+ it 'the other dog losses part of its fleas' do
162
+
163
+ big_dog . fleas = [ flea_a , flea_b ]
164
+
165
+ # small_dog is close enough to bid_dog and it caches a flea
166
+ small_dog . fleas = [ flea_a ]
167
+
168
+ # flea A no longer in big dog
169
+ expect ( big_dog . fleas ) . to_not include ( flea_a )
170
+ expect ( big_dog . fleas ) . to eq ( [ flea_b ] ) # sanity check
151
171
end
152
172
153
173
end
174
+
154
175
end
155
176
156
177
end
0 commit comments