Module: Sinatra
- Defined in:
- lib/sinatra/runner.rb,
lib/sinatra/json.rb,
lib/sinatra/webdav.rb,
lib/sinatra/capture.rb,
lib/sinatra/contrib.rb,
lib/sinatra/cookies.rb,
lib/sinatra/reloader.rb,
lib/sinatra/extension.rb,
lib/sinatra/namespace.rb,
lib/sinatra/streaming.rb,
lib/sinatra/config_file.rb,
lib/sinatra/content_for.rb,
lib/sinatra/link_header.rb,
lib/sinatra/multi_route.rb,
lib/sinatra/respond_with.rb,
lib/sinatra/test_helpers.rb,
lib/sinatra/contrib/setup.rb,
lib/sinatra/custom_logger.rb,
lib/sinatra/contrib/version.rb,
lib/sinatra/engine_tracking.rb,
lib/sinatra/required_params.rb
Overview
NOTE: This feature is experimental, and missing tests!
Helps you spinning up and shutting down your own sinatra app. This is especially helpful for running real network tests against a sinatra backend.
The backend server could look like the following (in test/server.rb).
require "sinatra"
get "/" do
"Cheers from test server"
end
get "/ping" do
"1"
end
Note that you need to implement a ping action for internal use.
Next, you need to write your runner.
require 'sinatra/runner'
class Runner < Sinatra::Runner
def app_file
File.("../server.rb", __FILE__)
end
end
Override Runner#app_file, #command, #port, #protocol and #ping_path for customization.
**Don’t forget to override #app_file specific to your application!**
Whereever you need this test backend, here’s how you manage it. The following example assumes you have a test in your app that needs to be run against your test backend.
runner = ServerRunner.new
runner.run
# ..tests against localhost:4567 here..
runner.kill
For an example, check github.com/apotonick/roar/blob/master/test/integration/runner.rb
Defined Under Namespace
Modules: Capture, ConfigFile, ContentFor, Contrib, Cookies, CustomLogger, EngineTracking, Extension, JSON, LinkHeader, MultiRoute, Namespace, Reloader, RequiredParams, RespondWith, Streaming, TestHelpers, WebDAV Classes: Runner