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-05-25 01:34:19 +08:00
|
|
|
var Driver = source("driver"),
|
2014-06-06 03:11:37 +08:00
|
|
|
Logger = source('logger'),
|
|
|
|
Utils = source('utils');
|
2014-03-22 03:17:39 +08:00
|
|
|
|
2014-02-28 06:52:25 +08:00
|
|
|
describe("Driver", function() {
|
2014-03-22 03:17:39 +08:00
|
|
|
var device = {
|
|
|
|
connection: {},
|
|
|
|
emit: spy()
|
|
|
|
};
|
2014-05-07 09:24:43 +08:00
|
|
|
|
|
|
|
var driver = new Driver({
|
2014-03-22 03:17:39 +08:00
|
|
|
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-06-11 03:29:44 +08:00
|
|
|
it("sets @commands to an empty array by default", function() {
|
|
|
|
expect(driver.commands).to.be.eql([]);
|
2014-03-22 03:17:39 +08:00
|
|
|
});
|
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() {
|
2014-06-11 02:33:52 +08:00
|
|
|
var string = "Driver driver started.";
|
2014-03-22 03:17:39 +08:00
|
|
|
expect(Logger.info).to.be.calledWith(string);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("triggers the provided callback", function() {
|
|
|
|
expect(callback).to.be.called;
|
|
|
|
});
|
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() {
|
2014-06-11 02:33:52 +08:00
|
|
|
expect(Logger.info).to.be.calledWith("Driver driver halted.")
|
2014-03-22 03:17:39 +08:00
|
|
|
});
|
2014-02-28 06:52:25 +08:00
|
|
|
});
|
|
|
|
});
|