shard-kemal/spec/logger_spec.cr

37 lines
1 KiB
Crystal
Raw Normal View History

2015-10-27 19:01:36 +00:00
require "./spec_helper"
2016-02-03 20:08:54 +00:00
describe "Kemal::LogHandler" do
2015-11-20 21:07:10 +00:00
it "creates a handler" do
2016-02-11 21:26:47 +00:00
logger = Kemal::LogHandler.new "production"
2015-11-20 21:07:10 +00:00
logger.handler.should_not be nil
end
2015-11-18 20:45:49 +00:00
it "creates a STDOUT handler by default" do
config = Kemal.config
2016-02-11 21:26:47 +00:00
logger = Kemal::LogHandler.new "production"
2015-11-18 20:45:49 +00:00
logger.handler.should be_a IO
end
it "creates a file handler in production" do
config = Kemal.config
config.env = "production"
2016-02-11 21:26:47 +00:00
logger = Kemal::LogHandler.new "production"
2015-11-18 20:45:49 +00:00
logger.handler.should be_a File
2015-10-27 19:01:36 +00:00
end
2016-01-08 16:44:37 +00:00
2015-11-20 21:07:10 +00:00
it "writes to a file in production" do
config = Kemal.config
config.env = "production"
2016-02-11 21:26:47 +00:00
logger = Kemal::LogHandler.new "production"
2015-11-20 21:07:10 +00:00
request = HTTP::Request.new("GET", "/?message=world&time=now")
2016-01-24 10:22:25 +00:00
io = MemoryIO.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
logger.call(context)
response.close
2015-11-20 21:07:10 +00:00
str = File.read("kemal.log")
File.delete("kemal.log")
2015-11-21 20:46:37 +00:00
str.includes?("GET /?message=world&time=now").should eq true
2015-11-20 21:07:10 +00:00
end
2015-10-27 19:01:36 +00:00
end