Unit testing with webrick

Hi. I've written a unit test that starts up WEBrick in a new thread in
the setup method. I was wondering what the best way would be to
guarantee that WEBrick is ready to accept connections before leaving the
setup method.

I was thinking after creating the thread I would attempt to make a
connection and if the connection didn't work, do a retry. Here is my
(not completely implemented) code so far:

class WebTest < Test::Unit::TestCase
  def setup
    @server = Thread.new {
      s = WEBrick::HTTPServer.new(
        :Port => 0,
        :DocumentRoot => Dir::pwd + "/htdocs"
      )
      @port = s.config[:Port]

      s.start
    }

    begin
      # Test to see if the server is up
    rescue
      # Sleep, then retry
    end
  end
end

Does anyone have a more elegant way of doing this? Thanks!

--Aaron