This extension is part of the Sinatra::Contrib project. Run gem install sinatra-contrib to have it available.
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.expand_path("server.rb", __dir__) 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!**
Wherever 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