Require a connection if a robot has any devices

This commit is contained in:
Andrew Stewart 2014-07-11 10:40:45 -07:00
parent ee366739d3
commit 4dd7e013ed
2 changed files with 21 additions and 0 deletions

View File

@ -89,6 +89,13 @@ var Robot = module.exports = function Robot(opts) {
this.initConnections(opts.connection || opts.connections);
this.initDevices(opts.device || opts.devices);
var hasDevices = !!Object.keys(this.devices).length,
hasConnections = !!Object.keys(this.connections).length;
if (hasDevices && !hasConnections) {
throw new Error("No connections specified");
}
for (var n in opts) {
var func = opts[n],
reserved = ['connection', 'connections', 'device', 'devices', 'work'];

View File

@ -71,6 +71,19 @@ describe("Robot", function() {
expect(robot.extraFunction).to.be.eql(extraFunction);
expect(robot.extraValue).to.be.eql("Hello World");
});
context("if there are devices but no connections", function() {
it('throws an error', function() {
var fn = function() {
return new Robot({
name: 'BrokenBot',
device: { name: 'ping', driver: 'ping' }
});
};
expect(fn).to.throw(Error, "No connections specified");
});
});
});
describe("all work and no play", function() {
@ -229,6 +242,7 @@ describe("Robot", function() {
beforeEach(function() {
bot = new Robot({
connection: [{ name: 'loopback', adaptor: 'loopback' }],
devices: [
{ name: 'alpha', driver: 'ping' },
{ name: 'bravo', driver: 'ping' }