Skip to content

Commit

Permalink
Merge pull request yeoman#120 from revathskumar/backbone_jasmine
Browse files Browse the repository at this point in the history
Generate backbone scaffold with Jasmine
  • Loading branch information
sindresorhus committed Nov 21, 2012
2 parents 62c2af6 + 581077a commit ce2f434
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
40 changes: 37 additions & 3 deletions lib/generators/backbone/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,46 @@ module.exports = Generator;

function Generator() {
yeoman.generators.Base.apply(this, arguments);

this.test_framework = this.options['test-framework'] || 'mocha';
this.hookFor('test-framework', { as: 'app' });
}

util.inherits(Generator, yeoman.generators.Base);

Generator.prototype.setupEnv = function setupEnv() {
// Copies the contents of the generator `templates`
// directory into your users new application path
this.directory('.','.', true);
this.directory('app/scripts/','app/scripts/', true);
this.directory('app/styles/','app/styles/', true);
this.template('app/.buildignore');
this.template('app/.htaccess');
this.template('app/404.html');
this.template('app/favicon.ico');
this.template('app/robots.txt');
};

Generator.prototype.git = function git() {
this.copy('.gitignore', '.gitignore');
this.copy('.gitattributes', '.gitattributes');
};

Generator.prototype.gruntfile = function gruntfile() {
if(this.test_framework === 'jasmine'){
var jasmine_gruntfile = this.read('Gruntfile.js').replace(/mocha/g,'jasmine');
this.write('Gruntfile.js', jasmine_gruntfile);
}else{
this.template('Gruntfile.js');
}
};

Generator.prototype.packageJSON = function packageJSON() {
this.template('package.json');
};

Generator.prototype.indexFile = function indexFile(){
if(this.test_framework === 'jasmine'){
var jasmine_indexfile = this.read('app/index.html').replace(/mocha/gi, 'Jasmine');
this.write('app/index.html', jasmine_indexfile,true);
}else{
this.template('app/index.html');
}
};
24 changes: 22 additions & 2 deletions test/generators/test-backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ describe('Backbone generator test', function() {

helpers.assertFile('test/lib/expect.js');

helpers.assertFile('test/lib/mocha-1.2.2/mocha.css');
helpers.assertFile('test/lib/mocha/mocha.css');

helpers.assertFile('test/lib/mocha-1.2.2/mocha.js');
helpers.assertFile('test/lib/mocha/mocha.js');

helpers.assertFile('test/runner/mocha.js');

Expand Down Expand Up @@ -91,4 +91,24 @@ describe('Backbone generator test', function() {
helpers.assertFile('app/scripts/collections/application-collection.coffee');
});

it('runs successfully with --test-framework as argument', function(done) {
helpers.runGenerator('backbone', {'test-framework': 'jasmine'} ,done);
});

it('creates jasmine files when run with --test-framework',function(){
helpers.assertFile('test/runner/headless.js');

helpers.assertFile('test/runner/html.js');

helpers.assertFile('test/lib/jasmine-1.2.0/jasmine.css');

helpers.assertFile('test/lib/jasmine-1.2.0/jasmine-html.js');

helpers.assertFile('test/lib/jasmine-1.2.0/jasmine.js');

helpers.assertFile('test/spec/');

helpers.assertFile('test/spec/introduction.js');
});

});

0 comments on commit ce2f434

Please sign in to comment.