Skip to content

Commit

Permalink
Merge 2486601 into 7831022
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jan 24, 2014
2 parents 7831022 + 2486601 commit cfc07d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
18 changes: 0 additions & 18 deletions lib/actions/invoke.js
Expand Up @@ -21,24 +21,6 @@ module.exports = function invoke(namespace, options, cb) {

var generator = this.env.create(namespace, options);

if (!generator.sourceRoot()) {
generator.sourceRoot(path.join(path.dirname(generator.resolved), 'templates'));
}

// validate the generator (show help on missing arguments/options)
// also show help if --help was specifically passed
var requiredArgs = generator._arguments.some(function (arg) {
return arg.config && arg.config.required;
});

if (!options.args.length && requiredArgs) {
return console.log(generator.help());
}

if (options.help) {
return console.log(generator.help());
}

this.log.emit('up');
this.log.invoke(namespace);
this.log.emit('up');
Expand Down
40 changes: 40 additions & 0 deletions test/invoke.js
@@ -0,0 +1,40 @@
/*global describe, it, before, after, beforeEach, afterEach */
'use strict';

var yo = require('..');
var helpers = yo.test;
var assert = yo.assert;

describe('Base#invoke()', function () {
beforeEach(function () {
this.env = yo();
this.gen = new (helpers.createDummyGenerator())({
namespace: 'foo:lab',
resolved: 'path/',
env: this.env,
'skip-install': true
});
this.env.registerStub(yo.generators.Base.extend({
exec: function () { this.stubGenRunned = true; }
}), 'foo:bar');
});

it('invoke available generators', function (done) {
var invoked = this.gen.invoke('foo:bar', {
options: { 'skip-install': true }
});
invoked.on('end', function () {
assert(invoked.stubGenRunned);
done();
});
});

it('accept a callback argument', function (done) {
var invoked = this.gen.invoke('foo:bar', {
options: { 'skip-install': true }
}, function () {
assert(invoked.stubGenRunned);
done();
});
});
});

0 comments on commit cfc07d8

Please sign in to comment.