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 38 39 |
# 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: []) unless .empty? warn 'Positional arguments, other than the application, to Server#new are deprecated, please use keyword arguments' end @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.
91 92 93 |
# File 'lib/capybara/server.rb', line 91 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.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/capybara/server.rb', line 72 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.
45 46 47 |
# File 'lib/capybara/server.rb', line 45 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.
41 42 43 |
# File 'lib/capybara/server.rb', line 41 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.
53 54 55 56 57 58 59 60 61 |
# File 'lib/capybara/server.rb', line 53 def responsive? return false if @server_thread&.join(0) res = @checker.request { |http| http.get('/__identify__') } 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.
49 50 51 |
# File 'lib/capybara/server.rb', line 49 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.
63 64 65 66 67 68 69 70 |
# File 'lib/capybara/server.rb', line 63 def wait_for_pending_requests timer = Capybara::Helpers.timer(expire_in: 60) while pending_requests? raise "Requests did not finish in 60 seconds: #{middleware.pending_requests}" if timer.expired? sleep 0.01 end end |