Class: Watir::Rails
- Inherits:
-
Object
- Object
- Watir::Rails
- Defined in:
- lib/watir/rails.rb,
lib/watir/version.rb,
lib/watir/rails/middleware.rb
Constant Summary collapse
- VERSION =
"2.2.2"
Class Attribute Summary collapse
-
.ignore_exceptions
writeonly
Sets the attribute ignore_exceptions.
-
.middleware
readonly
Returns the value of attribute middleware.
-
.port
readonly
Returns the value of attribute port.
-
.server
writeonly
Sets the attribute server.
Class Method Summary collapse
-
.app ⇒ Object
Rails app under test.
-
.boot(port: nil)
Start the Rails server for tests.
-
.error ⇒ Exception or NilClass
Error rescued by the middleware.
-
.error=(value)
Set error rescued by the middleware.
-
.host ⇒ String
Host for Rails app under test.
-
.host=(host)
Set host for Rails app.
-
.ignore_exceptions? ⇒ Boolean
Check if Rails exceptions should be ignored.
-
.local_host ⇒ String
Local host for Rails app under test.
-
.pending_requests? ⇒ Boolean
Returns true if there are pending requests to server.
-
.running? ⇒ Boolean
Check if Rails app under test is running.
Class Attribute Details
.ignore_exceptions=(value) (writeonly)
Sets the attribute ignore_exceptions
21 22 23 |
# File 'lib/watir/rails.rb', line 21 def ignore_exceptions=(value) @ignore_exceptions = value end |
.middleware (readonly)
Returns the value of attribute middleware.
20 21 22 |
# File 'lib/watir/rails.rb', line 20 def middleware @middleware end |
.port (readonly)
Returns the value of attribute port.
20 21 22 |
# File 'lib/watir/rails.rb', line 20 def port @port end |
.server=(value)
Sets the attribute server
21 22 23 |
# File 'lib/watir/rails.rb', line 21 def server=(value) @server = value end |
Class Method Details
.app ⇒ Object
Rails app under test.
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/watir/rails.rb', line 123 def app legacy = legacy_rails? @app ||= Rack::Builder.new do map "/" do if legacy use ::Rails::Rack::Static run ActionController::Dispatcher.new else run ::Rails.application end end end.to_app end |
.boot(port: nil)
Start the Rails server for tests. Will be called automatically by Browser#initialize.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/watir/rails.rb', line 27 def boot(port: nil) @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 ⇒ Exception or NilClass
Error rescued by the middleware.
67 68 69 |
# File 'lib/watir/rails.rb', line 67 def error @middleware.error end |
.error=(value)
Set error rescued by the middleware.
81 82 83 |
# File 'lib/watir/rails.rb', line 81 def error=(value) @middleware.error = value end |
.host ⇒ String
Host for Rails app under test. Default is local_host.
46 47 48 |
# File 'lib/watir/rails.rb', line 46 def host @host || local_host end |
.host=(host)
Set host for Rails app. Will be used by Browser#goto method.
53 54 55 |
# File 'lib/watir/rails.rb', line 53 def host=(host) @host = host end |
.ignore_exceptions? ⇒ Boolean
Check if Rails exceptions should be ignored. Defaults to false.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/watir/rails.rb', line 88 def ignore_exceptions? if @ignore_exceptions.nil? show_exceptions = if legacy_rails? ::Rails.configuration.action_dispatch.show_exceptions else ::Rails.application.config.action_dispatch.show_exceptions end if 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 ⇒ String
Local host for Rails app under test.
60 61 62 |
# File 'lib/watir/rails.rb', line 60 def local_host "127.0.0.1" end |
.pending_requests? ⇒ Boolean
Returns true if there are pending requests to server.
74 75 76 |
# File 'lib/watir/rails.rb', line 74 def pending_requests? @middleware.pending_requests? end |
.running? ⇒ Boolean
Check if Rails app under test is running.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/watir/rails.rb', line 108 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 |