Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

54 lines (43 sloc) 1.054 kb
require 'net/http'
require 'rack'
class Capybara::Server
attr_reader :app
def initialize(app)
@app = app
end
def port
8080
end
def host
'localhost'
end
def url(path)
"http://#{host}:#{port}#{path}"
end
def boot
Capybara.log "application has already booted" and return if responsive?
Capybara.log "booting Rack applicartion on port #{port}"
start_time = Time.now
Thread.new do
Rack::Handler::Mongrel.run @app, :Port => port
end
Capybara.log "checking if application has booted"
loop do
Capybara.log("application has booted") and break if responsive?
if Time.now - start_time > 10
Capybara.log "Rack application timed out during boot"
exit
end
Capybara.log '.'
sleep 1
end
end
def responsive?
res = Net::HTTP.start(host, port) { |http| http.get('/') }
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
return true
end
rescue Errno::ECONNREFUSED
return false
end
end
Jump to Line
Something went wrong with that request. Please try again.