class Watir::Rack
Constants
- VERSION
Attributes
middleware[R]
port[RW]
server[W]
test_app[RW]
Public Class Methods
app()
click to toggle source
boot(port: nil)
click to toggle source
Start the Rack
Will be called automatically by {Watir::Browser#initialize}.
@param [Integer] port port for the Rack
# File lib/watir/rack.rb, line 22 def boot(port: nil) unless running? @middleware = Middleware.new(app) @port = port || find_available_port @server_thread = Thread.new do server.call @middleware, @port end Timeout.timeout(boot_timeout) { @server_thread.join(0.1) until running? } end rescue Timeout::Error raise Timeout::Error, "Rack Rack application timed out during boot" end
error()
click to toggle source
Error rescued by the middleware.
@return [Exception or NilClass]
# File lib/watir/rack.rb, line 61 def error @middleware.error end
error=(value)
click to toggle source
Set error rescued by the middleware.
@param value
# File lib/watir/rack.rb, line 75 def error=(value) @middleware.error = value end
host()
click to toggle source
host=(host)
click to toggle source
Set host for Rack
app. Will be used by {Browser#goto} method.
@param [String] host host to use when using {Browser#goto}.
# File lib/watir/rack.rb, line 47 def host=(host) @host = host end
local_host()
click to toggle source
Local host for Rack
app under test.
@return [String] Local host with the value of “127.0.0.1”.
# File lib/watir/rack.rb, line 54 def local_host "127.0.0.1" end
pending_requests?()
click to toggle source
Returns true if there are pending requests to server.
@return [Boolean]
# File lib/watir/rack.rb, line 68 def pending_requests? @middleware.pending_requests? end
running?()
click to toggle source
Check if Rack
app under test is running.
@return [Boolean] true when Rack
app under test is running, false otherwise.
# File lib/watir/rack.rb, line 82 def running? return false if @server_thread && @server_thread.join(0) res = Net::HTTP.start(local_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
Private Class Methods
boot_timeout()
click to toggle source
# File lib/watir/rack.rb, line 109 def boot_timeout 60 end
find_available_port()
click to toggle source
# File lib/watir/rack.rb, line 113 def find_available_port server = TCPServer.new(local_host, 0) server.addr[1] ensure server.close if server end
server()
click to toggle source
# File lib/watir/rack.rb, line 120 def server @server ||= lambda do |app, port| begin require 'rack/handler/thin' Thin::Logging.silent = true return ::Rack::Handler::Thin.run(app, :Port => port) rescue LoadError end begin require 'rack/handler/puma' return ::Rack::Handler::Puma.run(app, :Port => port, :Silent => true) rescue LoadError end require 'rack/handler/webrick' ::Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0)) end end