Use _.result to get commands from options.
This commit is contained in:
parent
6cbf2db122
commit
c9e16fe8c2
18
lib/robot.js
18
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue