[rspec-users] how to write spec for infinite loop?
mailing_lists at railsnewbie.com
Thu May 29 03:46:14 EDT 2008
On May 29, 2008, at 3:33 AM, David Chelimsky wrote:
> On May 29, 2008, at 12:31 AM, Scott Taylor wrote:
>> On May 29, 2008, at 2:25 AM, zuo peng wrote:
>>> I've got trouble when describe infinite loop.
>>> code snippet:
>>> def start_loop
>>> while true
>>> data = self.server.handle_client
>>> if data
>>> without the loop, it is easy to test the logic.
>>> but how can I describe it to tell the developer ( me :-) ) that
>>> should be an infinite loop inside.
>> Here's a tip which Aslak gave me several months ago, and I find
>> myself repeating it in many different contexts on this mailing list:
>> One way is with dependency injection:
>> def start_loop(looping_infinitely = true)
> I think calling this dependency injection is a bit of a stretch. I
> agree with the approach of having a logical default that you can
> override in the example, but what exactly is the dependency on? true?
> Regardless of its name, this is a very good solution to the problem
> at hand.
Yeah, good point. It makes me laugh a bit too, now that I think about
Also, shouldn't the dependency occur in the constructor for it to be
More information about the rspec-users