kemal/spec/handler_spec.cr
Serdar Dogruyol 922d6de4d1 Middleware ordering (#236)
Improve and correct request middleware

 Request -> Middleware -> Filter -> Route
2016-10-28 11:35:34 +03:00

30 lines
764 B
Crystal

require "./spec_helper"
class CustomTestHandler < HTTP::Handler
def call(env)
env.response << "Kemal"
call_next env
end
end
describe "Handler" do
it "adds custom handler before before_*" do
filter_middleware = Kemal::Middleware::Filter.new
filter_middleware._add_route_filter("GET", "/", :before) do |env|
env.response << " is"
end
filter_middleware._add_route_filter("GET", "/", :before) do |env|
env.response << " so"
end
add_handler CustomTestHandler.new
get "/" do |env|
" Great"
end
request = HTTP::Request.new("GET", "/")
client_response = call_request_on_app(request)
client_response.status_code.should eq(200)
client_response.body.should eq("Kemal is so Great")
end
end