2016-03-18 18:03:04 +00:00
|
|
|
require "./spec_helper"
|
|
|
|
|
|
|
|
describe "Kemal::CommonExceptionHandler" do
|
2016-07-03 09:13:11 +00:00
|
|
|
it "renders 404 on route not found" do
|
|
|
|
get "/" do |env|
|
|
|
|
"Hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
request = HTTP::Request.new("GET", "/asd")
|
|
|
|
io = MemoryIO.new
|
|
|
|
response = HTTP::Server::Response.new(io)
|
|
|
|
context = HTTP::Server::Context.new(request, response)
|
|
|
|
Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
|
|
|
response.close
|
|
|
|
io.rewind
|
|
|
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
|
|
|
response.status_code.should eq 404
|
|
|
|
end
|
|
|
|
|
2016-05-05 20:12:17 +00:00
|
|
|
# it "renders custom error" do
|
|
|
|
# error 403 do
|
|
|
|
# "403 error"
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# get "/" do |env|
|
|
|
|
# env.response.status_code = 403
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# request = HTTP::Request.new("GET", "/")
|
2016-07-03 09:13:11 +00:00
|
|
|
# io = MemoryIO.new
|
|
|
|
# response = HTTP::Server::Response.new(io)
|
|
|
|
# context = HTTP::Server::Context.new(request, response)
|
|
|
|
# Kemal::RouteHandler::INSTANCE.call(context)
|
|
|
|
# Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
|
|
|
# response.close
|
|
|
|
# io.rewind
|
|
|
|
# response = HTTP::Client::Response.from_io(io, decompress: false)
|
|
|
|
# response.status_code.should eq 403
|
|
|
|
# response.body.should eq "403 error"
|
2016-05-05 20:12:17 +00:00
|
|
|
# end
|
2016-03-18 18:03:04 +00:00
|
|
|
end
|