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
|
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"
|
|
|
|
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-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
|