Forum: Ruby unit testing with webrick

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Aaron P. (Guest)
on 2006-03-17 20:03
(Received via mailing list)
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 = {
      s =
        :Port           => 0,
        :DocumentRoot   => Dir::pwd + "/htdocs"
      @port = s.config[:Port]


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

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

This topic is locked and can not be replied to.