Skip to content

Commit

Permalink
Clean up formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
p-m-p committed Jan 11, 2014
1 parent 5c96344 commit f41a7d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
6 changes: 2 additions & 4 deletions lib/base.js
Expand Up @@ -128,12 +128,10 @@ var Base = module.exports = function Base(args, options) {
// - Current working directory
try {
this.appname = require(path.join(process.cwd(), 'bower.json')).name;
}
catch (e) {
} catch (e) {
try {
this.appname = require(path.join(process.cwd(), 'package.json')).name;
}
catch (e) {
} catch (e) {
this.appname = this.args[0] || path.basename(process.cwd());
}
}
Expand Down
27 changes: 16 additions & 11 deletions test/base.js
Expand Up @@ -48,7 +48,7 @@ describe('yeoman.generators.Base', function () {
});

describe('generator.appname', function () {
beforeEach(function () {
before(function () {
this.createDummyGenerator = function (args) {
return new this.Dummy(args || [], {
resolved: 'ember:all',
Expand All @@ -60,30 +60,35 @@ describe('yeoman.generators.Base', function () {
process.chdir(path.join(__dirname, 'temp.dev'));
});

it('should pull app name from bower.json', function () {
afterEach(function () {
if (fs.existsSync('bower.json')) {
fs.unlinkSync('bower.json');
delete require.cache[path.join(process.cwd(), 'bower.json')];
}
if (fs.existsSync('package.json')) {
fs.unlinkSync('package.json');
delete require.cache[path.join(process.cwd(), 'package.json')];
}
});

it('is set 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 pull app name from package.json', function () {
it('is set from package.json', function () {
fs.writeFileSync('package.json', '{ "name": "package_app-name" }');
this.dummy = this.createDummyGenerator();
assert.equal(this.dummy.appname, 'package_app name');

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

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

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

0 comments on commit f41a7d1

Please sign in to comment.