Hi, imagine there’s a class called Egg which has the following method
(which calls another method):
def do_thing
has_iterated = false
self.each_row do |row|
has_iterated = true unless has_iterated
end
has_iterated
end
Stupid code, I know.
I have two questions with it. The first is, would it be possible to set
it up to test the case when each_row operates on an empty Array? Sort of
like this:
it “should return true if it does iterate over something” do
@egg.stub!( each_row ).and_yield( :value )
@egg.do_thing.should be_true
end
Secondly, is this the best (correct) way to pass multiple values to
iterate over?
As you can see, my understanding of and_yield() is very imperfect, so
any & all pointers are very gratefully received.
Cheers,
Doug.