class Capybara::Server

Attributes

app[R]
port[R]

Public Class Methods

new(app) click to toggle source
# File lib/capybara/server.rb, line 30
def initialize(app)
  @app = app
end
ports() click to toggle source
# File lib/capybara/server.rb, line 23
def ports
  @ports ||= {}
end

Public Instance Methods

boot() click to toggle source
# File lib/capybara/server.rb, line 56
def boot
  if @app
    @port = Capybara::Server.ports[@app.object_id]

    if not @port or not responsive?
      @port = Capybara.server_port || find_available_port
      Capybara::Server.ports[@app.object_id] = @port

      Thread.new do
        Capybara.server.call(Identify.new(@app), @port)
      end

      Capybara.timeout(Capybara.server_boot_timeout) do
        if responsive? then true else sleep(0.5) and false end
      end
    end
  end
rescue TimeoutError
  puts "Rack application timed out during boot"
  exit
else
  self
end
host() click to toggle source
# File lib/capybara/server.rb, line 34
def host
  "127.0.0.1"
end
responsive?() click to toggle source
# File lib/capybara/server.rb, line 46
def responsive?
  res = Net::HTTP.start(host, @port) { |http| http.get('/__identify__') }

  if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
    return res.body == @app.object_id.to_s
  end
rescue Errno::ECONNREFUSED, Errno::EBADF
  return false
end
url(path) click to toggle source
# File lib/capybara/server.rb, line 38
def url(path)
  if path =~ %r^http/
    path
  else
    (Capybara.app_host || "http://#{host}:#{port}") + path.to_s
  end
end