kemal/spec/spec_helper.cr

45 lines
955 B
Crystal
Raw Normal View History

2014-06-11 23:41:02 +00:00
require "spec"
2015-10-23 18:33:26 +00:00
require "../src/kemal/*"
2015-12-27 09:53:54 +00:00
require "../src/kemal/middleware/*"
2014-06-11 23:41:02 +00:00
2015-10-23 18:33:26 +00:00
include Kemal
2015-11-25 21:35:04 +00:00
2016-01-05 12:20:40 +00:00
class CustomTestHandler < HTTP::Handler
def call(request)
call_next request
end
end
2016-02-12 12:11:21 +00:00
class CustomLogHandler < Kemal::BaseLogHandler; end
2016-01-24 10:22:25 +00:00
def create_request_and_return_io(handler, request)
io = MemoryIO.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
handler.call(context)
response.close
io.rewind
io
end
def create_ws_request_and_return_io(handler, request)
io = MemoryIO.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
begin
handler.call context
rescue IO::Error
# Raises because the MemoryIO is empty
end
response.close
io
end
2015-11-25 21:35:04 +00:00
Spec.before_each do
2016-02-12 12:11:21 +00:00
config = Kemal.config
config.env = "development"
config.setup_logging
config.handlers.clear
Kemal::RouteHandler::INSTANCE.tree = Radix::Tree.new
2015-11-25 21:35:04 +00:00
end