cylon/spec/lib/logger.spec.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-12-15 07:21:28 +08:00
"use strict";
2014-05-25 01:34:19 +08:00
var Logger = lib("logger"),
Config = lib("config");
2013-10-25 05:25:42 +08:00
2014-12-15 07:21:28 +08:00
describe("Logger", function() {
2014-07-05 00:49:29 +08:00
afterEach(function() {
// to be friendly to other specs
Config.logger = false;
Config.silent = false;
Logger.setup();
2013-10-25 05:25:42 +08:00
});
2014-03-22 07:15:13 +08:00
describe("#setup", function() {
context("with no arguments", function() {
it("sets up a BasicLogger", function() {
Config.logger = null;
2014-03-22 07:15:13 +08:00
Logger.setup();
expect(Logger.logger.name).to.be.eql("basiclogger");
2014-03-22 07:15:13 +08:00
});
});
2014-02-28 06:52:25 +08:00
2014-03-22 07:15:13 +08:00
context("with false", function() {
it("sets up a NullLogger", function() {
Config.logger = false;
Logger.setup();
expect(Logger.logger.name).to.be.eql("nulllogger");
2014-03-22 07:15:13 +08:00
});
});
context("with a custom logger", function() {
it("uses the custom logger", function() {
function customlogger() {}
Config.logger = customlogger;
Logger.setup();
expect(Logger.logger.name).to.be.eql("customlogger");
});
});
2014-02-28 06:52:25 +08:00
});
2014-03-22 07:15:13 +08:00
describe("proxies", function() {
2014-07-05 00:49:29 +08:00
var logger;
beforeEach(function() {
logger = spy();
Logger.logger = logger;
2014-03-22 07:15:13 +08:00
});
describe("#debug", function() {
it("proxies to the logger method", function() {
Logger.should.debug = true;
Logger.debug("debug message");
Logger.should.debug = false;
expect(logger).to.be.calledWith("debug message");
2014-03-22 07:15:13 +08:00
});
});
describe("#log", function() {
it("proxies to the logger method", function() {
Logger.log("log message");
expect(logger).to.be.calledWith("log message");
2014-03-22 07:15:13 +08:00
});
});
2014-10-27 23:59:36 +08:00
});
it("automatically updates if configuration changed", function() {
var custom = spy();
expect(Logger.logger.name).to.be.eql("basiclogger");
Config.update({ logger: custom });
expect(Logger.logger).to.be.eql(custom);
});
2014-02-28 06:52:25 +08:00
});