Class: Capybara::Server Private
- Inherits:
-
Object
- Object
- Capybara::Server
- Defined in:
- lib/capybara/server.rb,
lib/capybara/server/checker.rb,
lib/capybara/server/middleware.rb,
lib/capybara/server/animation_disabler.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: AnimationDisabler, Checker, Middleware
Instance Attribute Summary collapse
- #app ⇒ Object readonly private
- #host ⇒ Object readonly private
- #port ⇒ Object readonly private
Class Method Summary collapse
- .ports ⇒ Object private
Instance Method Summary collapse
- #base_url ⇒ Object private
- #boot ⇒ Object private
- #error ⇒ Object private
-
#initialize(app, *deprecated_options, port: Capybara.server_port, host: Capybara.server_host, reportable_errors: Capybara.server_errors, extra_middleware: []) ⇒ Server
constructor
private
A new instance of Server.
- #reset_error! ⇒ Object private
- #responsive? ⇒ Boolean private
- #using_ssl? ⇒ Boolean private
- #wait_for_pending_requests ⇒ Object private
Constructor Details
#initialize(app, *deprecated_options, port: Capybara.server_port, host: Capybara.server_host, reportable_errors: Capybara.server_errors, extra_middleware: []) ⇒ Server
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Server.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/capybara/server.rb', line 21 def initialize(app, *, port: Capybara.server_port, host: Capybara.server_host, reportable_errors: Capybara.server_errors, extra_middleware: []) warn 'Positional arguments, other than the application, to Server#new are deprecated, please use keyword arguments' unless .empty? @app = app @extra_middleware = extra_middleware @server_thread = nil # suppress warnings @host = [1] || host @reportable_errors = [2] || reportable_errors @port = [0] || port @port ||= Capybara::Server.ports[port_key] @port ||= find_available_port(host) @checker = Checker.new(@host, @port) end |
Instance Attribute Details
#app ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/capybara/server.rb', line 19 def app @app end |
#host ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/capybara/server.rb', line 19 def host @host end |
#port ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/capybara/server.rb', line 19 def port @port end |
Class Method Details
.ports ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/capybara/server.rb', line 14 def ports @ports ||= {} end |
Instance Method Details
#base_url ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 |
# File 'lib/capybara/server.rb', line 89 def base_url "http#{'s' if using_ssl?}://#{host}:#{port}" end |
#boot ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/capybara/server.rb', line 70 def boot unless responsive? Capybara::Server.ports[port_key] = port @server_thread = Thread.new do Capybara.server.call(middleware, port, host) end timer = Capybara::Helpers.timer(expire_in: 60) until responsive? raise 'Rack application timed out during boot' if timer.expired? @server_thread.join(0.1) end end self end |
#error ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/capybara/server.rb', line 43 def error middleware.error end |
#reset_error! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/capybara/server.rb', line 39 def reset_error! middleware.clear_error end |
#responsive? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 54 55 56 57 58 59 |
# File 'lib/capybara/server.rb', line 51 def responsive? return false if @server_thread&.join(0) res = @checker.request { |http| http.get('/__identify__') } return res.body == app.object_id.to_s if res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPRedirection) rescue SystemCallError, Net::ReadTimeout, OpenSSL::SSL::SSLError false end |
#using_ssl? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
47 48 49 |
# File 'lib/capybara/server.rb', line 47 def using_ssl? @checker.ssl? end |
#wait_for_pending_requests ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 64 65 66 67 68 |
# File 'lib/capybara/server.rb', line 61 def wait_for_pending_requests timer = Capybara::Helpers.timer(expire_in: 60) while pending_requests? raise 'Requests did not finish in 60 seconds' if timer.expired? sleep 0.01 end end |