Permalink
Browse files

test suite organization pass

  • Loading branch information...
Sam Breed
Sam Breed committed Feb 5, 2012
1 parent 61dcd12 commit c3db1d30899e0b02590bd45168d558b2bafcb472
View
@@ -27,13 +27,13 @@ routes.index = function( req, res, next ){
routes.api = {};
-routes.api.index = function( req, res, next ){
+routes.api.index = function( req, res ){
if( !req.user ){
return res.send({ error: "Not found" }, 404);
}
- res.send( req.user );
+ res.send( req.user, 200 );
};
View
@@ -0,0 +1,4 @@
+var
+ routes = require('./routes'),
+ models = require('./models');
+
View
@@ -0,0 +1,35 @@
+exports.request = function(){
+ return {
+
+ body: {},
+
+ params: {},
+
+ user: {
+
+ get: function(){
+ return 'old-dude';
+ }
+
+ }
+
+ };
+};
+
+exports.response = function( cb ){
+ return {
+
+ render: function( path, context ){
+ return cb.apply( this, arguments );
+ },
+
+ send: function( res, code ){
+ return cb.apply( this, arguments );
+ },
+
+ redirect: function( path ){
+ return cb.apply( this, arguments );
+ }
+
+ };
+};
View
@@ -1,127 +0,0 @@
-var
- models = require('../lib/models'),
- fixtures = require('./fixtures'),
- assert = require('assert');
-
-/* ------------------------------ Stout ------------------------------ */
-
-describe('Stout', function(){
-
- beforeEach(function( done ){
- this.stout = new models.stout( fixtures.stout );
- this.stout.save( done );
- });
-
- after(function( done ){
- models.stout.remove({ "slug" : "meat-packer-stout" }, done );
- });
-
- it('should exist', function(){
- assert.ok( models.stout );
- assert.ok( this.stout );
- });
-
- it('should supply default text for (certain) empty fields', function(){
- assert.equal( this.stout.og, '??' );
- });
-
- describe('rating', function(){
-
- it('should calculate the average rating', function(){
- assert.equal( this.stout.rating, 4 ); // 4 / 1
- });
-
- it('should set raw_rating incrementally', function( done ){
- this.stout.raw_rating = 4;
-
- this.stout.save(function( err, stout ){
- assert.equal( stout.raw_rating, 8 );
- done();
- });
- });
-
- it('should increment ratings on save', function(){
- assert( this.stout.ratings, 2 );
- });
-
- });
-
- describe('slug', function(){
-
- it('should prettify the stout slug', function(){
- assert.equal( this.stout.slug, 'meat-packer-stout' );
- });
-
- });
-
-});
-
-/* ------------------------------ Drink ------------------------------ */
-
-describe('Drink', function(){
-
- beforeEach(function( done ){
- this.drink = new models.drink( fixtures.factory.drink() );
- this.drink.save( done );
- });
-
- after(function( done ){
- models.drink.remove({ user: this.drink.user }, done);
- });
-
- it('should exist', function(){
- assert.ok( models.drink );
- assert.ok( this.drink );
- });
-
- describe('count', function(){
-
- it('should have a default value of 1', function(){
- assert.ok( this.drink.count, 0 );
- });
-
- it('should increment count when set', function( done ){
- this.drink.count = 1;
-
- this.drink.save(function( err, drink ){
- if( err ) throw err;
-
- assert.equal( drink.count, 1 );
- done();
- });
- });
-
- });
-
- describe('#getTotal', function(){
-
- it('should get the total number of drinks for a user', function( done ){
- var drink = new models.drink( fixtures.factory.drink({
- beer: 'some-other-sout',
- count: 1
- }) );
-
- drink.save(function( err, drink ){
-
- models.drink.getTotal( drink.user, function(err, total){
- assert.equal( total, 2 );
- done();
- });
-
- });
- });
-
- });
-
-});
-
-/* ------------------------------ User ------------------------------ */
-
-describe('User', function(){
-
- it('should exist', function(){
- assert.ok( models.user );
- });
-
-});
-
View
@@ -0,0 +1,65 @@
+var
+ models = require('../../lib/models'),
+ fixtures = require('../fixtures'),
+ assert = require('assert');
+
+/* ------------------------------ Drink ------------------------------ */
+
+describe('Drink', function(){
+
+ beforeEach(function( done ){
+ this.drink = new models.drink( fixtures.factory.drink() );
+ this.drink.save( done );
+ });
+
+ after(function( done ){
+ models.drink.remove({ user: this.drink.user }, done);
+ });
+
+ it('should exist', function(){
+ assert.ok( models.drink );
+ assert.ok( this.drink );
+ });
+
+ describe('count', function(){
+
+ it('should have a default value of 1', function(){
+ assert.ok( this.drink.count, 0 );
+ });
+
+ it('should increment count when set', function( done ){
+ this.drink.count = 1;
+
+ this.drink.save(function( err, drink ){
+ if( err ) throw err;
+
+ assert.equal( drink.count, 1 );
+ done();
+ });
+ });
+
+ });
+
+ describe('#getTotal', function(){
+
+ it('should get the total number of drinks for a user', function( done ){
+ var drink = new models.drink( fixtures.factory.drink({
+ beer: 'some-other-sout',
+ count: 1
+ }) );
+
+ drink.save(function( err, drink ){
+
+ models.drink.getTotal( drink.user, function(err, total){
+ assert.equal( total, 2 );
+ done();
+ });
+
+ });
+ });
+
+ });
+
+});
+
+
View
@@ -0,0 +1,4 @@
+var
+ drink = require('./drink'),
+ stout = require('./stout'),
+ user = require('./user');
View
@@ -0,0 +1,59 @@
+var
+ models = require('../../lib/models'),
+ fixtures = require('../fixtures'),
+ assert = require('assert');
+
+/* ------------------------------ Stout ------------------------------ */
+
+describe('Stout', function(){
+
+ beforeEach(function( done ){
+ this.stout = new models.stout( fixtures.stout );
+ this.stout.save( done );
+ });
+
+ after(function( done ){
+ models.stout.remove({ "slug" : "meat-packer-stout" }, done );
+ });
+
+ it('should exist', function(){
+ assert.ok( models.stout );
+ assert.ok( this.stout );
+ });
+
+ it('should supply default text for (certain) empty fields', function(){
+ assert.equal( this.stout.og, '??' );
+ });
+
+ describe('rating', function(){
+
+ it('should calculate the average rating', function(){
+ assert.equal( this.stout.rating, 4 ); // 4 / 1
+ });
+
+ it('should set raw_rating incrementally', function( done ){
+ this.stout.raw_rating = 4;
+
+ this.stout.save(function( err, stout ){
+ assert.equal( stout.raw_rating, 8 );
+ done();
+ });
+ });
+
+ it('should increment ratings on save', function(){
+ assert( this.stout.ratings, 2 );
+ });
+
+ });
+
+ describe('slug', function(){
+
+ it('should prettify the stout slug', function(){
+ assert.equal( this.stout.slug, 'meat-packer-stout' );
+ });
+
+ });
+
+});
+
+
View
@@ -0,0 +1,15 @@
+var
+ models = require('../../lib/models'),
+ fixtures = require('../fixtures'),
+ assert = require('assert');
+
+/* ------------------------------ User ------------------------------ */
+
+describe('User', function(){
+
+ it('should exist', function(){
+ assert.ok( models.user );
+ });
+
+});
+
Oops, something went wrong.

0 comments on commit c3db1d3

Please sign in to comment.