mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
67 lines
1.2 KiB
Ruby
67 lines
1.2 KiB
Ruby
![]() |
require 'test/unit'
|
||
|
require 'mongrel'
|
||
|
require 'rack/lint'
|
||
|
require 'test/testhelp'
|
||
|
|
||
|
class TestRackServer < Test::Unit::TestCase
|
||
|
|
||
|
class ErrorChecker
|
||
|
def initialize(app)
|
||
|
@app = app
|
||
|
@exception = nil
|
||
|
@env = nil
|
||
|
end
|
||
|
|
||
|
attr_reader :exception, :env
|
||
|
|
||
|
def call(env)
|
||
|
begin
|
||
|
@env = env
|
||
|
return @app.call(env)
|
||
|
rescue Exception => e
|
||
|
@exception = e
|
||
|
|
||
|
[
|
||
|
500,
|
||
|
{ "X-Exception" => e.message, "X-Exception-Class" => e.class.to_s },
|
||
|
["Error detected"]
|
||
|
]
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
class ServerLint < Rack::Lint
|
||
|
def call(env)
|
||
|
assert("No env given") { env }
|
||
|
check_env env
|
||
|
|
||
|
@app.call(env)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def setup
|
||
|
@valid_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\n\r\n"
|
||
|
|
||
|
@server = Mongrel::RackServer.new("127.0.0.1", 9998)
|
||
|
@simple = lambda { |env| [200, { "X-Header" => "Works" }, "Hello"] }
|
||
|
@server.app = @simple
|
||
|
end
|
||
|
|
||
|
def teardown
|
||
|
@server.stop(true)
|
||
|
end
|
||
|
|
||
|
def test_lint
|
||
|
@checker = ErrorChecker.new ServerLint.new(@simple)
|
||
|
@server.app = @checker
|
||
|
|
||
|
@server.run
|
||
|
|
||
|
hit(['http://localhost:9998/test'])
|
||
|
|
||
|
if exc = @checker.exception
|
||
|
raise exc
|
||
|
end
|
||
|
end
|
||
|
end
|