2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2011-06-16 08:02:52 -04:00
|
|
|
require 'stringio'
|
2009-01-19 20:58:26 -05:00
|
|
|
|
2009-05-20 21:13:38 -04:00
|
|
|
module Rack::Handler
|
|
|
|
class Mock
|
|
|
|
extend Test::Unit::Assertions
|
|
|
|
|
|
|
|
def self.run(app, options={})
|
|
|
|
assert(app < Sinatra::Base)
|
|
|
|
assert_equal 9001, options[:Port]
|
|
|
|
assert_equal 'foo.local', options[:Host]
|
|
|
|
yield new
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
end
|
2009-01-19 20:58:26 -05:00
|
|
|
end
|
|
|
|
|
2009-05-20 21:13:38 -04:00
|
|
|
register 'mock', 'Rack::Handler::Mock'
|
2009-01-19 20:58:26 -05:00
|
|
|
end
|
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
class ServerTest < Test::Unit::TestCase
|
|
|
|
setup do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
2009-01-19 20:58:26 -05:00
|
|
|
set :server, 'mock'
|
2010-02-04 20:16:05 -05:00
|
|
|
set :bind, 'foo.local'
|
2009-01-19 20:58:26 -05:00
|
|
|
set :port, 9001
|
2012-05-21 17:21:59 -04:00
|
|
|
end
|
2011-06-16 08:02:52 -04:00
|
|
|
$stderr = StringIO.new
|
2009-01-19 20:58:26 -05:00
|
|
|
end
|
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
def teardown
|
2011-06-16 08:02:52 -04:00
|
|
|
$stderr = STDERR
|
2009-03-26 11:42:13 -04:00
|
|
|
end
|
2009-01-19 20:58:26 -05:00
|
|
|
|
|
|
|
it "locates the appropriate Rack handler and calls ::run" do
|
|
|
|
@app.run!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets options on the app before running" do
|
|
|
|
@app.run! :sessions => true
|
|
|
|
assert @app.sessions?
|
|
|
|
end
|
|
|
|
|
|
|
|
it "falls back on the next server handler when not found" do
|
|
|
|
@app.run! :server => %w[foo bar mock]
|
|
|
|
end
|
|
|
|
end
|