From f3b6bdadf07631f72dff9f9f9507903a7bf768f2 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Sun, 10 Apr 2016 17:13:25 +0300 Subject: [PATCH] Add specs --- spec/spec-kemal_spec.cr | 15 +++++++++++---- spec/spec_helper.cr | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/spec/spec-kemal_spec.cr b/spec/spec-kemal_spec.cr index 70adcf2..bbf3dc9 100644 --- a/spec/spec-kemal_spec.cr +++ b/spec/spec-kemal_spec.cr @@ -1,9 +1,16 @@ require "./spec_helper" -describe Spec::Kemal do - # TODO: Write tests +describe "SpecKemalApp" do + start - it "works" do - false.should eq(true) + it "handles get" do + response = 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) + response.body.should eq(json_body.to_json) end end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 82a81e1..a3946b8 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -1,2 +1,16 @@ require "spec" +require "kemal" require "../src/spec-kemal" + +# Create a dummy app +get "/" do + "Hello world" +end + +post "/user" do |env| + env.response.content_type = "application/json" + name = env.params.json["name"] + age = env.params.json["age"] as Int + skills = env.params.json["skills"] as Array + {"name": name, "age": age, "skills": skills}.to_json +end