I have a method like this
class SomeClass
def self.test_method
while(true)
make_heavy_lifting
sleep(60*60)
end
end
end
How do i write test for this method.
one solution i thought of is stubbing sleep method and it worked but i am not able to stub the while keyword. please suggest best practices for unit testing a method which has infinite loop.
Maybe you can move everything inside the while except the sleep to another method, then you write specs only for that method, I don't think you really need to test that your method has a while loop and a sleep (you don't need to test EVERY line of your code :P) but if you want to do that check this question, it has some things you can try What is the best practice when it comes to testing "infinite loops"?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With