[rspec-users] Stubbing Sleep

James Martin jimmymartin at gmail.com
Tue Feb 22 22:13:28 EST 2011

Thanks, Michael: That's a useful article.

I attempted to emulate the example in RSpec but still found that stubbing
sleep with any of the built in rspec-mocks wasn't working the way I hoped. I
was probably doing something wrong.

In the end I wrote a little module (Sleepy) that I can include in
RSpec.configure, which adds the #within method to the DSL. So now I can say
something like this:

RSpec.configure do |c|

describe "some long running method" do
   it "takes no longer than thirty seconds to do its work" do
      within 30.seconds do
          some_long_running_method.should do_what_we_expect

And yes; I committed horrible atrocities duck punching Fixnum and Float to
get the syntax reading nicely! :)

I suppose what I really wanted to be able to say was something like:

some_long_running_method.should_eventually do_what_we_expect

And be able to configure the maximum timeout of #should_eventually

Anyway, if this looks interesting or helpful for someone else I'll throw it
in a Gist.


On Wed, Feb 23, 2011 at 6:37 AM, Michael Guterl <mguterl at gmail.com> wrote:

> >
> Eric Hodel recently blogged about this:
> http://blog.segment7.net/2011/01/06/how-to-sleep-in-tests
> Best,
> Michael Guterl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110223/bf580a3b/attachment.html>

More information about the rspec-users mailing list