mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
39 lines
812 B
Crystal
39 lines
812 B
Crystal
require "spec"
|
|
require "../src/kemal/*"
|
|
require "../src/kemal/middleware/*"
|
|
|
|
include Kemal
|
|
|
|
class CustomTestHandler < HTTP::Handler
|
|
def call(request)
|
|
call_next request
|
|
end
|
|
end
|
|
|
|
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
|
|
|
|
Spec.before_each do
|
|
Kemal.config.env = "development"
|
|
Kemal.config.handlers.clear
|
|
end
|