cylon/spec/lib/registry.spec.js

73 lines
1.7 KiB
JavaScript
Raw Normal View History

"use strict";
var Registry = lib("registry");
2014-12-15 07:21:28 +08:00
var path = "./../spec/support/mock_module.js";
2014-12-16 01:37:52 +08:00
var mod = require("./../support/mock_module.js");
2014-11-01 05:14:02 +08:00
describe("Registry", function() {
var original;
beforeEach(function() {
2014-11-01 05:14:02 +08:00
original = Registry.data;
Registry.data = {};
});
afterEach(function() {
2014-11-01 05:14:02 +08:00
Registry.data = original;
2014-12-16 01:37:52 +08:00
});
describe("#register", function() {
it("adds the supplied module to the Registry", function() {
2014-11-01 05:14:02 +08:00
expect(Registry.data).to.be.eql({});
2014-11-01 05:14:02 +08:00
Registry.register(path);
2014-11-01 05:14:02 +08:00
expect(Registry.data).to.be.eql({
"./../spec/support/mock_module.js": {
2014-12-16 01:37:52 +08:00
module: mod,
2014-12-15 07:21:28 +08:00
drivers: ["test-driver"],
adaptors: ["test-adaptor"],
2014-11-06 06:24:07 +08:00
dependencies: []
}
});
});
context("when the module already exists", function() {
it("returns the module", function() {
expect(Registry.data).to.be.eql({});
var result = Registry.register(path);
// should register the module and return it
expect(result).to.be.eql(mod);
result = Registry.register(path);
// should just return the existing module
expect(result).to.be.eql(mod);
});
});
});
describe("#findBy", function() {
beforeEach(function() {
stub(Registry, "search");
});
afterEach(function() {
Registry.search.restore();
});
it("calls #search, pluralizing if necessary", function() {
Registry.findBy("adaptors", "testing");
expect(Registry.search).to.be.calledWith("adaptors", "testing");
Registry.findBy("driver", "testing");
expect(Registry.search).to.be.calledWith("drivers", "testing");
});
});
});