Simplify coercion of Robot to JSON

This commit is contained in:
Andrew Stewart 2014-07-29 18:49:35 -07:00
parent d0c29822ff
commit 026d3777e6
2 changed files with 10 additions and 21 deletions

View File

@ -128,25 +128,16 @@ Robot.randomName = function() {
//
// Returns an Object containing Robot data
Robot.prototype.toJSON = function() {
var connections = (function() {
var results = [];
var devices = [],
connections = [];
for (var n in this.connections) {
results.push(this.connections[n].toJSON());
}
for (var n in this.connections) {
connections.push(this.connections[n]);
}
return results;
}).call(this);
var devices = (function() {
var results = [];
for (var n in this.devices) {
results.push(this.devices[n].toJSON());
}
return results;
}).call(this);
for (var n in this.devices) {
devices.push(this.devices[n]);
}
return {
name: this.name,

View File

@ -119,13 +119,11 @@ describe("Robot", function() {
});
it("contains the robot's devices", function() {
var deviceJSON = bot.devices.ping.toJSON();
expect(json.devices).to.eql([deviceJSON]);
expect(json.devices).to.eql([bot.devices.ping]);
});
it("contains the robot's connections", function() {
var connectionJSON = bot.connections.loopback.toJSON();
expect(json.connections).to.eql([connectionJSON]);
expect(json.connections).to.eql([bot.connections.loopback]);
});
});