Permalink
Browse files

Updated tests to use new Jake TestTask.

  • Loading branch information...
1 parent c389ea9 commit c2c0c1954591e009a8b53e983caaddb664078a27 mde committed Jun 24, 2012
Showing with 143 additions and 181 deletions.
  1. +8 −2 Jakefile
  2. +1 −7 test/ejs.js
  3. +4 −11 test/event_buffer.js
  4. +23 −26 test/model_create_user.js
  5. +19 −32 test/model_datatypes.js
  6. +64 −67 test/regexp_router.js
  7. +11 −17 test/sorted_collection.js
  8. +13 −19 test/xml.js
View
10 Jakefile
@@ -3,7 +3,8 @@ require('./lib/geddy')
var fs = require('fs')
, createPackageTask
- , JSPAT = /\.js$/;
+ , JSPAT = /\.js$/
+ , testTask;
namespace('doc', function () {
task('generate', ['doc:clobber'], function () {
@@ -64,8 +65,13 @@ var p = new jake.NpmPublishTask('geddy', [
// set up the package part included in the publish-task
jake.Task['npm:definePackage'].invoke();
-var t = jake.TestTask('Geddy model-adapters', function () {
+testTask = new jake.TestTask('Geddy', function () {
+ this.testFiles.include('test/*.js');
+});
+
+testTask = new jake.TestTask('Geddy model-adapters', function () {
this.testName = 'testModelAdapters'
this.testFiles.include('lib/model/adapters/**/test.js');
});
+
View
8 test/ejs.js
@@ -216,10 +216,4 @@ tests = {
};
-for (var p in tests) {
- if (typeof tests[p] == 'function') {
- console.log('Running ' + p);
- tests[p]();
- }
-}
-
+module.exports = tests;
View
15 test/event_buffer.js
@@ -7,9 +7,9 @@ var Stream = require('stream').Stream
, assert = require('assert')
, tests;
-tests = new (function () {
+tests = {
- this.testEventBuffer = function () {
+ 'test basic event buffer functionality': function () {
var source = new Stream()
, dest = new EventEmitter()
, buff = new EventBuffer(source)
@@ -23,15 +23,8 @@ tests = new (function () {
assert.equal('abcdef123456', data);
source.emit('data', '---');
assert.equal('abcdef123456---', data);
- };
-
-})();
-
-for (var p in tests) {
- if (typeof tests[p] == 'function') {
- console.log('Running ' + p);
- tests[p]();
}
-}
+};
+module.exports = tests;
View
49 test/model_create_user.js
@@ -9,7 +9,8 @@ geddy.config = {
var model = require('../lib/model')
, assert = require('assert')
- , tests;
+ , tests
+ , _params;
geddy.model = model;
@@ -32,57 +33,53 @@ User.prototype.someMethod = function () {
User = geddy.model.register('User', User);
-var tests = new (function () {
- var _params = {
- login: 'zzz',
- password: 'asdf',
- confirmPassword: 'asdf',
- firstName: 'Neil'
- };
+_params = {
+ login: 'zzz',
+ password: 'asdf',
+ confirmPassword: 'asdf',
+ firstName: 'Neil'
+};
+
+var tests = {
- this.testValid = function () {
+ 'test validity': function () {
var user = User.create(_params);
assert.ok(user.isValid());
- };
+ }
- this.testShortLogin = function () {
+
+, 'test login is too short': function () {
_params.login = 'zz'; // Too short, invalid
var user = User.create(_params);
assert.ok(typeof user.errors.login != 'undefined');
- };
+ }
- this.testInvalidLoginWithCustomMessage = function () {
+, 'test invalid login with custom error message': function () {
_params.login = '2112'; // Contains numbers, invalid
var user = User.create(_params);
// Error message should be customized
assert.ok(user.errors.login, 'Subdivisions!');
- };
+ }
- this.testNoLogin = function () {
+, 'test missing login': function () {
delete _params.login; // Contains numbers, invalid
var user = User.create(_params);
// Error message should be customized
assert.ok(typeof user.errors.login != 'undefined');
_params.login = 'zzz'; // Restore to something valid
- };
+ }
- this.testNoConfirmPassword = function () {
+, 'test no password confirmation': function () {
_params.confirmPassword = 'fdsa';
var user = User.create(_params);
// Error message should be customized
assert.ok(typeof user.errors.password != 'undefined');
_params.confirmPassword = 'asdf'; // Restore to something valid
- };
-
-})();
-
-for (var p in tests) {
- if (typeof tests[p] == 'function') {
- console.log('Running ' + p);
- tests[p]();
}
-}
+};
+
+module.exports = tests;
View
51 test/model_datatypes.js
@@ -25,14 +25,14 @@ var ByTor = function () {
ByTor = geddy.model.register('ByTor', ByTor);
-var tests = new (function () {
- this.testAllOptional = function () {
+var tests = {
+ 'test all properties optional': function () {
var params = {};
var byTor = ByTor.create(params);
assert.ok(byTor.isValid());
- };
+ }
- this.testNumber = function () {
+, 'test number': function () {
var byTor;
// Actual number, valid
byTor = ByTor.create({numberProp: 2112});
@@ -45,10 +45,9 @@ var tests = new (function () {
// Non-numeric string, error
byTor = ByTor.create({numberProp: 'Snow Dog'});
assert.notStrictEqual(byTor.errors.numberProp, undefined);
+ }
- };
-
- this.testInt = function () {
+, 'test integer': function () {
var byTor;
// Actual int, valid
byTor = ByTor.create({intProp: 2112});
@@ -69,10 +68,9 @@ var tests = new (function () {
// Non-numeric string, error
byTor = ByTor.create({intProp: 'away from here'});
assert.notStrictEqual(byTor.errors.intProp, undefined);
+ }
- };
-
- this.testObject = function () {
+, 'test object': function () {
var byTor;
// Actual Object, valid
byTor = ByTor.create({objectProp: {}});
@@ -85,10 +83,9 @@ var tests = new (function () {
// string, should fail
byTor = ByTor.create({objectProp: 'As gray traces of dawn ...'});
assert.notStrictEqual(byTor.errors.objectProp, undefined);
+ }
- };
-
- this.testArray = function () {
+, 'test array': function () {
var byTor;
// Actual Array, valid
byTor = ByTor.create({arrayProp: []});
@@ -101,10 +98,9 @@ var tests = new (function () {
// string, should fail
byTor = ByTor.create({arrayProp: 'As gray traces of dawn ...'});
assert.notStrictEqual(byTor.errors.arrayProp, undefined);
+ }
- };
-
- this.testDate = function () {
+, 'test date': function () {
var byTor;
var dates = [
'12/27/1968'
@@ -127,10 +123,9 @@ var tests = new (function () {
assert.equal(byTor.dateProp.getMonth(), 11, 'Testing getMonth'); // Zero-based
assert.equal(byTor.dateProp.getDate(), 27, 'Testing getDate');
}
+ }
- };
-
- this.testDatetime = function () {
+, 'test datetime': function () {
var byTor;
var dates, dt;
// Dates with no set time -- time should be set to 12 midnight
@@ -172,10 +167,9 @@ var tests = new (function () {
assert.equal(byTor.datetimeProp.getMinutes(), 10);
assert.equal(byTor.datetimeProp.getSeconds(), 3);
}
+ }
- };
-
- this.testTime = function () {
+, 'test time': function () {
var byTor;
var dates, dt, vals;
// Obj key is the input string, value is the list of values
@@ -196,16 +190,9 @@ var tests = new (function () {
assert.equal(byTor.timeProp.getSeconds(), vals[2]);
assert.equal(byTor.timeProp.getMilliseconds(), vals[3]);
}
-
- };
-
-})();
-
-for (var p in tests) {
- if (typeof tests[p] == 'function') {
- console.log('Running ' + p);
- tests[p]();
}
-}
+};
+
+module.exports = tests;
View
131 test/regexp_router.js
@@ -7,103 +7,106 @@ var Router = require('../lib/routers/regexp_router').RegExpRouter
tests = {
// create a router
- testCreateRouter: function() {
+ 'test create router': function () {
router = new Router();
assert.ok(router);
- },
+ }
// create a simple route
- testCreateSimpleRoute: function() {
+, 'test create simple route': function () {
router = new Router();
var route = router.match('/:controller/:action/:id');
assert.ok(route);
- },
+ }
// create a route with optional segments
- testCreateOptionalRoute: function() {
+, 'test create optional route': function () {
router = new Router();
var route = router.match('/:controller/:action/:id(.:format)')
assert.ok(route)
- },
+ }
// create a route with multiple optional segments
- testCreateMultipleOptionalRoute: function() {
+, 'test create multiple optional route': function () {
router = new Router();
var route = router.match('/:controller/:id(/:action)(.:format)')
assert.ok(route)
- },
+ }
// create a resource
- testCreateResource: function() {
+, 'test create resource': function () {
router = new Router();
var routes = router.resource('SnowDogs');
assert.ok(routes.length === 11)
for (var i in routes) {
assert.ok(route)
}
- },
+ }
// create a static route with fixed params
- testRouteWithParams: function() {
+, 'test route with params': function () {
router = new Router();
- var route = router.match('/hello/there').to( { controller:'Application', action: 'index' } );
+ var route = router.match('/hello/there')
+ .to( { controller:'Application', action: 'index' } );
assert.ok(route)
- },
+ }
// create a static route with extra fixed params
- testRouteWithExtraParams: function() {
+, 'test route with extra params': function () {
router = new Router();
- var route = router.match('/hello/there').to( { controller:'Application', action: 'index', language: 'english' } );
+ var route = router.match('/hello/there')
+ .to( { controller:'Application', action: 'index', language: 'english' } );
assert.ok(route)
- },
+ }
// create a static route with a specific request method
- testRouteWithMethod: function() {
+, 'test route with method': function () {
router = new Router();
var route = router.match('/:controller/:action', 'GET');
assert.ok(route)
- },
+ }
// create a static route with key regex match requirements
- testRouteWithRegexReqs: function() {
+, 'test route with regex reqs': function () {
router = new Router();
var route = router.match('/:controller/:action/:id', { id: /\d+/ } );
assert.ok(route)
- },
+ }
// create a static route with key match requirements as a regex string
- testRouteWithStringRegexReqs: function() {
+, 'test route with string regex reqs': function () {
router = new Router();
var route = router.match('/:controller/:action/:id', { id: '\\d+' } );
assert.ok(route)
- },
+ }
// create a static route with key match requirements AND a method
- testRouteWithReqsAndMethod: function() {
+, 'test route with reqs and method': function () {
router = new Router();
var route = router.match('/:controller/:action/:id', 'GET', { id: /\d+/ } );
assert.ok(route)
- },
+ }
// create a static route with key match requirements AND a method in reverse order
- testRouteWithReqsAndMethodReversed: function() {
+, 'test route with reqs and method reversed': function () {
router = new Router();
var route = router.match('/:controller/:action/:id', { id: /\d+/ }, 'GET' );
assert.ok(route)
- },
+ }
// create a static route with key match requirements AND a method in reverse order
- testRouteWithName: function() {
+, 'test route with name': function () {
router = new Router();
- var route = router.match('/:controller/:action/:id', { id: /\d+/ }, 'GET' ).name('aweosme');
+ var route = router.match('/:controller/:action/:id',
+ { id: /\d+/ }, 'GET' ).name('aweosme');
assert.ok(route)
- },
+ }
// ok - let's start doing things with these routes
// test that the router matches a URL
- testSimpleRouteParses: function() {
+, 'test simple route parses': function () {
router = new Router();
var route = router.match('/:controller/:action/:id');
var params = router.first({url: '/products/show/1'},'GET');
@@ -112,10 +115,10 @@ tests = {
assert.equal(params.action, 'show');
assert.equal(params.id, 1);
assert.equal(params.method, 'GET');
- },
+ }
// test that the router matches a URL
- testSimpleRouteParsesWithOptionalSegment: function() {
+, 'test simple route parses with optional segment': function () {
router = new Router();
var route = router.match('/:controller/:action/:id(.:format)');
var params = router.first({url: '/products/show/1.html'},'GET');
@@ -125,9 +128,9 @@ tests = {
assert.equal(params.id, 1);
assert.equal(params.method, 'GET');
assert.equal(params.format, 'html');
- },
+ }
- testSimpleRouteParsesWithOptionalSegmentMissing: function() {
+, 'test simple route parses with optional segment missing': function () {
router = new Router();
var route = router.match('/:controller/:action/:id(.:format)','GET');
var params = router.first({url: '/products/show/1'},'GET');
@@ -137,16 +140,16 @@ tests = {
assert.equal(params.id, 1);
assert.equal(params.method, 'GET');
assert.equal(typeof(params.format), 'undefined');
- },
+ }
- testSimpleRouteFailingDueToBadMethod: function() {
+, 'test simple route failing due to bad method': function () {
router = new Router();
var route = router.match('/:controller/:action/:id(.:format)','GET');
var params = router.first({url: '/products/show/1'},'POST');
assert.equal(params instanceof Error, true);
- },
+ }
- testSimpleRouteWithTwoOptionalSegments: function() {
+, 'test simple route with two optional segments': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)','GET');
var params = router.first({url: '/products/show'},'GET');
@@ -156,9 +159,9 @@ tests = {
assert.equal(typeof(params.id), 'undefined');
assert.equal(typeof(params.format), 'undefined');
assert.equal(params.method, 'GET');
- },
+ }
- testSimpleRouteWithTwoOptionalSegmentsWithFirstUsed: function() {
+, 'test simple route with two optional segments with first used': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)','GET');
var params = router.first({url: '/products/show/1'},'GET');
@@ -168,9 +171,9 @@ tests = {
assert.equal(params.id, 1);
assert.equal(typeof(params.format), 'undefined');
assert.equal(params.method, 'GET');
- },
+ }
- testSimpleRouteWithTwoOptionalSegmentsWithSecondUsed: function() {
+, 'test simple route with two optional segments with second used': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)','GET');
var params = router.first({url: '/products/show.html'},'GET');
@@ -180,9 +183,9 @@ tests = {
assert.equal(typeof(params.id), 'undefined');
assert.equal(params.format, 'html');
assert.equal(params.method, 'GET');
- },
+ }
- testSimpleRouteWithTwoOptionalSegmentsWithBothUsed: function() {
+, 'test simple route with two optional segments with both used': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)','GET');
var params = router.first({url: '/products/show/1.html'},'GET');
@@ -192,45 +195,45 @@ tests = {
assert.equal(params.id, 1);
assert.equal(params.format, 'html');
assert.equal(params.method, 'GET');
- },
+ }
// fuck, how repetitive. how about methods for a bit?
- testGET: function() {
+, 'test GET': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)','GET');
var params = router.first({url: '/products/show/1.html'},'GET');
assert.ok(params);
assert.equal(params.method, 'GET');
- },
+ }
- testPOST: function() {
+, 'test POST': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)','POST');
var params = router.first({url: '/products/show/1.html'},'POST');
assert.ok(params);
assert.equal(params.method, 'POST');
- },
+ }
- testPUT: function() {
+, 'test PUT': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)','PUT');
var params = router.first({url: '/products/show/1.html'},'PUT');
assert.ok(params);
assert.equal(params.method, 'PUT');
- },
+ }
- testDELETE: function() {
+, 'test DELETE': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)','DELETE');
var params = router.first({url: '/products/show/1.html'},'DELETE');
assert.ok(params);
assert.equal(params.method, 'DELETE');
- },
+ }
// that was fun. Let's do a little resource testing
- testResourceMatches: function() {
+, 'test resource matches': function () {
router = new Router();
var routes = router.resource('SnowDogs');
// index
@@ -261,11 +264,11 @@ tests = {
assert.ok(router.first({url:'/snow_dogs/1'},'DELETE'));
assert.ok(router.first({url:'/snow_dogs/1.html'},'DELETE'));
assert.equal(router.first({url:'/snow_dogs/1'},'DELETE').action, 'remove');
- },
+ }
// url generation time nao
- testResourceUrlGeneration: function() {
+, 'test resource url generation': function () {
router = new Router();
var routes = router.resource('SnowDogs');
// index
@@ -297,9 +300,9 @@ tests = {
assert.equal(router.url( { controller:'SnowDogs', action:'remove', id:1, format: 'html' } ), '/snow_dogs/1.html');
assert.equal(router.url( { controller:'SnowDogs', action:'remove', id:1, format: 'json' } ), '/snow_dogs/1.json');
- },
+ }
- testRouteUrlGeneration: function() {
+, 'test route url generation': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)');
assert.equal(router.url( { controller:'SnowDogs', action:'pet' } ), '/snow_dogs/pet');
@@ -308,20 +311,14 @@ tests = {
assert.equal(router.url( { controller:'SnowDogs', action:'pet', id:5, format:'json' } ), '/snow_dogs/pet/5.json');
assert.equal(router.url( { controller:'SnowDogs', action:'pet', format:'html' } ), '/snow_dogs/pet.html');
- },
+ }
- testDefaultValues: function() {
+, 'test default values': function () {
router = new Router();
var route = router.match('/:controller/:action(/:id)(.:format)');
assert.equal(router.url(), '/application/index');
}
};
-for (var p in tests) {
- if (typeof tests[p] == 'function') {
- console.log('Running ' + p);
- tests[p]();
- }
-}
-
+module.exports = tests;
View
28 test/sorted_collection.js
@@ -5,9 +5,9 @@ var SortedCollection = geddy.SortedCollection
, assert = require('assert')
, tests;
-tests = new (function () {
+tests = {
- this.testNoDefault = function () {
+ 'test no default value': function () {
// Set up a collection, no default value for new items
var c = new geddy.SortedCollection();
// Add some items
@@ -30,9 +30,9 @@ tests = new (function () {
c.setItem(2, 'cccc');
var item = c.getItem(2);
assert.equal('cccc', item);
- };
+ }
- this.testDefaultValue = function () {
+, 'test default value': function () {
// Set up a collection, default value for new items is 'foo'
var c = new geddy.SortedCollection('foo');
// Add an item with no value -- should get
@@ -49,9 +49,9 @@ tests = new (function () {
assert.equal(null, item);
var item = c.getItem('testC');
assert.equal(false, item);
- };
+ }
- this.testEach = function () {
+, 'test each': function () {
var c = new geddy.SortedCollection()
, str = '';
// Add an item with no value -- should get
@@ -64,9 +64,9 @@ tests = new (function () {
str += val + key;
});
assert.equal('AaBbCcDd', str);
- };
+ }
- this.testRemoveItem = function () {
+, 'test removing an item': function () {
var c = new geddy.SortedCollection()
, str = '';
// Add an item with no value -- should get
@@ -84,14 +84,8 @@ tests = new (function () {
str += val + key;
});
assert.equal('AaBbDd', str);
- };
-
-})();
-
-for (var p in tests) {
- if (typeof tests[p] == 'function') {
- console.log('Running ' + p);
- tests[p]();
}
-}
+};
+
+module.exports = tests;
View
32 test/xml.js
@@ -10,50 +10,44 @@ var serialize = function (o) {
return XML.stringify(o, {whitespace: false});
};
-var tests = new (function () {
+var tests = {
- this.testObject = function () {
+ 'test serialized object': function () {
obj = {foo: 'bar'};
xml = serialize(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><object><foo>bar</foo></object>';
assert.equal(res, xml);
- };
+ }
- this.testArrayNumbers = function () {
+, 'test array of numbers': function () {
obj = [1, 2, 3];
xml = serialize(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><numbers type="array"><number>1</number><number>2</number><number>3</number></numbers>';
assert.equal(res, xml);
- };
+ }
- this.testArrayStrings = function () {
+, 'test array of strings': function () {
obj = ['foo', 'bar'];
xml = serialize(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><strings type="array"><string>foo</string><string>bar</string></strings>';
assert.equal(res, xml);
- };
+ }
- this.testArrayMixed = function () {
+, 'test array of mixed datatypes': function () {
obj = ['foo', 1];
xml = serialize(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><records type="array"><record>foo</record><record>1</record></records>';
assert.equal(res, xml);
- };
+ }
- this.testArrayPropOfObject = function () {
+, 'test array property of an object': function () {
obj = {foo: ['bar', 'baz']};
xml = serialize(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><object><foo type="array"><foo>bar</foo><foo>baz</foo></foo></object>';
assert.equal(res, xml);
- };
-
-})();
-
-for (var p in tests) {
- if (typeof tests[p] == 'function') {
- console.log('Running ' + p);
- tests[p]();
}
-}
+};
+
+module.exports = tests;

0 comments on commit c2c0c19

Please sign in to comment.