Skip to content

Commit

Permalink
Remove Base#run() args parameter
Browse files Browse the repository at this point in the history
Reason: Generators are self contained, it doesn't make sense for
external source to modify the arguments it's methods takes.
  • Loading branch information
SBoudrias committed Jan 6, 2015
1 parent 7c4e1c8 commit d4f5ebc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
16 changes: 4 additions & 12 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,25 +361,17 @@ Base.prototype.checkRequiredArgs = function () {
* none is given, the same values used to initialize the invoker are
* used to initialize the invoked.
*
* @param {String|Array|Function} [args]
* @param {Function} [cb]
*/

Base.prototype.run = function run(args, cb) {
Base.prototype.run = function run(cb) {
cb = cb || function () {};

var self = this;
this._running = true;
this.emit('run');

if (!cb) {
cb = args;
args = this.args;
}

args = _.isString(args) ? args.split(' ') : args;
cb = cb || function () {};

var methods = Object.keys(Object.getPrototypeOf(this));

assert(methods.length, 'This Generator is empty. Add at least one method for it to run.');

this.env.runLoop.once('end', function () {
Expand Down Expand Up @@ -410,7 +402,7 @@ Base.prototype.run = function run(args, cb) {

self.emit('method:' + methodName);
try {
method.apply(self, args);
method.apply(self, self.args);
if (!running) return done();
} catch (err) {
debug('An error occured while running ' + methodName, err);
Expand Down
16 changes: 1 addition & 15 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,6 @@ describe('generators.Base', function () {
this.testGen.run(done);
});

it('pass an array of arguments to the called methods', function (done) {
this.testGen.run(['some', 'args'], function () {
assert(this.execSpy.withArgs('some', 'args').calledOnce);
done();
}.bind(this));
});

it('pass string of arguments to the called methods', function (done) {
this.testGen.run('some args', function () {
assert(this.execSpy.withArgs('some', 'args').calledOnce);
done();
}.bind(this));
});

it('pass instance .args property to the called methods', function (done) {
this.testGen.args = ['2', 'args'];
this.testGen.run(function () {
Expand All @@ -250,7 +236,7 @@ describe('generators.Base', function () {
});

it('resolve conflicts after it ran', function (done) {
this.testGen.run({}, function () {
this.testGen.run(function () {
assert.equal(this.resolveSpy.callCount, 1);
done();
}.bind(this));
Expand Down

0 comments on commit d4f5ebc

Please sign in to comment.