diff --git a/test/helper.js b/test/helper.js new file mode 100644 index 0000000..c952f7f --- /dev/null +++ b/test/helper.js @@ -0,0 +1,26 @@ +var yeoman = require('yeoman-generator'); +var helpers = yeoman.test; + +exports.createSubGenerator = function (type, asserts) { + var subGenerator = helpers.createGenerator('backbone:' + type, [ + '../../' + type, [ + helpers.createDummyGenerator(), + 'backbone-mocha:' + type + ] + ], ['foo']); + + subGenerator.run([], function () { + asserts(); + }); +}; + +exports.createAppGenerator = function (args, options) { + var app = helpers.createGenerator('backbone:app', [ + '../../app', [ + helpers.createDummyGenerator(), + 'mocha:app' + ] + ], args, options); + app.options['skip-install'] = true; + return app; +}; diff --git a/test/test-apppath.js b/test/test-apppath.js index 1887730..580bcdc 100644 --- a/test/test-apppath.js +++ b/test/test-apppath.js @@ -1,9 +1,11 @@ /*global describe:true, beforeEach:true, it:true */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; -var assert = require('assert'); +var yeoman = require('yeoman-generator'); +var helpers = yeoman.test; +var assert = yeoman.assert; var fs = require('fs'); +var test = require('./helper.js'); describe('backbone generator with appPath option', function () { beforeEach(function (done) { @@ -12,13 +14,7 @@ describe('backbone generator with appPath option', function () { return done(err); } this.backbone = {}; - this.backbone.app = helpers.createGenerator('backbone:app', [ - '../../app', [ - helpers.createDummyGenerator(), - 'mocha:app' - ] - ], ['temp'], {appPath: 'public'}); - this.backbone.app.options['skip-install'] = true; + this.backbone.app = test.createAppGenerator(['temp'], {appPath: 'public'}); helpers.mockPrompt(this.backbone.app, { features: ['compassBootstrap'] @@ -40,10 +36,13 @@ describe('backbone generator with appPath option', function () { describe('create expected files', function () { it('in path specified by --appPath', function (done) { - var expected = [ + var expectedContent = [ ['bower.json', /"name": "temp"/], ['package.json', /"name": "temp"/], - ['Gruntfile.js', /app: 'public'/], + ['Gruntfile.js', /app: 'public'/] + ]; + + var expected = [ 'public/404.html', 'public/favicon.ico', 'public/robots.txt', @@ -60,69 +59,63 @@ describe('backbone generator with appPath option', function () { ]; this.backbone.app.run({}, function () { - helpers.assertFiles(expected); + assert.file(expected); + assert.fileContent(expectedContent); done(); }); }); }); - describe('Backbone Model', function () { - it('creates backbone model', function (done) { - var model = helpers.createGenerator('backbone:model', ['../../model'], ['foo']); - + describe('creates model', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - model.run([], function () { - helpers.assertFiles([ - ['public/scripts/models/foo.js', /Models.Foo = Backbone.Model.extend\(\{/] - ]); + test.createSubGenerator('model', function () { + assert.fileContent( + 'public/scripts/models/foo.js', /Models.Foo = Backbone.Model.extend\(\{/ + ); + done(); }); - done(); }); }); }); - describe('Backbone Collection', function () { - it('creates backbone collection', function (done) { - var collection = helpers.createGenerator('backbone:collection', ['../../collection'], ['foo']); - + describe('creates collection', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - collection.run([], function () { - helpers.assertFiles([ - ['public/scripts/collections/foo.js', /Collections.Foo = Backbone.Collection.extend\(\{/] - ]); + test.createSubGenerator('collection', function () { + assert.fileContent( + 'public/scripts/collections/foo.js', /Collections.Foo = Backbone.Collection.extend\(\{/ + ); + done(); }); - done(); }); }); }); - describe('Backbone Router', function () { - it('creates backbone router', function (done) { - var router = helpers.createGenerator('backbone:router', ['../../router'], ['foo']); - + describe('creates router', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - router.run([], function () { - helpers.assertFiles([ - ['public/scripts/routes/foo.js', /Routers.Foo = Backbone.Router.extend\(\{/] - ]); + test.createSubGenerator('router', function () { + assert.fileContent( + 'public/scripts/routes/foo.js', /Routers.Foo = Backbone.Router.extend\(\{/ + ); + done(); }); - done(); }); }); }); - describe('Backbone View', function () { - it('creates backbone view', function (done) { - var view = helpers.createGenerator('backbone:view', ['../../view'], ['foo']); + describe('creates view', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - view.run([], function () { - helpers.assertFiles([ - ['public/scripts/views/foo.js', /Views.Foo = Backbone.View.extend\(\{(.|\n)*public\/scripts\/templates\/foo.ejs/], - 'public/scripts/templates/foo.ejs' - ]); + test.createSubGenerator('view', function () { + assert.fileContent( + 'public/scripts/views/foo.js', /Views.Foo = Backbone.View.extend\(\{(.|\n)*public\/scripts\/templates\/foo.ejs/ + ); + assert.file('public/scripts/templates/foo.ejs'); + done(); }); - done(); }); }); }); diff --git a/test/test-coffee-requirejs.js b/test/test-coffee-requirejs.js index 6106cff..5da2dab 100644 --- a/test/test-coffee-requirejs.js +++ b/test/test-coffee-requirejs.js @@ -1,9 +1,11 @@ /*global describe:true, beforeEach:true, it:true */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; -var assert = require('assert'); +var yeoman = require('yeoman-generator'); +var helpers = yeoman.test; +var assert = yeoman.assert; var fs = require('fs'); +var test = require('./helper.js'); describe('Backbone generator test with --coffee and --requirejs option', function () { beforeEach(function (done) { @@ -12,13 +14,7 @@ describe('Backbone generator test with --coffee and --requirejs option', functio return done(err); } this.backbone = {}; - this.backbone.app = helpers.createGenerator('backbone:app', [ - '../../app', [ - helpers.createDummyGenerator(), - 'mocha:app' - ] - ]); - this.backbone.app.options['skip-install'] = true; + this.backbone.app = test.createAppGenerator(); helpers.mockPrompt(this.backbone.app, { features: ['compassBootstrap', 'coffee', 'requirejs'] @@ -39,14 +35,16 @@ describe('Backbone generator test with --coffee and --requirejs option', functio }); it('creates expected files', function (done) { - var expected = [ + var expectedContent = [ ['bower.json', /("name": "temp")(|.|\n)*(requirejs)/], ['package.json', /"name": "temp"/], + ['app/index.html', /(Bootstrap)(|.|\n)*(RequireJS)/i] + ]; + var expected = [ 'Gruntfile.js', 'app/404.html', 'app/favicon.ico', 'app/robots.txt', - ['app/index.html', /(Bootstrap)(|.|\n)*(RequireJS)/i], 'app/.htaccess', '.gitignore', '.gitattributes', @@ -58,72 +56,68 @@ describe('Backbone generator test with --coffee and --requirejs option', functio ]; this.backbone.app.run([], function () { - helpers.assertFiles(expected); + assert.file(expected); + assert.fileContent(expectedContent); done(); }); }); - describe('Backbone Model in coffeescript with RequireJS support', function () { - it('creates backbone model', function (done) { + describe('creates model in coffeescript with rjs', function () { + it('without failure', function (done) { this.backbone.app.run([], function () { - var model = helpers.createGenerator('backbone:model', ['../../model'], ['foo']); - model.run([], function () { - helpers.assertFiles([ - ['app/scripts/models/foo.coffee', /class FooModel extends Backbone.Model/] - ]); + test.createSubGenerator('model', function () { + assert.fileContent( + 'app/scripts/models/foo.coffee', /class FooModel extends Backbone.Model/ + ); + done(); }); - done(); }); }); }); - describe('Backbone Collection in coffeescript with RequireJS support', function () { - it('creates backbone collection', function (done) { + describe('creates collection in coffeescript with rjs', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var collection = helpers.createGenerator('backbone:collection', ['../../collection'], ['foo']); - - collection.run([], function () { - helpers.assertFiles([ - ['app/scripts/collections/foo.coffee', /class FooCollection extends Backbone.Collection/] - ]); + test.createSubGenerator('collection', function () { + assert.fileContent( + 'app/scripts/collections/foo.coffee', /class FooCollection extends Backbone.Collection/ + ); + done(); }); - done(); }); }); }); - describe('Backbone Router in coffeescript with RequireJS support', function () { - it('creates backbone router', function (done) { + describe('creates router in coffeescript with rjs', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var router = helpers.createGenerator('backbone:router', ['../../router'], ['foo']); - - router.run([], function () { - helpers.assertFiles([ - ['app/scripts/routes/foo.coffee', /class FooRouter extends Backbone.Router/] - ]); + test.createSubGenerator('router', function () { + assert.fileContent( + 'app/scripts/routes/foo.coffee', /class FooRouter extends Backbone.Router/ + ); + done(); }); - done(); + }); }); }); - describe('Backbone View in coffeescript with RequireJS support', function () { - it('creates backbone view', function (done) { + describe('creates view in coffeescript with rjs', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var view = helpers.createGenerator('backbone:view', ['../../view'], ['foo']); - - view.run([], function () { - helpers.assertFiles([ - ['app/scripts/views/foo.coffee', /class FooView extends Backbone.View(.|\n)*app\/scripts\/templates\/foo.ejs/], - 'app/scripts/templates/foo.ejs' - ]); + test.createSubGenerator('view', function () { + assert.fileContent( + 'app/scripts/views/foo.coffee', /class FooView extends Backbone.View(.|\n)*app\/scripts\/templates\/foo.ejs/ + ); + assert.file('app/scripts/templates/foo.ejs'); + done(); }); - done(); + }); }); }); diff --git a/test/test-coffee.js b/test/test-coffee.js index 90901ff..bfe7c18 100644 --- a/test/test-coffee.js +++ b/test/test-coffee.js @@ -1,9 +1,11 @@ /*global describe:true, beforeEach:true, it:true */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; -var assert = require('assert'); +var yeoman = require('yeoman-generator'); +var helpers = yeoman.test; +var assert = yeoman.assert; var fs = require('fs'); +var test = require('./helper.js'); describe('Backbone generator test with --coffee option', function () { beforeEach(function (done) { @@ -12,13 +14,7 @@ describe('Backbone generator test with --coffee option', function () { return done(err); } this.backbone = {}; - this.backbone.app = helpers.createGenerator('backbone:app', [ - '../../app', [ - helpers.createDummyGenerator(), - 'mocha:app' - ] - ]); - this.backbone.app.options['skip-install'] = true; + this.backbone.app = test.createAppGenerator(); helpers.mockPrompt(this.backbone.app, { features: ['compassBootstrap', 'coffee'] @@ -39,9 +35,11 @@ describe('Backbone generator test with --coffee option', function () { }); it('creates expected files', function (done) { - var expected = [ + var expectedContent = [ ['bower.json', /"name": "temp"/], - ['package.json', /"name": "temp"/], + ['package.json', /"name": "temp"/] + ]; + var expected = [ 'Gruntfile.js', 'app/404.html', 'app/favicon.ico', @@ -58,96 +56,67 @@ describe('Backbone generator test with --coffee option', function () { ]; this.backbone.app.run([], function () { - helpers.assertFiles(expected); + assert.file(expected); + assert.fileContent(expectedContent); done(); }); }); - describe('Backbone Model in coffeescript', function () { - it('creates backbone model', function (done) { - var model = helpers.createGenerator('backbone:model', ['../../model'], ['foo']); + describe('creates model in coffeescript', function () { + it('without failure', function (done) { this.backbone.app.run([], function () { - var model = helpers.createGenerator('backbone:model', [ - '../../model', [ - helpers.createDummyGenerator(), - 'backbone-mocha:model' - ] - ], ['foo']); - - model.run([], function () { - helpers.assertFiles([ - ['app/scripts/models/foo.coffee', /class Temp.Models.Foo extends Backbone.Model/] - ]); + test.createSubGenerator('model', function () { + assert.fileContent( + 'app/scripts/models/foo.coffee', /class Temp.Models.Foo extends Backbone.Model/ + ); + done(); }); - done(); }); }); }); - describe('Backbone Collection in coffeescript', function () { - it('creates backbone collection', function (done) { + describe('creates collection in coffeescript', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var collection = helpers.createGenerator('backbone:collection', [ - '../../collection', [ - helpers.createDummyGenerator(), - 'backbone-mocha:collection' - ] - ], ['foo']); - - collection.run([], function () { - helpers.assertFiles([ - ['app/scripts/collections/foo.coffee', /class Temp.Collections.Foo extends Backbone.Collection/] - ]); + test.createSubGenerator('collection', function () { + assert.fileContent( + 'app/scripts/collections/foo.coffee', /class Temp.Collections.Foo extends Backbone.Collection/ + ); + done(); }); - done(); }); }); }); - describe('Backbone Router in coffeescript', function () { - it('creates backbone router', function (done) { + describe('creates router in coffeescript', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var router = helpers.createGenerator('backbone:router', [ - '../../router', [ - helpers.createDummyGenerator(), - 'backbone-mocha:router' - ] - ], ['foo']); - - router.run([], function () { - helpers.assertFiles([ - ['app/scripts/routes/foo.coffee', /class Temp.Routers.Foo extends Backbone.Router/] - ]); + test.createSubGenerator('router', function () { + assert.fileContent( + 'app/scripts/routes/foo.coffee', /class Temp.Routers.Foo extends Backbone.Router/ + ); + done(); }); - done(); }); }); }); - describe('Backbone View in coffeescript', function () { - it('creates backbone view', function (done) { + describe('creates view in coffeescript', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var view = helpers.createGenerator('backbone:view', [ - '../../view', [ - helpers.createDummyGenerator(), - 'backbone-mocha:view' - ] - ], ['foo']); - - view.run([], function () { - helpers.assertFiles([ - ['app/scripts/views/foo.coffee', /class Temp.Views.Foo extends Backbone.View/], - 'app/scripts/templates/foo.ejs' - ]); + test.createSubGenerator('view', function () { + assert.fileContent( + 'app/scripts/views/foo.coffee', /class Temp.Views.Foo extends Backbone.View/ + ); + assert.file('app/scripts/templates/foo.ejs'); + done(); }); - done(); }); }); }); - }); diff --git a/test/test-foo.js b/test/test-foo.js index 9d85134..b9acaae 100644 --- a/test/test-foo.js +++ b/test/test-foo.js @@ -1,33 +1,11 @@ /*global describe:true, beforeEach:true, it:true */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; -var assert = require('assert'); +var yeoman = require('yeoman-generator'); +var helpers = yeoman.test; +var assert = yeoman.assert; var fs = require('fs'); - -// XXX With current API, (prior v2), that's a complete mess to setup generators -// if they differ from the standard lib/generators layout. -// -// Even for workarounds, the API is awful and doesn't let you do anything. -// -// With the new API, it will be much easier to manually register one or a set -// of generators, and manage multiple environments. -// -// Something like: -// -// generators() -// .register(require('../all'), 'backbone:all') -// .register(require('../app'), 'backbone:app') -// .register(require('../view'), 'backbone:view') -// .register(require('../router'), 'backbone:router') -// .register(require('../model'), 'backbone:model') -// .register(require('../collection'), 'backbone:collection') -// -// Or for the lazy guy: -// -// generators() -// .lookup('*:*', path.join(__dirname, '..')) -// +var test = require('./helper.js'); describe('Backbone generator test', function () { beforeEach(function (done) { @@ -36,13 +14,7 @@ describe('Backbone generator test', function () { return done(err); } this.backbone = {}; - this.backbone.app = helpers.createGenerator('backbone:app', [ - '../../app', [ - helpers.createDummyGenerator(), - 'mocha:app' - ] - ]); - this.backbone.app.options['skip-install'] = true; + this.backbone.app = test.createAppGenerator(); helpers.mockPrompt(this.backbone.app, { features: ['compassBootstrap'] @@ -73,90 +45,89 @@ describe('Backbone generator test', function () { }); describe('create expected files', function () { - it('in path /app', function (done) { - var expected = [ - ['bower.json', /"name": "temp"/], - ['package.json', /"name": "temp"/], - 'Gruntfile.js', - 'app/404.html', - 'app/favicon.ico', - 'app/robots.txt', - 'app/index.html', - 'app/.htaccess', - '.gitignore', - '.gitattributes', - '.bowerrc', - '.jshintrc', - '.editorconfig', - '.yo-rc.json', - 'app/scripts/main.js', - 'app/styles/main.scss' - ]; - - this.backbone.app.run({}, function () { - helpers.assertFiles(expected); - done(); - }); - }); + it('in path /app', function (done) { + var expectedContent = [ + ['bower.json', /"name": "temp"/], + ['package.json', /"name": "temp"/] + ]; + var expected = [ + 'Gruntfile.js', + 'app/404.html', + 'app/favicon.ico', + 'app/robots.txt', + 'app/index.html', + 'app/.htaccess', + '.gitignore', + '.gitattributes', + '.bowerrc', + '.jshintrc', + '.editorconfig', + '.yo-rc.json', + 'app/scripts/main.js', + 'app/styles/main.scss' + ]; + + this.backbone.app.run({}, function () { + assert.file(expected); + assert.fileContent(expectedContent); + done(); + }); + }); }); - describe('Backbone Model', function () { - it('creates backbone model', function (done) { - var model = helpers.createGenerator('backbone:model', ['../../model'], ['foo']); + describe('creates backbone model', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - model.run([], function () { - helpers.assertFiles([ - ['app/scripts/models/foo.js', /Models.Foo = Backbone.Model.extend\(\{/] - ]); + test.createSubGenerator('model', function () { + assert.fileContent( + 'app/scripts/models/foo.js', /Models.Foo = Backbone.Model.extend\(\{/ + ); + done(); }); - done(); }); }); }); - describe('Backbone Collection', function () { - it('creates backbone collection', function (done) { - var collection = helpers.createGenerator('backbone:collection', ['../../collection'], ['foo']); + describe('creates backbone collection', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - collection.run([], function () { - helpers.assertFiles([ - ['app/scripts/collections/foo.js', /Collections.Foo = Backbone.Collection.extend\(\{/] - ]); + test.createSubGenerator('collection', function () { + assert.fileContent( + 'app/scripts/collections/foo.js', /Collections.Foo = Backbone.Collection.extend\(\{/ + ); + done(); }); - done(); }); }); }); - describe('Backbone Router', function () { - it('creates backbone router', function (done) { - var router = helpers.createGenerator('backbone:router', ['../../router'], ['foo']); + describe('creates backbone router', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - router.run([], function () { - helpers.assertFiles([ - ['app/scripts/routes/foo.js', /Routers.Foo = Backbone.Router.extend\(\{/] - ]); + test.createSubGenerator('router', function () { + assert.fileContent( + 'app/scripts/routes/foo.js', /Routers.Foo = Backbone.Router.extend\(\{/ + ); + done(); }); - done(); }); }); }); - describe('Backbone View', function () { - it('creates backbone view', function (done) { - var view = helpers.createGenerator('backbone:view', ['../../view'], ['foo']); + describe('creates backbone view', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - view.run([], function () { - helpers.assertFiles([ - ['app/scripts/views/foo.js', /Views.Foo = Backbone.View.extend\(\{(.|\n)*app\/scripts\/templates\/foo.ejs/], - 'app/scripts/templates/foo.ejs' - ]); + test.createSubGenerator('view', function () { + assert.fileContent( + 'app/scripts/views/foo.js', /Views.Foo = Backbone.View.extend\(\{(.|\n)*app\/scripts\/templates\/foo.ejs/ + ); + assert.file('app/scripts/templates/foo.ejs'); + done(); }); - done(); }); }); }); diff --git a/test/test-handlebars.js b/test/test-handlebars.js index 32b2902..12e8adc 100644 --- a/test/test-handlebars.js +++ b/test/test-handlebars.js @@ -1,9 +1,11 @@ /*global describe:true, beforeEach:true, it:true */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; -var assert = require('assert'); +var yeoman = require('yeoman-generator'); +var helpers = yeoman.test; +var assert = yeoman.assert; var fs = require('fs'); +var test = require('./helper.js'); describe('Backbone generator with handlebars', function () { beforeEach(function (done) { @@ -12,13 +14,7 @@ describe('Backbone generator with handlebars', function () { return done(err); } this.backbone = {}; - this.backbone.app = helpers.createGenerator('backbone:app', [ - '../../app', [ - helpers.createDummyGenerator(), - 'mocha:app' - ] - ], ['temp'], {'template-framework': 'handlebars'}); - this.backbone.app.options['skip-install'] = true; + this.backbone.app = test.createAppGenerator(['temp'], {'template-framework': 'handlebars'}); helpers.mockPrompt(this.backbone.app, { features: ['compassBootstrap'], @@ -29,7 +25,8 @@ describe('Backbone generator with handlebars', function () { '{', ' "generator-backbone": {', ' "appPath": "app",', - ' "appName": "Temp"', + ' "appName": "Temp",', + ' "templateFramework": "handlebars"', ' }', '}' ]; @@ -40,18 +37,17 @@ describe('Backbone generator with handlebars', function () { }); - describe('Backbone View', function () { - it('creates backbone view', function (done) { - var view = helpers.createGenerator('backbone:view', ['../../view'], ['foo']); + describe('creates backbone view', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - view.run([], function () { - helpers.assertFiles([ - ['app/scripts/views/foo.js', /Views.Foo = Backbone.View.extend\(\{(.|\n)*app\/scripts\/templates\/foo.hbs/], - 'app/scripts/templates/foo.hbs' - ]); + test.createSubGenerator('view', function () { + assert.fileContent( + 'app/scripts/views/foo.js', /Views.Foo = Backbone.View.extend\(\{(.|\n)*app\/scripts\/templates\/foo.hbs/ + ); + assert.file('app/scripts/templates/foo.hbs'); + done(); }); - done(); }); }); }); diff --git a/test/test-mustache.js b/test/test-mustache.js index bdb887a..4963f69 100644 --- a/test/test-mustache.js +++ b/test/test-mustache.js @@ -1,9 +1,11 @@ /*global describe:true, beforeEach:true, it:true */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; -var assert = require('assert'); +var yeoman = require('yeoman-generator'); +var helpers = yeoman.test; +var assert = yeoman.assert; var fs = require('fs'); +var test = require('./helper.js'); describe('Backbone generator with mustache', function () { beforeEach(function (done) { @@ -12,13 +14,7 @@ describe('Backbone generator with mustache', function () { return done(err); } this.backbone = {}; - this.backbone.app = helpers.createGenerator('backbone:app', [ - '../../app', [ - helpers.createDummyGenerator(), - 'mocha:app' - ] - ], ['temp'], {'template-framework': 'mustache'}); - this.backbone.app.options['skip-install'] = true; + this.backbone.app = test.createAppGenerator(['temp'], {'template-framework': 'mustache'}); helpers.mockPrompt(this.backbone.app, { features: ['compassBootstrap'], @@ -29,7 +25,8 @@ describe('Backbone generator with mustache', function () { '{', ' "generator-backbone": {', ' "appPath": "app",', - ' "appName": "Temp"', + ' "appName": "Temp",', + ' "templateFramework": "mustache"', ' }', '}' ]; @@ -40,17 +37,14 @@ describe('Backbone generator with mustache', function () { }); - describe('Backbone View', function () { - it('creates backbone view', function (done) { - var view = helpers.createGenerator('backbone:view', ['../../view'], ['foo']); + it('creates backbone view', function (done) { - this.backbone.app.run({}, function () { - view.run([], function () { - helpers.assertFiles([ - ['app/scripts/views/foo.js', /Views.Foo = Backbone.View.extend\(\{(.|\n)*foo-template/], - 'app/scripts/templates/foo-template.mustache' - ]); - }); + this.backbone.app.run({}, function () { + test.createSubGenerator('view', function () { + assert.fileContent( + 'app/scripts/views/foo.js', /Views.Foo = Backbone.View.extend\(\{(.|\n)*foo-template/ + ); + assert.file('app/scripts/templates/foo-template.mustache'); done(); }); }); diff --git a/test/test-requirejs.js b/test/test-requirejs.js index 4c063e4..c3826dd 100644 --- a/test/test-requirejs.js +++ b/test/test-requirejs.js @@ -1,9 +1,11 @@ /*global describe:true, beforeEach:true, it:true */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; -var assert = require('assert'); +var yeoman = require('yeoman-generator'); +var helpers = yeoman.test; +var assert = yeoman.assert; var fs = require('fs'); +var test = require('./helper.js'); describe('Backbone generator with RequireJS', function () { beforeEach(function (done) { @@ -12,13 +14,7 @@ describe('Backbone generator with RequireJS', function () { return done(err); } this.backbone = {}; - this.backbone.app = helpers.createGenerator('backbone:app', [ - '../../app', [ - helpers.createDummyGenerator(), - 'mocha:app' - ] - ]); - this.backbone.app.options['skip-install'] = true; + this.backbone.app = test.createAppGenerator(); helpers.mockPrompt(this.backbone.app, { features: ['compassBootstrap', 'requirejs'] @@ -41,40 +37,44 @@ describe('Backbone generator with RequireJS', function () { describe('creates expected files', function () { it('with compassBootstrap', function (done) { - var expected = [ + var expectedContent = [ ['bower.json', /("name": "temp")(|.|\n)*(requirejs)/], ['package.json', /"name": "temp"/], + ['app/index.html', /(Bootstrap)(|.|\n)*(RequireJS)/i], + ['app/scripts/main.js', /bootstrap/] + ]; + var expected = [ 'Gruntfile.js', 'app/404.html', 'app/favicon.ico', 'app/robots.txt', - ['app/index.html', /(Bootstrap)(|.|\n)*(RequireJS)/i], 'app/.htaccess', '.gitignore', '.gitattributes', '.bowerrc', '.jshintrc', - '.editorconfig', - '.yo-rc.json', - ['app/scripts/main.js', /bootstrap/] + '.editorconfig' ]; this.backbone.app.run({}, function () { - helpers.assertFiles(expected); + assert.file(expected); + assert.fileContent(expectedContent); done(); }); }); it('without compassBootstrap', function (done) { - var expected = [ + var expectedContent = [ ['bower.json', /("name": "temp")(|.|\n)*(requirejs)/], ['package.json', /"name": "temp"/], ['Gruntfile.js', /requirejs/], + ['app/index.html', /(RequireJS)/i] + ]; + var expected = [ 'app/404.html', 'app/favicon.ico', 'app/robots.txt', - ['app/index.html', /(RequireJS)/i], 'app/.htaccess', '.gitignore', '.gitattributes', @@ -87,74 +87,63 @@ describe('Backbone generator with RequireJS', function () { ]; this.backbone.app.run({}, function () { - helpers.assertFiles(expected); + assert.file(expected); + assert.fileContent(expectedContent); done(); }); }); }); - describe('Backbone Model', function () { - it('creates backbone model', function (done) { + describe('creates model', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var model = helpers.createGenerator('backbone:model', ['../../model'], ['foo']); - - model.run([], function () { - helpers.assertFiles([ - ['app/scripts/models/foo.js', /var FooModel = Backbone.Model.extend\(\{/] - ]); + test.createSubGenerator('model', function () { + assert.fileContent( + 'app/scripts/models/foo.js', /var FooModel = Backbone.Model.extend\(\{/ + ); + done(); }); - - done(); }); }); }); - describe('Backbone Collection with RequireJS', function () { - it('creates backbone collection', function (done) { + describe('creates collection', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var collection = helpers.createGenerator('backbone:collection', ['../../collection'], ['foo']); - - collection.run([], function () { - helpers.assertFiles([ - ['app/scripts/collections/foo.js', /var FooCollection = Backbone.Collection.extend\(\{/] - ]); + test.createSubGenerator('collection', function () { + assert.fileContent( + 'app/scripts/collections/foo.js', /var FooCollection = Backbone.Collection.extend\(\{/ + ); + done(); }); - - done(); }); }); }); - describe('Backbone Router with RequireJS', function () { - it('creates backbone router', function (done) { + describe('creates router', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var router = helpers.createGenerator('backbone:router', ['../../router'], ['foo']); - - router.run([], function () { - helpers.assertFiles([ - ['app/scripts/routes/foo.js', /var FooRouter = Backbone.Router.extend\(\{/] - ]); + test.createSubGenerator('router', function () { + assert.fileContent( + 'app/scripts/routes/foo.js', /var FooRouter = Backbone.Router.extend\(\{/ + ); + done(); }); - - done(); }); }); }); - describe('Backbone View with RequireJS', function () { - it('creates backbone view', function (done) { + describe('creates backbone view', function () { + it('without failure', function (done) { this.backbone.app.run({}, function () { - var view = helpers.createGenerator('backbone:view', ['../../view'], ['foo']); - - view.run([], function () { - helpers.assertFiles([ - ['app/scripts/views/foo.js', /var FooView = Backbone.View.extend\(\{(.|\n)*app\/scripts\/templates\/foo.ejs/], - 'app/scripts/templates/foo.ejs' - ]); + test.createSubGenerator('view', function () { + assert.fileContent( + 'app/scripts/views/foo.js', /var FooView = Backbone.View.extend\(\{(.|\n)*app\/scripts\/templates\/foo.ejs/ + ); + assert.file('app/scripts/templates/foo.ejs'); + done(); }); - done(); }); }); }); - });