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