2014-02-28 06:52:25 +08:00
|
|
|
'use strict';
|
2013-12-19 05:02:18 +08:00
|
|
|
|
2014-02-28 06:52:25 +08:00
|
|
|
var EventEmitter = require('events').EventEmitter;
|
2013-12-16 10:18:22 +08:00
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
source("driver");
|
|
|
|
|
2014-02-28 06:52:25 +08:00
|
|
|
describe("Driver", function() {
|
2014-03-22 03:17:39 +08:00
|
|
|
var device = {
|
|
|
|
connection: {},
|
|
|
|
emit: spy()
|
|
|
|
};
|
|
|
|
var driver = new Cylon.Driver({
|
|
|
|
name: 'driver',
|
2014-02-28 06:52:25 +08:00
|
|
|
device: device
|
|
|
|
});
|
2013-12-19 05:02:18 +08:00
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
describe("#constructor", function() {
|
|
|
|
it("sets @self as a reference to the driver", function() {
|
|
|
|
expect(driver.self).to.be.eql(driver);
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
it("sets @name to the provided name", function() {
|
|
|
|
expect(driver.name).to.be.eql('driver');
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
it("sets @device to the provided device", function() {
|
|
|
|
expect(driver.device).to.be.eql(device);
|
|
|
|
});
|
2013-12-16 10:18:22 +08:00
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
it("sets @connection to the provided device's connection", function() {
|
|
|
|
expect(driver.connection).to.be.eql(device.connection);
|
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
it("sets @commandList to an empty array by default", function() {
|
|
|
|
expect(driver.commandList).to.be.eql([]);
|
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|
2014-02-28 09:39:02 +08:00
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
describe("#commands", function() {
|
|
|
|
var commands = ['list', 'of', 'commands']
|
|
|
|
before(function() {
|
|
|
|
driver.commandList = commands;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
driver.commandList = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns the driver's @commandList", function() {
|
|
|
|
expect(driver.commands()).to.be.eql(commands);
|
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
describe("#start", function() {
|
|
|
|
var callback = spy();
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
stub(Logger, 'info');
|
|
|
|
driver.start(callback);
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
Logger.info.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("logs that it's starting the driver", function() {
|
|
|
|
var string = "Driver driver started";
|
|
|
|
expect(Logger.info).to.be.calledWith(string);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("triggers the provided callback", function() {
|
|
|
|
expect(callback).to.be.called;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("tells the device to emit the 'start' event", function() {
|
|
|
|
expect(device.emit).to.be.calledWith('start');
|
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|
|
|
|
|
2014-03-22 03:17:39 +08:00
|
|
|
describe("#halt", function() {
|
|
|
|
before(function() {
|
|
|
|
stub(Logger, 'info');
|
|
|
|
driver.halt();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
Logger.info.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("logs that it's halting the driver", function() {
|
|
|
|
expect(Logger.info).to.be.calledWith("Driver driver halted")
|
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|
|
|
|
});
|