Add more specs to common_exception_handler
This commit is contained in:
parent
676ed2aa67
commit
dc3cc74798
1 changed files with 39 additions and 21 deletions
|
@ -17,25 +17,43 @@ describe "Kemal::CommonExceptionHandler" do
|
||||||
response.status_code.should eq 404
|
response.status_code.should eq 404
|
||||||
end
|
end
|
||||||
|
|
||||||
# it "renders custom error" do
|
it "renders custom error" do
|
||||||
# error 403 do
|
error 403 do
|
||||||
# "403 error"
|
"403 error"
|
||||||
# end
|
end
|
||||||
#
|
get "/" do |env|
|
||||||
# get "/" do |env|
|
env.response.status_code = 403
|
||||||
# env.response.status_code = 403
|
end
|
||||||
# end
|
request = HTTP::Request.new("GET", "/")
|
||||||
#
|
io = MemoryIO.new
|
||||||
# request = HTTP::Request.new("GET", "/")
|
response = HTTP::Server::Response.new(io)
|
||||||
# io = MemoryIO.new
|
context = HTTP::Server::Context.new(request, response)
|
||||||
# response = HTTP::Server::Response.new(io)
|
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
||||||
# context = HTTP::Server::Context.new(request, response)
|
Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
||||||
# Kemal::RouteHandler::INSTANCE.call(context)
|
response.close
|
||||||
# Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
io.rewind
|
||||||
# response.close
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
||||||
# io.rewind
|
response.status_code.should eq 403
|
||||||
# response = HTTP::Client::Response.from_io(io, decompress: false)
|
response.body.should eq "403 error"
|
||||||
# response.status_code.should eq 403
|
end
|
||||||
# response.body.should eq "403 error"
|
|
||||||
# end
|
it "renders custom 500 error" do
|
||||||
|
error 500 do
|
||||||
|
"Something happened"
|
||||||
|
end
|
||||||
|
get "/" do |env|
|
||||||
|
env.response.status_code = 500
|
||||||
|
end
|
||||||
|
request = HTTP::Request.new("GET", "/")
|
||||||
|
io = MemoryIO.new
|
||||||
|
response = HTTP::Server::Response.new(io)
|
||||||
|
context = HTTP::Server::Context.new(request, response)
|
||||||
|
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
|
||||||
|
Kemal::CommonExceptionHandler::INSTANCE.call(context)
|
||||||
|
response.close
|
||||||
|
io.rewind
|
||||||
|
response = HTTP::Client::Response.from_io(io, decompress: false)
|
||||||
|
response.status_code.should eq 500
|
||||||
|
response.body.should eq "Something happened"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue