Start implementing error block

This commit is contained in:
sdogruyol 2016-05-05 22:35:36 +03:00
parent 35239dfaa0
commit e6d9311895
7 changed files with 71 additions and 25 deletions

View file

@ -2,10 +2,27 @@ require "./spec_helper"
describe "Kemal::CommonExceptionHandler" do
it "renders 404 on route not found" do
common_exception_handler = Kemal::CommonExceptionHandler::INSTANCE
request = HTTP::Request.new("GET", "/?message=world")
io_with_context = create_request_and_return_io(common_exception_handler, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
get "/" do |env|
"Hello"
end
request = HTTP::Request.new("GET", "/asd")
client_response = call_request_on_app(request)
client_response.status_code.should eq 404
end
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", "/")
client_response = call_request_on_app(request)
client_response.status_code.should eq 403
client_response.body.should eq "403 error"
end
end