From c9e16fe8c220362d2f990d2e68f934f732fa64ef Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 17 Dec 2014 15:07:03 -0800 Subject: [PATCH] Use _.result to get commands from options. --- lib/robot.js | 18 ++++++------------ spec/lib/robot.spec.js | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/robot.js b/lib/robot.js index 4dd9a29..b839b43 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -84,20 +84,14 @@ var Robot = module.exports = function Robot(opts) { }, this); if (opts.commands) { - var cmds = opts.commands; + var cmds = _.result(opts, "commands"); - if (_.isObject(cmds)) { + if (_.isObject(cmds) && !_.isArray(cmds)) { this.commands = cmds; - } - - if (_.isFunction(cmds)) { - var result = cmds.call(this, this); - - if (_.isObject(result) && !_.isArray(result)) { - this.commands = result; - } else { - throw new Error("#commands function must return an object"); - } + } else { + var err = "#commands must be an object "; + err += "or a function that returns an object"; + throw new Error(err); } } diff --git a/spec/lib/robot.spec.js b/spec/lib/robot.spec.js index 05a09b1..9f59862 100644 --- a/spec/lib/robot.spec.js +++ b/spec/lib/robot.spec.js @@ -139,7 +139,7 @@ describe("Robot", function() { it("throws an error", function() { expect(fn).to.throw( Error, - "#commands function must return an object" + "#commands must be an object or a function that returns an object" ); }); });