Class: Watir::Rack
- Inherits:
-
Object
- Object
- Watir::Rack
- Defined in:
- lib/watir/rack.rb,
lib/watir/version.rb,
lib/watir/rack/middleware.rb
Constant Summary collapse
- VERSION =
"0.1"
Class Attribute Summary collapse
-
.middleware
readonly
Returns the value of attribute middleware.
-
.port
Returns the value of attribute port.
-
.server
writeonly
Sets the attribute server.
-
.test_app
Returns the value of attribute test_app.
Class Method Summary collapse
-
.app ⇒ Object
Rack app under test.
-
.boot(port: nil)
Start the Rack Will be called automatically by Browser#initialize.
-
.error ⇒ Exception or NilClass
Error rescued by the middleware.
-
.error=(value)
Set error rescued by the middleware.
-
.host ⇒ String
Host for Rack app under test.
-
.host=(host)
Set host for Rack app.
-
.local_host ⇒ String
Local host for Rack app under test.
-
.pending_requests? ⇒ Boolean
Returns true if there are pending requests to server.
-
.running? ⇒ Boolean
Check if Rack app under test is running.
Class Attribute Details
.middleware (readonly)
Returns the value of attribute middleware.
14 15 16 |
# File 'lib/watir/rack.rb', line 14 def middleware @middleware end |
.port
Returns the value of attribute port.
14 15 16 |
# File 'lib/watir/rack.rb', line 14 def port @port end |
.server=(value)
Sets the attribute server
15 16 17 |
# File 'lib/watir/rack.rb', line 15 def server=(value) @server = value end |
.test_app
Returns the value of attribute test_app.
13 14 15 |
# File 'lib/watir/rack.rb', line 13 def test_app @test_app end |
Class Method Details
.app ⇒ Object
Rack app under test.
97 98 99 100 101 102 103 104 105 |
# File 'lib/watir/rack.rb', line 97 def app test_app = self.test_app @app ||= ::Rack::Builder.new do map "/" do run test_app end end.to_app end |
.boot(port: nil)
Start the Rack Will be called automatically by Browser#initialize.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 ⇒ Exception or NilClass
Error rescued by the middleware.
61 62 63 |
# File 'lib/watir/rack.rb', line 61 def error @middleware.error end |
.error=(value)
Set error rescued by the middleware.
75 76 77 |
# File 'lib/watir/rack.rb', line 75 def error=(value) @middleware.error = value end |
.host ⇒ String
Host for Rack app under test. Default is local_host.
40 41 42 |
# File 'lib/watir/rack.rb', line 40 def host @host || local_host end |
.host=(host)
Set host for Rack app. Will be used by Browser#goto method.
47 48 49 |
# File 'lib/watir/rack.rb', line 47 def host=(host) @host = host end |
.local_host ⇒ String
Local host for Rack app under test.
54 55 56 |
# File 'lib/watir/rack.rb', line 54 def local_host "127.0.0.1" end |
.pending_requests? ⇒ Boolean
Returns true if there are pending requests to server.
68 69 70 |
# File 'lib/watir/rack.rb', line 68 def pending_requests? @middleware.pending_requests? end |
.running? ⇒ Boolean
Check if Rack app under test is running.
82 83 84 85 86 87 88 89 90 91 92 |
# 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 |