spec-kemal/src/spec-kemal.cr

33 lines
687 B
Crystal
Raw Normal View History

2016-04-09 14:37:46 +00:00
require "spec"
require "kemal"
2016-04-10 11:24:19 +00:00
TIME_TO_SLEEP = 0.00001
APP_HOST_BINDING = "127.0.0.1"
2016-04-10 11:24:19 +00:00
APP_PORT = 1989
APP_ENV = "test"
APP_URL = "http://localhost:#{APP_PORT}"
2016-04-10 11:24:19 +00:00
Kemal.config.env = APP_ENV
Kemal.config.host_binding = APP_HOST_BINDING
2016-04-10 11:24:19 +00:00
Kemal.config.port = APP_PORT
2016-04-16 21:13:12 +00:00
Kemal.config.logging = false
2016-04-09 14:37:46 +00:00
def start
2016-04-09 14:37:46 +00:00
spawn do
Kemal.run
2016-04-16 21:13:12 +00:00
Kemal.config.server.not_nil!.listen
2016-04-09 14:37:46 +00:00
end
2016-04-10 11:24:19 +00:00
sleep TIME_TO_SLEEP
2016-04-09 14:37:46 +00:00
end
def stop
2016-04-16 21:13:12 +00:00
Kemal.config.server.not_nil!.close
sleep TIME_TO_SLEEP
2016-04-09 14:37:46 +00:00
end
{% for method in %w(get post put head delete patch) %}
def {{method.id}}(path, headers : HTTP::Headers? = nil, body : String? = nil)
HTTP::Client.{{method.id}}(APP_URL + path, headers, body)
end
{% end %}