Class: Watir::Rails
- Inherits:
-
Object
- Object
- Watir::Rails
- Defined in:
- lib/watir/rails.rb,
lib/watir/rails/version.rb,
lib/watir/rails/middleware.rb
Constant Summary collapse
- VERSION =
"2.3.0"
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
16 17 18 |
# File 'lib/watir/rails.rb', line 16 def ignore_exceptions=(value) @ignore_exceptions = value end |
.middleware (readonly)
Returns the value of attribute middleware.
15 16 17 |
# File 'lib/watir/rails.rb', line 15 def middleware @middleware end |
.port (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/watir/rails.rb', line 15 def port @port end |
.server=(value)
Sets the attribute server
16 17 18 |
# File 'lib/watir/rails.rb', line 16 def server=(value) @server = value end |
Class Method Details
.app ⇒ Object
Rails app under test.
113 114 115 116 117 118 119 |
# File 'lib/watir/rails.rb', line 113 def app @app ||= Rack::Builder.new do map "/" do run ::Rails.application end end.to_app end |
.boot(port: nil)
Start the Rails server for tests. Will be called automatically by Browser#initialize.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 ⇒ Exception or NilClass
Error rescued by the middleware.
63 64 65 |
# File 'lib/watir/rails.rb', line 63 def error @middleware.error end |
.error=(value)
Set error rescued by the middleware.
77 78 79 |
# File 'lib/watir/rails.rb', line 77 def error=(value) @middleware.error = value end |
.host ⇒ String
Host for Rails app under test. Default is local_host.
42 43 44 |
# File 'lib/watir/rails.rb', line 42 def host @host || local_host end |
.host=(host)
Set host for Rails app. Will be used by Browser#goto method.
49 50 51 |
# File 'lib/watir/rails.rb', line 49 def host=(host) @host = host end |
.ignore_exceptions? ⇒ Boolean
Check if Rails exceptions should be ignored. Defaults to false.
84 85 86 87 88 89 90 91 92 93 |
# 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 ⇒ String
Local host for Rails app under test.
56 57 58 |
# File 'lib/watir/rails.rb', line 56 def local_host "127.0.0.1" end |
.pending_requests? ⇒ Boolean
Returns true if there are pending requests to server.
70 71 72 |
# File 'lib/watir/rails.rb', line 70 def pending_requests? @middleware.pending_requests? end |
.running? ⇒ Boolean
Check if Rails app under test is running.
98 99 100 101 102 103 104 105 106 107 108 |
# 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 |