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]


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


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


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs