Skip to content

Commit

Permalink
Add test for Env#alias() and default :app alias
Browse files Browse the repository at this point in the history
This will allow third party tools from having to set this config everytime
  • Loading branch information
SBoudrias committed Jan 16, 2014
1 parent 2a725aa commit 027c284
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/env/index.js
Expand Up @@ -53,6 +53,8 @@ var Environment = module.exports = function Environment(args, opts, adapter) {

this.lookups = ['.', 'generators', 'lib/generators'];
this.aliases = [];

this.alias(/^([^:]+)$/, '$1:app');
};

util.inherits(Environment, events.EventEmitter);
Expand Down
23 changes: 23 additions & 0 deletions test/env.js
Expand Up @@ -448,6 +448,29 @@ describe('Environment', function () {
});
});

describe('#alias()', function () {
it('apply regex and replace with alternative value', function () {
this.env.alias(/^([^:]+)$/, '$1:app');
assert.equal(this.env.alias('foo'), 'foo:app');
});

it('apply multiple regex', function () {
this.env.alias(/^([a-zA-Z0-9:\*]+)$/, 'generator-$1');
this.env.alias(/^([^:]+)$/, '$1:app');
assert.equal(this.env.alias('foo'), 'generator-foo:app');
});

it('apply latest aliases first', function () {
this.env.alias(/^([^:]+)$/, '$1:all');
this.env.alias(/^([^:]+)$/, '$1:app');
assert.equal(this.env.alias('foo'), 'foo:app');
});

it('alias empty namespace to `:app` by default', function () {
assert.equal(this.env.alias('foo'), 'foo:app');
});
});

describe('.enforceUpdate()', function () {
beforeEach(function () {
this.env = new Environment();
Expand Down

0 comments on commit 027c284

Please sign in to comment.