From cf643d9d708c21bc20bd2cf52204c67b2f29dc0e Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Mon, 8 Sep 2014 09:27:18 -0700 Subject: [PATCH] Remove default Adaptor#connect and Driver#start methods Child classes should always implement these themselves. --- lib/adaptor.js | 11 ----------- lib/connection.js | 6 +++--- lib/device.js | 6 +++--- lib/driver.js | 10 ---------- test/specs/adaptor.spec.js | 23 ----------------------- test/specs/connection.spec.js | 3 +-- test/specs/device.spec.js | 6 +----- test/specs/driver.spec.js | 23 ----------------------- 8 files changed, 8 insertions(+), 80 deletions(-) diff --git a/lib/adaptor.js b/lib/adaptor.js index ef2da1c..39dceb5 100644 --- a/lib/adaptor.js +++ b/lib/adaptor.js @@ -30,17 +30,6 @@ Utils.subclass(Adaptor, Basestar); Adaptor.prototype.commands = []; -// Public: Connects to the adaptor, and triggers the provided callback when -// done. -// -// callback - function to run when the adaptor is connected -// -// Returns nothing -Adaptor.prototype.connect = function(callback) { - Logger.info("Connecting to adaptor '" + this.name + "'."); - callback(null); -}; - // Public: Voids all command functions so they do not interact // with anything after disconnect has been called. // diff --git a/lib/connection.js b/lib/connection.js index 4282c0f..b9314a1 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -60,11 +60,11 @@ Connection.prototype.toJSON = function() { // // callback - callback function to run when the adaptor is connected // -// Returns the result of the supplied callback function +// Returns nothing Connection.prototype.connect = function(callback) { var msg = this._logstring("Connecting to"); Logger.info(msg); - return this.adaptor.connect(callback); + this.adaptor.connect(callback); }; // Public: Disconnect the adaptor's connection @@ -76,7 +76,7 @@ Connection.prototype.disconnect = function(callback) { var msg = this._logstring("Disconnecting from"); Logger.info(msg); this.removeAllListeners(); - return this.adaptor.disconnect(callback); + this.adaptor.disconnect(callback); }; // Public: sets up adaptor with @robot diff --git a/lib/device.js b/lib/device.js index 183ecb5..58651d8 100644 --- a/lib/device.js +++ b/lib/device.js @@ -58,7 +58,7 @@ Utils.subclass(Device, EventEmitter); // // callback - callback function to be executed by the driver start // -// Returns result of supplied callback +// Returns nothing Device.prototype.start = function(callback) { var msg = "Starting device '" + this.name + "'"; @@ -69,14 +69,14 @@ Device.prototype.start = function(callback) { msg += "."; Logger.info(msg); - return this.driver.start(callback); + this.driver.start(callback); }; // Public: Halt the device driver // // callback - function to trigger when the device has been halted // -// Returns result of supplied callback +// Returns nothing Device.prototype.halt = function(callback) { Logger.info("Halting device '" + this.name + "'."); this.removeAllListeners(); diff --git a/lib/driver.js b/lib/driver.js index 051276e..6b1757d 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -54,13 +54,3 @@ Driver.prototype.setupCommands = function(commands, proxy) { this.commands[snake_case] = this[command]; } } - -// Public: Starts up the driver, and triggers the provided callback when done. -// -// callback - function to run when the driver is started -// -// Returns nothing -Driver.prototype.start = function(callback) { - Logger.info("Driver " + this.name + " started."); - callback(); -}; diff --git a/test/specs/adaptor.spec.js b/test/specs/adaptor.spec.js index ef8651f..bd9d178 100644 --- a/test/specs/adaptor.spec.js +++ b/test/specs/adaptor.spec.js @@ -24,29 +24,6 @@ describe("Adaptor", function() { }); }); - describe("#connect", function() { - var callback; - - beforeEach(function() { - callback = spy(); - stub(Logger, 'info'); - adaptor.connect(callback); - }); - - afterEach(function() { - Logger.info.restore(); - }); - - it("logs that it's connecting to the adaptor", function() { - var string = "Connecting to adaptor 'adaptor'."; - expect(Logger.info).to.be.calledWith(string); - }); - - it("triggers the provided callback", function() { - expect(callback).to.be.called; - }); - }); - describe("#_noop", function() { var hello; diff --git a/test/specs/connection.spec.js b/test/specs/connection.spec.js index 85444aa..863778c 100644 --- a/test/specs/connection.spec.js +++ b/test/specs/connection.spec.js @@ -51,13 +51,12 @@ describe("Connection", function() { beforeEach(function() { stub(Logger, 'info').returns(true); - stub(connection.adaptor, 'connect').returns(true); + connection.adaptor.connect = stub().returns(true); connection.connect(callback); }); afterEach(function() { - connection.adaptor.connect.restore(); Logger.info.restore(); }); diff --git a/test/specs/device.spec.js b/test/specs/device.spec.js index 5b6cdc2..8909c61 100644 --- a/test/specs/device.spec.js +++ b/test/specs/device.spec.js @@ -72,11 +72,7 @@ describe("Device", function() { describe("#start", function() { beforeEach(function() { - stub(driver, 'start').returns(true); - }); - - afterEach(function() { - driver.start.restore(); + driver.start = stub().returns(true); }); it("starts the driver, passing along a callback", function() { diff --git a/test/specs/driver.spec.js b/test/specs/driver.spec.js index fae488c..caa98cb 100644 --- a/test/specs/driver.spec.js +++ b/test/specs/driver.spec.js @@ -75,27 +75,4 @@ describe("Driver", function() { expect(Object.keys(driver.commands)).to.be.eql(snake_case); }); }); - - describe("#start", function() { - var callback; - - beforeEach(function() { - callback = spy(); - stub(Logger, 'info'); - driver.start(callback); - }); - - afterEach(function() { - Logger.info.restore(); - }); - - it("logs that it's starting the driver", function() { - var string = "Driver driver started."; - expect(Logger.info).to.be.calledWith(string); - }); - - it("triggers the provided callback", function() { - expect(callback).to.be.called; - }); - }); });