shard-kemal/spec/context_spec.cr

47 lines
1.3 KiB
Crystal
Raw Normal View History

2015-10-28 18:52:34 +00:00
require "./spec_helper"
describe "Context" do
it "has a default content type" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do |env|
"Hello"
end
request = HTTP::Request.new("GET", "/")
response = kemal.call(request)
response.headers["Content-Type"].should eq("text/html")
2015-10-28 18:52:34 +00:00
end
it "sets content type" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do |env|
2015-10-30 20:34:44 +00:00
env.content_type = "application/json"
2015-10-28 18:52:34 +00:00
end
request = HTTP::Request.new("GET", "/")
response = kemal.call(request)
response.headers["Content-Type"].should eq("application/json")
end
2015-10-30 15:06:25 +00:00
it "parses headers" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do |env|
name = env.headers["name"]
"Hello #{name}"
end
headers = HTTP::Headers.new
headers["Name"] = "kemal"
request = HTTP::Request.new("GET", "/", headers)
response = kemal.call(request)
response.body.should eq "Hello kemal"
end
2015-10-30 20:01:18 +00:00
it "sets response headers" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do |env|
2015-10-30 20:34:44 +00:00
env.add_header "Accept-Language", "tr"
2015-10-30 20:01:18 +00:00
end
request = HTTP::Request.new("GET", "/")
response = kemal.call(request)
response.headers["Accept-Language"].should eq "tr"
end
2015-10-28 18:52:34 +00:00
end