2014-10-30 06:25:35 +08:00
|
|
|
"use strict";
|
|
|
|
|
2015-06-09 22:21:03 +08:00
|
|
|
var Registry = lib("registry");
|
2014-10-30 06:25:35 +08:00
|
|
|
|
2014-12-15 07:21:28 +08:00
|
|
|
var path = "./../spec/support/mock_module.js";
|
2014-10-30 06:25:35 +08:00
|
|
|
|
2014-12-16 01:37:52 +08:00
|
|
|
var mod = require("./../support/mock_module.js");
|
2014-10-30 06:25:35 +08:00
|
|
|
|
2014-11-01 05:14:02 +08:00
|
|
|
describe("Registry", function() {
|
2014-10-31 04:15:40 +08:00
|
|
|
var original;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2014-11-01 05:14:02 +08:00
|
|
|
original = Registry.data;
|
|
|
|
Registry.data = {};
|
2014-10-31 04:15:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
2014-11-01 05:14:02 +08:00
|
|
|
Registry.data = original;
|
2014-12-16 01:37:52 +08:00
|
|
|
});
|
2014-10-31 04:15:40 +08:00
|
|
|
|
2014-10-30 06:25:35 +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-10-30 06:25:35 +08:00
|
|
|
|
2014-11-01 05:14:02 +08:00
|
|
|
Registry.register(path);
|
2014-10-30 06:25:35 +08:00
|
|
|
|
2014-11-01 05:14:02 +08:00
|
|
|
expect(Registry.data).to.be.eql({
|
2014-10-30 06:25:35 +08:00
|
|
|
"./../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: []
|
2014-10-30 06:25:35 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-02-21 03:25:31 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2014-10-30 06:25:35 +08:00
|
|
|
});
|
2015-03-10 12:26:45 +08:00
|
|
|
|
|
|
|
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");
|
|
|
|
});
|
|
|
|
});
|
2014-10-30 06:25:35 +08:00
|
|
|
});
|