shard-kemal/spec/logger_spec.cr

34 lines
891 B
Crystal
Raw Normal View History

2015-10-27 19:01:36 +00:00
require "./spec_helper"
describe "Logger" do
2015-11-20 21:07:10 +00:00
it "creates a handler" do
logger = Kemal::Logger.new
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
logger = Kemal::Logger.new
logger.handler.should be_a IO
end
it "creates a file handler in production" do
config = Kemal.config
config.env = "production"
logger = Kemal::Logger.new
logger.handler.should be_a File
2015-10-27 19:01:36 +00:00
end
2015-11-20 21:07:10 +00:00
2015-11-20 22:43:28 +00:00
#TODO: Check https://github.com/manastech/crystal/issues/1899
2015-11-20 21:07:10 +00:00
it "writes to a file in production" do
config = Kemal.config
config.env = "production"
logger = Kemal::Logger.new
request = HTTP::Request.new("GET", "/?message=world&time=now")
logger.call request
str = File.read("kemal.log")
File.delete("kemal.log")
2015-11-20 22:43:28 +00:00
str.includes?("GET /?message=world&time=now").should eq false
2015-11-20 21:07:10 +00:00
end
2015-10-27 19:01:36 +00:00
end