Stop giving robots random names, use inc. counter

This commit is contained in:
Andrew Stewart 2015-06-09 11:50:50 -07:00
parent 952a25ac2c
commit 681e197ed9
2 changed files with 6 additions and 22 deletions

View File

@ -17,6 +17,9 @@ var initializer = require("./initializer"),
var Async = require("async"),
EventEmitter = require("events").EventEmitter;
// used when creating default robot names
var ROBOT_ID = 1;
/**
* Creates a new Robot instance based on provided options
*
@ -100,16 +103,6 @@ var Robot = module.exports = function Robot(opts) {
Utils.subclass(Robot, EventEmitter);
/**
* Generates a random name for a Robot.
*
* @todo should perhaps just increment a counter as a global value?
* @returns {String} a robot name
*/
Robot.randomName = function() {
return "Robot " + (Math.floor(Math.random() * 100000));
};
/**
* Condenses information on a Robot to a JSON-serializable format
*
@ -159,7 +152,7 @@ Robot.prototype.connection = function(name, conn) {
* @return {void}
*/
Robot.prototype.initRobot = function(opts) {
this.name = opts.name || Robot.randomName();
this.name = opts.name || "Robot " + ROBOT_ID++;
this.connections = {};
this.devices = {};
this.adaptors = {};

View File

@ -32,17 +32,8 @@ describe("Robot", function() {
});
context("if not provided", function() {
beforeEach(function() {
stub(Robot, "randomName").returns("New Robot");
});
afterEach(function() {
Robot.randomName.restore();
});
it("is set to a random name", function() {
var bot = new Robot({});
expect(bot.name).to.be.eql("New Robot");
it("is set to an incrementing name", function() {
expect(new Robot({}).name).to.match(/Robot \d/);
});
});
});