Refactor global namespace DSL into OOP Kemal::Base

This commit is contained in:
Johannes Müller 2017-07-16 19:16:12 +02:00 committed by sdogruyol
parent a5d8df7382
commit aaa2109837
25 changed files with 420 additions and 387 deletions

View file

@ -1,5 +1,7 @@
require "spec"
require "../src/*"
require "../src/**"
require "../src/kemal/base"
require "../src/kemal/dsl"
include Kemal
@ -33,6 +35,7 @@ def create_request_and_return_io_and_context(handler, request)
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
context.app = Kemal.application
handler.call(context)
response.close
io.rewind
@ -43,6 +46,7 @@ def create_ws_request_and_return_io_and_context(handler, request)
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
context.app = Kemal.application
begin
handler.call context
rescue IO::Error
@ -64,10 +68,10 @@ def call_request_on_app(request)
end
def build_main_handler
Kemal.config.setup
main_handler = Kemal.config.handlers.first
Kemal.application.setup
main_handler = Kemal.application.handlers.first
current_handler = main_handler
Kemal.config.handlers.each do |handler|
Kemal.application.handlers.each_with_index do |handler, index|
current_handler.next = handler
current_handler = handler
end
@ -81,8 +85,5 @@ Spec.before_each do
end
Spec.after_each do
Kemal.config.clear
Kemal::RouteHandler::INSTANCE.routes = Radix::Tree(Route).new
Kemal::RouteHandler::INSTANCE.cached_routes = Hash(String, Radix::Result(Route)).new
Kemal::WebSocketHandler::INSTANCE.routes = Radix::Tree(WebSocket).new
Kemal.application.clear
end