kemal/spec/context_spec.cr

44 lines
1.2 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
2016-03-21 16:29:48 +00:00
get "/" do |env|
2016-01-24 15:44:37 +00:00
"Hello"
end
request = HTTP::Request.new("GET", "/")
2016-03-21 16:29:48 +00:00
client_response = call_request_on_app(request)
2016-01-24 15:44:37 +00:00
client_response.headers["Content-Type"].should eq("text/html")
end
2015-10-28 18:52:34 +00:00
it "sets content type" do
2016-03-21 16:29:48 +00:00
get "/" do |env|
2016-01-24 10:22:25 +00:00
env.response.content_type = "application/json"
"Hello"
2015-10-28 18:52:34 +00:00
end
request = HTTP::Request.new("GET", "/")
2016-03-21 16:29:48 +00:00
client_response = call_request_on_app(request)
2016-01-24 10:22:25 +00:00
client_response.headers["Content-Type"].should eq("application/json")
2015-10-28 18:52:34 +00:00
end
2015-10-30 15:06:25 +00:00
it "parses headers" do
2016-03-21 16:29:48 +00:00
get "/" do |env|
2016-01-24 10:22:25 +00:00
name = env.request.headers["name"]
2015-10-30 15:06:25 +00:00
"Hello #{name}"
end
headers = HTTP::Headers.new
2016-01-24 10:22:25 +00:00
headers["name"] = "kemal"
2015-10-30 15:06:25 +00:00
request = HTTP::Request.new("GET", "/", headers)
2016-03-21 16:29:48 +00:00
client_response = call_request_on_app(request)
2016-01-24 10:22:25 +00:00
client_response.body.should eq "Hello kemal"
2015-10-30 15:06:25 +00:00
end
2015-10-30 20:01:18 +00:00
it "sets response headers" do
2016-03-21 16:29:48 +00:00
get "/" do |env|
2016-01-24 10:22:25 +00:00
env.response.headers.add "Accept-Language", "tr"
2015-10-30 20:01:18 +00:00
end
request = HTTP::Request.new("GET", "/")
2016-03-21 16:29:48 +00:00
client_response = call_request_on_app(request)
2016-01-24 10:22:25 +00:00
client_response.headers["Accept-Language"].should eq "tr"
2015-10-30 20:01:18 +00:00
end
2015-10-28 18:52:34 +00:00
end