Improve specs for Logger

This commit is contained in:
Andrew Stewart 2014-03-21 16:15:13 -07:00
parent cb35cf27a5
commit 26b92987a8
1 changed files with 69 additions and 25 deletions

View File

@ -2,36 +2,80 @@
source('logger');
describe('Logger', function() {
it("sets to NullLogger if false is provided", function() {
Logger.setup(false);
Logger.toString().should.be.equal("NullLogger");
after(function() {
Logger.setup(false); // to be friendly to other specs
});
it("sets to BasicLogger if nothing is provided", function() {
Logger.setup();
Logger.toString().should.be.equal("BasicLogger");
describe("#setup", function() {
context("with no arguments", function() {
it("sets up a BasicLogger", function() {
Logger.setup();
expect(Logger.toString()).to.be.eql("BasicLogger");
});
});
context("with false", function() {
it("sets up a NullLogger", function() {
Logger.setup(false);
expect(Logger.toString()).to.be.eql("NullLogger");
});
});
context("with a custom logger", function() {
it("uses the custom logger", function() {
var logger = { toString: function() { return "custom"; } };
Logger.setup(logger);
expect(Logger.toString()).to.be.eql("custom");
});
});
});
it("allows for custom loggers", function() {
var logger;
logger = {
toString: function() {
return "CustomLogger";
}
describe("proxies", function() {
var logger = {
debug: spy(),
info: spy(),
warn: spy(),
error: spy(),
fatal: spy()
};
Logger.setup(logger);
Logger.toString().should.be.equal("CustomLogger");
});
it('passes all received args to loggers', function() {
var logger;
logger = {
debug: function(message, level) {
return "Debug Level " + level + ": " + message;
}
};
Logger.setup(logger);
Logger.debug("demo", 4).should.be.equal("Debug Level 4: demo");
return Logger.setup(false);
before(function() {
Logger.setup(logger);
});
describe("#debug", function() {
it("proxies to the Logger's #debug method", function() {
Logger.debug("Hello", "World");
expect(logger.debug).to.be.calledWith("Hello", "World");
});
});
describe("#info", function() {
it("proxies to the Logger's #info method", function() {
Logger.info("Hello", "World");
expect(logger.info).to.be.calledWith("Hello", "World");
});
});
describe("#warn", function() {
it("proxies to the Logger's #warn method", function() {
Logger.warn("Hello", "World");
expect(logger.warn).to.be.calledWith("Hello", "World");
});
});
describe("#error", function() {
it("proxies to the Logger's #error method", function() {
Logger.error("Hello", "World");
expect(logger.error).to.be.calledWith("Hello", "World");
});
});
describe("#fatal", function() {
it("proxies to the Logger's #fatal method", function() {
Logger.fatal("Hello", "World");
expect(logger.fatal).to.be.calledWith("Hello", "World");
});
});
});
});