2016-01-03 11:22:43 +00:00
|
|
|
require "./spec_helper"
|
|
|
|
|
|
|
|
describe "Macros" do
|
|
|
|
describe "#basic_auth" do
|
|
|
|
it "adds HTTPBasicAuthHandler" do
|
|
|
|
basic_auth "serdar", "123"
|
2016-03-21 16:29:48 +00:00
|
|
|
Kemal.config.handlers.size.should eq 5
|
2016-01-03 11:22:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#public_folder" do
|
|
|
|
it "sets public folder" do
|
|
|
|
public_folder "/some/path/to/folder"
|
|
|
|
Kemal.config.public_folder.should eq("/some/path/to/folder")
|
|
|
|
end
|
|
|
|
end
|
2016-01-05 12:20:40 +00:00
|
|
|
|
|
|
|
describe "#add_handler" do
|
|
|
|
it "adds a custom handler" do
|
|
|
|
add_handler CustomTestHandler.new
|
2016-03-21 16:29:48 +00:00
|
|
|
Kemal.config.handlers.size.should eq 5
|
2016-01-05 12:20:40 +00:00
|
|
|
end
|
|
|
|
end
|
2016-01-17 11:08:12 +00:00
|
|
|
|
|
|
|
describe "#logging" do
|
|
|
|
it "sets logging status" do
|
|
|
|
logging false
|
|
|
|
Kemal.config.logging.should eq false
|
|
|
|
end
|
2016-02-12 14:09:15 +00:00
|
|
|
it "sets a custom logger" do
|
|
|
|
config = Kemal::Config::INSTANCE
|
2016-07-05 19:14:00 +00:00
|
|
|
logger CustomLogHandler.new
|
2016-03-21 16:29:48 +00:00
|
|
|
config.handlers.last.should be_a(CustomLogHandler)
|
2016-02-12 14:09:15 +00:00
|
|
|
config.logger.should be_a(CustomLogHandler)
|
|
|
|
end
|
2016-01-17 11:08:12 +00:00
|
|
|
end
|
2016-03-29 21:48:58 +00:00
|
|
|
|
|
|
|
describe "#return_with" do
|
|
|
|
it "can break block with return_with macro" do
|
|
|
|
get "/non-breaking" do |env|
|
|
|
|
"hello"
|
|
|
|
"world"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/non-breaking")
|
|
|
|
client_response = call_request_on_app(request)
|
|
|
|
client_response.status_code.should eq(200)
|
|
|
|
client_response.body.should eq("world")
|
|
|
|
|
|
|
|
get "/breaking" do |env|
|
|
|
|
return_with env, 404, "hello"
|
|
|
|
"world"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/breaking")
|
|
|
|
client_response = call_request_on_app(request)
|
|
|
|
client_response.status_code.should eq(404)
|
|
|
|
client_response.body.should eq("hello")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can break block with return_with macro using default values" do
|
|
|
|
get "/" do |env|
|
|
|
|
return_with env
|
|
|
|
"world"
|
|
|
|
end
|
|
|
|
request = HTTP::Request.new("GET", "/")
|
|
|
|
client_response = call_request_on_app(request)
|
|
|
|
client_response.status_code.should eq(200)
|
|
|
|
client_response.body.should eq("")
|
|
|
|
end
|
|
|
|
end
|
2016-06-16 14:05:28 +00:00
|
|
|
|
|
|
|
describe "#headers" do
|
|
|
|
it "can add headers" do
|
|
|
|
get "/headers" do |env|
|
|
|
|
env.response.headers.add "Content-Type", "image/png"
|
|
|
|
headers env, {
|
|
|
|
"Access-Control-Allow-Origin" => "*",
|
2016-07-17 11:31:45 +00:00
|
|
|
"Content-Type" => "text/plain",
|
2016-06-16 14:05:28 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
request = HTTP::Request.new("GET", "/headers")
|
|
|
|
response = call_request_on_app(request)
|
|
|
|
response.headers["Access-Control-Allow-Origin"].should eq("*")
|
|
|
|
response.headers["Content-Type"].should eq("text/plain")
|
|
|
|
end
|
|
|
|
end
|
2016-01-03 11:22:43 +00:00
|
|
|
end
|