[rspec-users] how to write spec for infinite loop?
dchelimsky at gmail.com
Thu May 29 03:33:57 EDT 2008
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 there
>> 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
> while looping_infinitely
> In your spec, you simply pass false (but production code can call
> the method as if there is no option).
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users