class Watir::Rails
Constants
- VERSION
Attributes
Public Class Methods
Start the Rails
server for tests. Will be called automatically by {Watir::Browser#initialize}.
@param [Integer] port port for the Rails
up to run on. If omitted use
previously selected port or select random available port.
# File lib/watir/rails.rb, line 23 def boot(port: nil) @port = port || @port || find_available_port unless running? @middleware = Middleware.new(app) @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, "Rails Rack application timed out during boot" end
Error rescued by the middleware.
@return [Exception or NilClass]
# File lib/watir/rails.rb, line 63 def error @middleware.error end
Set error rescued by the middleware.
@param value
# File lib/watir/rails.rb, line 77 def error=(value) @middleware.error = value end
Set host for Rails
app. Will be used by {Browser#goto} method.
@param [String] host host to use when using {Browser#goto}.
# File lib/watir/rails.rb, line 49 def host=(host) @host = host end
Check if Rails
exceptions should be ignored. Defaults to false.
@return [Boolean] true if exceptions should be ignored, false otherwise.
# File lib/watir/rails.rb, line 84 def ignore_exceptions? if @ignore_exceptions.nil? if ::Rails.application.config.action_dispatch.show_exceptions warn '[WARN] "action_dispatch.show_exceptions" is set to "true", disabling watir-rails exception catcher.' @ignore_exceptions = true end end !!@ignore_exceptions end
Local host for Rails
app under test.
@return [String] Local host with the value of “127.0.0.1”.
# File lib/watir/rails.rb, line 56 def local_host "127.0.0.1" end
Returns true if there are pending requests to server.
@return [Boolean]
# File lib/watir/rails.rb, line 70 def pending_requests? @middleware.pending_requests? end
Check if Rails
app under test is running.
@return [Boolean] true when Rails
app under test is running, false otherwise.
# File lib/watir/rails.rb, line 98 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, EOFError return false end
Private Class Methods
# File lib/watir/rails.rb, line 123 def boot_timeout 60 end
# File lib/watir/rails.rb, line 127 def find_available_port server = TCPServer.new(local_host, 0) server.addr[1] ensure server.close if server end
# File lib/watir/rails.rb, line 134 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