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|
  c.include(Sleepy)
end

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
       end
   end
end


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.


Cheers,
James.

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

> >
> Eric Hodel recently blogged about this:
> http://blog.segment7.net/2011/01/06/how-to-sleep-in-tests
>
> Best,
> Michael Guterl
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to