This commit is contained in:
Serdar Dogruyol 2016-04-18 16:51:50 +03:00
parent 4abdf39037
commit 8c0d4268b9
5 changed files with 13 additions and 7 deletions

View File

@ -50,10 +50,10 @@ Now you can easily test your `Kemal` application in your `spec`s.
describe "Your::Kemal::App" do
# Be sure to start your app in test mode
start
# You can use get,post,put,patch,delete to call the corresponding route.
it "renders /" do
response = get "/"
get "/"
response.body.should eq "Hello World!"
end

View File

@ -1,5 +1,5 @@
name: spec-kemal
version: 0.1.0
version: 0.2.0
dependencies:
kemal:

View File

@ -4,13 +4,13 @@ describe "SpecKemalApp" do
start
it "handles get" do
response = get "/"
get "/"
response.body.should eq "Hello world"
end
it "handles post" do
json_body = {"name": "Serdar", "age": 27, "skills": ["crystal, kemal"]}
response = post("/user", headers: HTTP::Headers{"Content-Type": "application/json"}, body: json_body.to_json)
post("/user", headers: HTTP::Headers{"Content-Type": "application/json"}, body: json_body.to_json)
response.body.should eq(json_body.to_json)
end
end

View File

@ -12,6 +12,8 @@ Kemal.config.host_binding = APP_HOST_BINDING
Kemal.config.port = APP_PORT
Kemal.config.logging = false
$response : HTTP::Client::Response?
def start
spawn do
Kemal.run
@ -27,6 +29,10 @@ 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)
$response = HTTP::Client.{{method.id}}(APP_URL + path, headers, body)
end
{% end %}
def response
$response.not_nil!
end

View File

@ -1,3 +1,3 @@
module Spec::Kemal
VERSION = "0.1.0"
VERSION = "0.2.0"
end