Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
Refactoring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
revathskumar committed May 15, 2014
1 parent bc90178 commit 187e32b
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 356 deletions.
26 changes: 26 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -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;
};
89 changes: 41 additions & 48 deletions test/test-apppath.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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']
Expand All @@ -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',
Expand All @@ -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();
});
});
});
Expand Down
90 changes: 42 additions & 48 deletions test/test-coffee-requirejs.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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']
Expand All @@ -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',
Expand All @@ -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();

});
});
});
Expand Down
Loading

0 comments on commit 187e32b

Please sign in to comment.