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);
|
}, this);
|
||||||
|
|
||||||
if (opts.commands) {
|
if (opts.commands) {
|
||||||
var cmds = opts.commands;
|
var cmds = _.result(opts, "commands");
|
||||||
|
|
||||||
if (_.isObject(cmds)) {
|
if (_.isObject(cmds) && !_.isArray(cmds)) {
|
||||||
this.commands = cmds;
|
this.commands = cmds;
|
||||||
}
|
} else {
|
||||||
|
var err = "#commands must be an object ";
|
||||||
if (_.isFunction(cmds)) {
|
err += "or a function that returns an object";
|
||||||
var result = cmds.call(this, this);
|
throw new Error(err);
|
||||||
|
|
||||||
if (_.isObject(result) && !_.isArray(result)) {
|
|
||||||
this.commands = result;
|
|
||||||
} else {
|
|
||||||
throw new Error("#commands function must return an object");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ describe("Robot", function() {
|
||||||
it("throws an error", function() {
|
it("throws an error", function() {
|
||||||
expect(fn).to.throw(
|
expect(fn).to.throw(
|
||||||
Error,
|
Error,
|
||||||
"#commands function must return an object"
|
"#commands must be an object or a function that returns an object"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue