kemal/spec/spec_helper.cr

40 lines
812 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-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
Kemal.config.env = "development"
2016-01-03 11:22:43 +00:00
Kemal.config.handlers.clear
2015-11-25 21:35:04 +00:00
end