Class: Capybara::Server
- Inherits:
-
Object
- Object
- Capybara::Server
- Defined in:
- lib/capybara/server.rb
Defined Under Namespace
Classes: Identify
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
- #boot ⇒ Object
- #host ⇒ Object
-
#initialize(app) ⇒ Server
constructor
A new instance of Server.
- #responsive? ⇒ Boolean
- #url(path) ⇒ Object
Constructor Details
#initialize(app) ⇒ Server
Returns a new instance of Server.
30 31 32 |
# File 'lib/capybara/server.rb', line 30 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
28 29 30 |
# File 'lib/capybara/server.rb', line 28 def app @app end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
28 29 30 |
# File 'lib/capybara/server.rb', line 28 def port @port end |
Class Method Details
.ports ⇒ Object
23 24 25 |
# File 'lib/capybara/server.rb', line 23 def ports @ports ||= {} end |
Instance Method Details
#boot ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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 ⇒ Object
34 35 36 |
# File 'lib/capybara/server.rb', line 34 def host "127.0.0.1" end |
#responsive? ⇒ Boolean
46 47 48 49 50 51 52 53 54 |
# 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 |