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

@ -53,7 +53,7 @@ describe "Your::Kemal::App" do
# You can use get,post,put,patch,delete to call the corresponding route. # You can use get,post,put,patch,delete to call the corresponding route.
it "renders /" do it "renders /" do
response = get "/" get "/"
response.body.should eq "Hello World!" response.body.should eq "Hello World!"
end end

View file

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

View file

@ -4,13 +4,13 @@ describe "SpecKemalApp" do
start start
it "handles get" do it "handles get" do
response = get "/" get "/"
response.body.should eq "Hello world" response.body.should eq "Hello world"
end end
it "handles post" do it "handles post" do
json_body = {"name": "Serdar", "age": 27, "skills": ["crystal, kemal"]} 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) response.body.should eq(json_body.to_json)
end end
end end

View file

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

View file

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