Class: Capybara::Server
- Inherits:
-
Object
- Object
- Capybara::Server
- Defined in:
- lib/capybara/server.rb
Defined Under Namespace
Classes: Middleware
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
- #boot ⇒ Object
- #error ⇒ Object
-
#initialize(app, port = Capybara.server_port, host = Capybara.server_host) ⇒ Server
constructor
A new instance of Server.
- #reset_error! ⇒ Object
- #responsive? ⇒ Boolean
Constructor Details
#initialize(app, port = Capybara.server_port, host = Capybara.server_host) ⇒ Server
Returns a new instance of Server.
36 37 38 39 40 41 42 43 |
# File 'lib/capybara/server.rb', line 36 def initialize(app, port=Capybara.server_port, host=Capybara.server_host) @app = app @middleware = Middleware.new(@app) @server_thread = nil # suppress warnings @host, @port = host, port @port ||= Capybara::Server.ports[@app.object_id] @port ||= find_available_port end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
34 35 36 |
# File 'lib/capybara/server.rb', line 34 def app @app end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
34 35 36 |
# File 'lib/capybara/server.rb', line 34 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
34 35 36 |
# File 'lib/capybara/server.rb', line 34 def port @port end |
Class Method Details
.ports ⇒ Object
29 30 31 |
# File 'lib/capybara/server.rb', line 29 def ports @ports ||= {} end |
Instance Method Details
#boot ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/capybara/server.rb', line 65 def boot unless responsive? Capybara::Server.ports[@app.object_id] = @port @server_thread = Thread.new do Capybara.server.call(@middleware, @port) end Timeout.timeout(60) { @server_thread.join(0.1) until responsive? } end rescue Timeout::Error raise "Rack application timed out during boot" else self end |
#error ⇒ Object
49 50 51 |
# File 'lib/capybara/server.rb', line 49 def error @middleware.error end |
#reset_error! ⇒ Object
45 46 47 |
# File 'lib/capybara/server.rb', line 45 def reset_error! @middleware.error = nil end |
#responsive? ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/capybara/server.rb', line 53 def responsive? return false if @server_thread && @server_thread.join(0) 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 SystemCallError return false end |