[rspec-users] Stubbing Sleep

Michael Guterl mguterl at gmail.com
Tue Feb 22 14:37:47 EST 2011

On Tue, Feb 22, 2011 at 6:13 AM, James Martin <jimmymartin at gmail.com> wrote:
> I've recently been playing around with some code that re-runs a block until
> either the block returns a non-false value, or a timeout expires:
> https://gist.github.com/838520
> At first, I thought this was working, as I was just checking the timing of
> the examples when returning a true value, however, now it looks like sleep
> 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 specified
> 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 my
> 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.
Eric Hodel recently blogged about this:

Michael Guterl

More information about the rspec-users mailing list