From dc3cc7479871776f33c92f22025e70ddea55d595 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Tue, 19 Jul 2016 23:29:00 +0300 Subject: [PATCH] Add more specs to common_exception_handler --- spec/common_exception_handler_spec.cr | 60 +++++++++++++++++---------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/spec/common_exception_handler_spec.cr b/spec/common_exception_handler_spec.cr index 6593959..e7bdd1b 100644 --- a/spec/common_exception_handler_spec.cr +++ b/spec/common_exception_handler_spec.cr @@ -17,25 +17,43 @@ describe "Kemal::CommonExceptionHandler" do 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", "/") - # 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" - # 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", "/") + 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 403 + 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