What is the best practice when it comes to testing "infinite loops"? What is the best practice when it comes to testing "infinite loops"? ruby ruby

What is the best practice when it comes to testing "infinite loops"?


What might be more practical is to execute the loop in a separate thread, assert that everything is working correctly, and then terminate the thread when it is no longer required.

thread = Thread.new do  Blah.runendassert_equal 0, Blah.foothread.kill


How about having the body of the loop in a separate method, like calculateOneWorldIteration? That way you can spin the loop in the test as needed. And it doesn’t hurt the API, it’s quite a natural method to have in the public interface.


in rspec 3.3, add this line

allow(subject).to receive(:loop).and_yield

to your before hook will simple yield to the block without any looping