2014-02-28 04:10:00 +08:00
|
|
|
'use strict';
|
2013-12-19 04:26:21 +08:00
|
|
|
|
2014-02-28 04:10:00 +08:00
|
|
|
var EventEmitter = require('events').EventEmitter;
|
2013-12-16 10:18:22 +08:00
|
|
|
|
2014-03-22 01:15:53 +08:00
|
|
|
source("adaptor");
|
|
|
|
|
2014-02-28 04:10:00 +08:00
|
|
|
describe("Adaptor", function() {
|
2014-03-22 01:15:53 +08:00
|
|
|
var connection = new EventEmitter;
|
|
|
|
var adaptor = new Cylon.Adaptor({ name: 'adaptor', connection: connection });
|
2013-12-19 04:26:21 +08:00
|
|
|
|
2014-03-22 01:15:53 +08:00
|
|
|
describe("#constructor", function() {
|
|
|
|
it("sets @self as a reference to the adaptor", function() {
|
|
|
|
expect(adaptor.self).to.be.eql(adaptor);
|
2014-02-28 04:10:00 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 01:15:53 +08:00
|
|
|
it("sets @name to the provided name", function() {
|
|
|
|
expect(adaptor.name).to.be.eql('adaptor');
|
2014-02-28 04:10:00 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 01:15:53 +08:00
|
|
|
it("sets @connection to the provided connection", function() {
|
|
|
|
expect(adaptor.connection).to.be.eql(connection);
|
|
|
|
});
|
2014-02-28 04:10:00 +08:00
|
|
|
|
2014-03-22 01:15:53 +08:00
|
|
|
it("sets @commandList to an empty array by default", function() {
|
|
|
|
expect(adaptor.commandList).to.be.eql([]);
|
|
|
|
});
|
2013-12-16 10:18:22 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 01:15:53 +08:00
|
|
|
describe("#commands", function() {
|
|
|
|
var commands = ['list', 'of', 'commands']
|
|
|
|
before(function() {
|
|
|
|
adaptor.commandList = commands;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
adaptor.commandList = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns the adaptor's @commandList", function() {
|
|
|
|
expect(adaptor.commands()).to.be.eql(commands);
|
|
|
|
});
|
2014-02-28 04:10:00 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 01:15:53 +08:00
|
|
|
describe("#connect", function() {
|
|
|
|
var callback = spy();
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
stub(connection, 'emit');
|
|
|
|
stub(Logger, 'info');
|
|
|
|
adaptor.connect(callback);
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
connection.emit.restore();
|
|
|
|
Logger.info.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("logs that it's connecting to the adaptor", function() {
|
|
|
|
var string = "Connecting to adaptor 'adaptor'...";
|
|
|
|
expect(Logger.info).to.be.calledWith(string);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("triggers the provided callback", function() {
|
|
|
|
expect(callback).to.be.called;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("tells the connection to emit the 'connect' event", function() {
|
|
|
|
expect(connection.emit).to.be.calledWith('connect');
|
|
|
|
});
|
2014-02-28 04:10:00 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 01:15:53 +08:00
|
|
|
describe("#disconnect", function() {
|
|
|
|
before(function() {
|
|
|
|
stub(Logger, 'info');
|
|
|
|
adaptor.disconnect();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
Logger.info.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("logs that it's disconnecting to the adaptor", function() {
|
|
|
|
var string = "Disconnecting from adaptor 'adaptor'...";
|
|
|
|
expect(Logger.info).to.be.calledWith(string);
|
|
|
|
});
|
2014-02-28 04:10:00 +08:00
|
|
|
});
|
|
|
|
});
|