2009-01-19 20:58:26 -05:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
|
|
|
|
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
|
2009-01-19 20:58:26 -05:00
|
|
|
mock_app {
|
|
|
|
set :server, 'mock'
|
|
|
|
set :host, 'foo.local'
|
|
|
|
set :port, 9001
|
|
|
|
}
|
|
|
|
$stdout = File.open('/dev/null', 'wb')
|
|
|
|
end
|
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
def teardown
|
|
|
|
$stdout = STDOUT
|
|
|
|
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
|