Class: Capybara::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/server.rb

Defined Under Namespace

Classes: Identify

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Server

Returns a new instance of Server.



22
23
24
# File 'lib/capybara/server.rb', line 22

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



20
21
22
# File 'lib/capybara/server.rb', line 20

def app
  @app
end

#portObject (readonly)

Returns the value of attribute port.



20
21
22
# File 'lib/capybara/server.rb', line 20

def port
  @port
end

Instance Method Details

#bootObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/capybara/server.rb', line 57

def boot
  return self unless @app
  find_available_port
  Capybara.log "application has already booted" and return self if responsive?
  Capybara.log "booting Rack applicartion on port #{port}"

  Thread.new do
    handler.run(Identify.new(@app), :Port => port, :AccessLog => [])
  end
  Capybara.log "checking if application has booted"

  Capybara::WaitUntil.timeout(10) do
    if responsive?
      Capybara.log("application has booted")
      true
    else
      sleep 0.5
      false
    end
  end
  self
rescue Timeout::Error
  Capybara.log "Rack application timed out during boot"
  exit
end

#handlerObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/capybara/server.rb', line 42

def handler
  begin
    require 'rack/handler/thin'
    Rack::Handler::Thin
  rescue LoadError
    begin
      require 'rack/handler/mongrel'
      Rack::Handler::Mongrel
    rescue LoadError
      require 'rack/handler/webrick'
      Rack::Handler::WEBrick
    end
  end
end

#hostObject



26
27
28
# File 'lib/capybara/server.rb', line 26

def host
  "localhost" 
end

#responsive?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/capybara/server.rb', line 38

def responsive?
  is_running_on_port?(port)
end

#url(path) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/capybara/server.rb', line 30

def url(path)
  if path =~ /^http/
    path
  else
    (Capybara.app_host || "http://#{host}:#{port}") + path.to_s
  end
end