mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
All specs passing except macros
This commit is contained in:
parent
c6e9e7a827
commit
d1f95c0f39
17 changed files with 243 additions and 247 deletions
|
@ -1,46 +1,40 @@
|
|||
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")
|
||||
end
|
||||
|
||||
it "sets content type" do
|
||||
kemal = Kemal::Handler.new
|
||||
kemal.add_route "GET", "/" do |env|
|
||||
env.content_type = "application/json"
|
||||
env.response.content_type = "application/json"
|
||||
"Hello"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/")
|
||||
response = kemal.call(request)
|
||||
response.headers["Content-Type"].should eq("application/json")
|
||||
io_with_context = create_request_and_return_io(kemal, request)
|
||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
client_response.headers["Content-Type"].should eq("application/json")
|
||||
end
|
||||
|
||||
it "parses headers" do
|
||||
kemal = Kemal::Handler.new
|
||||
kemal.add_route "GET", "/" do |env|
|
||||
name = env.headers["name"]
|
||||
name = env.request.headers["name"]
|
||||
"Hello #{name}"
|
||||
end
|
||||
headers = HTTP::Headers.new
|
||||
headers["Name"] = "kemal"
|
||||
headers["name"] = "kemal"
|
||||
request = HTTP::Request.new("GET", "/", headers)
|
||||
response = kemal.call(request)
|
||||
response.body.should eq "Hello kemal"
|
||||
io_with_context = create_request_and_return_io(kemal, request)
|
||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
client_response.body.should eq "Hello kemal"
|
||||
end
|
||||
|
||||
it "sets response headers" do
|
||||
kemal = Kemal::Handler.new
|
||||
kemal.add_route "GET", "/" do |env|
|
||||
env.add_header "Accept-Language", "tr"
|
||||
env.response.headers.add "Accept-Language", "tr"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/")
|
||||
response = kemal.call(request)
|
||||
response.headers["Accept-Language"].should eq "tr"
|
||||
io_with_context = create_request_and_return_io(kemal, request)
|
||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
client_response.headers["Accept-Language"].should eq "tr"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue