Skip to content

Commit

Permalink
Fix up generate tests and implementation to match.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Oct 18, 2016
1 parent f761888 commit d297225
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bin/sails-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ module.exports = function () {
var cliArguments = _.initial(arguments);
scope.generatorType = cliArguments.shift();
scope.args = cliArguments;
assert(arguments.length === (scope.args.length + 2), new Error('Consistency violation: Should have trimmed exactly two args.'));


// If no generator type was defined, then log the expected usage.
if (!scope.generatorType) {
console.log('Usage: sails generate [something]');
return;
}
assert(arguments.length === (scope.args.length + 2), new Error('Consistency violation: Should have trimmed exactly two args.'));

// Call out to `sails-generate`.
return sailsGen(scope, {
Expand Down
20 changes: 12 additions & 8 deletions test/integration/generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('API and adapter generators', function() {
}

exec('node ' + sailsBin + ' new ' + appName, function(err) {
if (err) done(new Error(err));
if (err) { return done(new Error(err)); }

// Move into app directory and update sailsBin relative path
process.chdir(appName);
sailsBin = path.resolve('..', sailsBin);
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('API and adapter generators', function() {
it('should create a controller file in controllers folder', function(done) {

exec('node ' + sailsBin + ' generate controller ' + controllerName, function(err) {
if (err) done(new Error(err));
if (err) { return done(new Error(err)); }

assert.doesNotThrow(function() {
fs.readFileSync('./api/controllers/' + capitalize(controllerName) + 'Controller.js', 'utf8');
Expand Down Expand Up @@ -124,10 +125,10 @@ describe('API and adapter generators', function() {
it('should create a adapter file in adapters folder', function(done) {

exec('node ' + sailsBin + ' generate adapter ' + adapterName, function(err) {
if (err) done(new Error(err));
if (err) { return done(err); }

assert.doesNotThrow(function() {
fs.readFileSync('./api/adapters/' + adapterName + '/lib/adapter.js', 'utf8');
fs.readFileSync('./api/adapters/' + adapterName + '/index.js', 'utf8');
});

done();
Expand All @@ -146,10 +147,13 @@ describe('API and adapter generators', function() {
describe('sails generate', function() {
var modelName = 'post';

it('should display usage if no generator name is specified', function(done) {
it('should display usage if no generator type is specified', function(done) {

exec('node ' + sailsBin + ' generate', function(err, msg) {
if (err) { return done(err); }

assert.notEqual(msg.indexOf('Usage'), -1);

exec('node ' + sailsBin + ' generate', function(err, dumb, response) {
assert.notEqual(response.indexOf('Usage'), -1);
done();
});
});
Expand All @@ -171,7 +175,7 @@ describe('API and adapter generators', function() {
it('should create a controller and a model file', function(done) {

exec('node ' + sailsBin + ' generate api ' + apiName, function(err) {
if (err) done(new Error(err));
if (err) { return done(err); }

assert.doesNotThrow(function() {
fs.readFileSync('./api/models/' + capitalize(apiName) + '.js', 'utf8');
Expand Down

0 comments on commit d297225

Please sign in to comment.