Skip to content

Commit

Permalink
Add specs and fix argument issue
Browse files Browse the repository at this point in the history
  • Loading branch information
p-m-p committed Jan 11, 2014
1 parent d28d75e commit 9358915
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,15 @@ var Base = module.exports = function Base(args, options) {

// Get the application name by either:
// - Looking in bower.json if already setup
// - Argv if supplied
// - args if supplied
// - Current working directory
try {
this.appname = require(path.join(process.cwd(), 'bower.json')).name;
}
catch (e) {
this.argument('appname', { type: String, required: false });
this.appname || (this.appname = path.basename(process.cwd()));
this.appname = this.args[0] || path.basename(process.cwd());
}
this.appname = this._.slugify(this._.humanize(this.appname));
this.appname = this.appname.replace(/[^\w\s]+?/g, ' ');;

this.option('help', {
alias: 'h',
Expand Down
30 changes: 28 additions & 2 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('yeoman.generators.Base', function () {
// mandatory options, created by the env#create() helper
resolved: 'ember:all',
namespace: 'dummy',
env: env,
env: env
});

this.dummy
Expand All @@ -48,10 +48,36 @@ describe('yeoman.generators.Base', function () {
});

describe('generator.appname', function () {
it('should be set with the project directory name without non-alphanums', function () {
beforeEach(function () {
this.createDummyGenerator = function(args) {
return new this.Dummy(args || [], {
resolved: 'ember:all',
namespace: 'dummy',
env: this.env
});
}.bind(this);

process.chdir(path.join(__dirname, 'temp.dev'));
});

it('should pull app name from bower.json', function () {
fs.writeFileSync('bower.json', '{ "name": "app-name" }');
this.dummy = this.createDummyGenerator();
assert.equal(this.dummy.appname, 'app name');

fs.unlinkSync('bower.json');
delete require.cache[path.join(process.cwd(), 'bower.json')];
});

it('should be set with the project directory', function () {
this.dummy = this.createDummyGenerator();
assert.equal(this.dummy.appname, 'temp dev');
});

it('should be set from args', function () {
this.dummy = this.createDummyGenerator(['new-app']);
assert.equal(this.dummy.appname, 'new app');
});
});

describe('.extend', function () {
Expand Down

0 comments on commit 9358915

Please sign in to comment.