From ef3aaf6591dfa9096c76a47984975369b395982e Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Fri, 28 Feb 2014 20:50:45 -0800 Subject: [PATCH] Clean up initialization methods for adaptors/drivers --- lib/robot.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/robot.js b/lib/robot.js index c073d57..bbc6b02 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -252,24 +252,23 @@ namespace("Cylon", function() { // // Returns the adaptor Robot.prototype.initAdaptor = function(adaptorName, connection, opts) { - var realAdaptor, testAdaptor; - if (opts == null) { - opts = {}; - } - realAdaptor = this.robot.requireAdaptor(adaptorName).adaptor({ + if (opts == null) { opts = {}; } + + var adaptor = this.robot.requireAdaptor(adaptorName).adaptor({ name: adaptorName, connection: connection, extraParams: opts }); + if (CylonConfig.testing_mode) { - testAdaptor = this.robot.requireAdaptor('test').adaptor({ + var testAdaptor = this.robot.requireAdaptor('test').adaptor({ name: adaptorName, connection: connection, extraParams: opts }); - return proxyTestStubs(realAdaptor.commands(), testAdaptor); + return proxyTestStubs(adaptor.commands(), testAdaptor); } else { - return realAdaptor; + return adaptor; } }; @@ -306,24 +305,24 @@ namespace("Cylon", function() { // // Returns the new driver Robot.prototype.initDriver = function(driverName, device, opts) { - var realDriver, testDriver; - if (opts == null) { - opts = {}; - } - realDriver = this.robot.requireDriver(driverName).driver({ + if (opts == null) { opts = {}; } + + var driver = this.robot.requireDriver(driverName).driver({ name: driverName, device: device, extraParams: opts }); + if (CylonConfig.testing_mode) { - testDriver = this.robot.requireDriver('test').driver({ + var testDriver = this.robot.requireDriver('test').driver({ name: driverName, device: device, extraParams: opts }); - return proxyTestStubs(realDriver.commands(), testDriver); + + return proxyTestStubs(driver.commands(), testDriver); } else { - return realDriver; + return driver; } };