I’ve recently been playing around with some code that re-runs a block
either the block returns a non-false value, or a timeout expires:
At first, I thought this was working, as I was just checking the timing
the examples when returning a true value, however, now it looks like
isn’t being stubbed as I expect.
In the final example, the output from RSpec shows the time taken is 1
second, even though it’s sleeping for at least the full 10 seconds
in the first argument to #do_this.
I can kind of imagine this not working at all, as the code relies on
calculations between two instances of Time.now.
Is there a better way to do this?
I’m really keen to get away from the whole Time.now/sleep combination in
tests if possible. I was thinking that perhaps a virtual clock would be
better, but then I’ve still got the sleep issue to deal with.