Add macro specs

This commit is contained in:
sdogruyol 2016-01-03 13:22:43 +02:00
parent 806b129b1c
commit c21567fe17
5 changed files with 20 additions and 6 deletions

View file

@ -28,9 +28,4 @@ describe "Config" do
config.add_handler CustomTestHandler.new config.add_handler CustomTestHandler.new
config.handlers.size.should eq(1) config.handlers.size.should eq(1)
end end
it "sets public folder" do
public_folder "/some/path/to/folder"
Kemal.config.public_folder.should eq("/some/path/to/folder")
end
end end

View file

@ -18,6 +18,7 @@ describe "Logger" do
logger = Kemal::Logger.new logger = Kemal::Logger.new
logger.handler.should be_a File logger.handler.should be_a File
end end
it "writes to a file in production" do it "writes to a file in production" do
config = Kemal.config config = Kemal.config
config.env = "production" config.env = "production"

17
spec/macros_spec.cr Normal file
View file

@ -0,0 +1,17 @@
require "./spec_helper"
describe "Macros" do
describe "#basic_auth" do
it "adds HTTPBasicAuthHandler" do
basic_auth "serdar", "123"
Kemal.config.handlers.size.should eq 1
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
end

View file

@ -6,4 +6,5 @@ include Kemal
Spec.before_each do Spec.before_each do
Kemal.config.env = "development" Kemal.config.env = "development"
Kemal.config.handlers.clear
end end

View file

@ -23,7 +23,7 @@ end
# Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support. # Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support.
macro basic_auth(username, password) macro basic_auth(username, password)
auth_handler = Kemal::Middleware::HTTPBasicAuth.new(username, password) auth_handler = Kemal::Middleware::HTTPBasicAuth.new({{username}}, {{password}})
Kemal.config.add_handler auth_handler Kemal.config.add_handler auth_handler
end end