Class: Kookaburra::RackAppServer
- Inherits:
-
Object
- Object
- Kookaburra::RackAppServer
- Defined in:
- lib/kookaburra/rack_app_server.rb
Overview
Handles Starting/Stopping Rack Server for Tests
RackAppServer is basically a wrapper around Capybara::Server that makes it a bit easier to use Kookaburra with a Rack application (such as Rails or Sinatra) when you want to run your tests locally against a server that is only running for the duration of the tests. You simply tell it how to get ahold of your Rack application (see #initialize) and then call #boot before your tests run and #shutdown after your tests run.
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#boot ⇒ Object
Start the application server.
-
#initialize(startup_timeout = 10, &rack_app_initializer) ⇒ RackAppServer
constructor
Sets up a new app server.
- #shutdown ⇒ Object
Constructor Details
#initialize(startup_timeout = 10, &rack_app_initializer) ⇒ RackAppServer
Sets up a new app server
40 41 42 43 44 |
# File 'lib/kookaburra/rack_app_server.rb', line 40 def initialize(startup_timeout=10, &rack_app_initializer) self.startup_timeout = startup_timeout self.rack_app_initializer = rack_app_initializer self.port = FindAPort.available_port end |
Instance Attribute Details
#port ⇒ Object
Returns the value of attribute port.
33 34 35 |
# File 'lib/kookaburra/rack_app_server.rb', line 33 def port @port end |
Instance Method Details
#boot ⇒ Object
Start the application server
This will launch the server on a (detected to be) available port. It will then monitor that port and only return once the app server is responding (or after the timeout period specified on #initialize).
51 52 53 54 55 56 57 58 |
# File 'lib/kookaburra/rack_app_server.rb', line 51 def boot if defined?(JRUBY_VERSION) thread_app_server else fork_app_server end wait_for_app_to_respond end |
#shutdown ⇒ Object
60 61 62 63 64 |
# File 'lib/kookaburra/rack_app_server.rb', line 60 def shutdown return if defined?(JRUBY_VERSION) Process.kill(9, rack_server_pid) Process.wait end |