Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

started mvc acceptance tests

  • Loading branch information...
commit 1e85178c737820d98a83efdebac3e58caecd593d 1 parent d0bc0ad
@tj tj authored
View
2  Makefile
@@ -16,7 +16,7 @@ test:
test-acceptance:
@NODE_ENV=test ./node_modules/.bin/mocha \
- --reporter spec \
+ --reporter $(REPORTER) \
test/acceptance/*.js
test-cov: lib-cov
View
10 examples/mvc/index.js
@@ -1,7 +1,7 @@
var express = require('../..');
-var app = express();
+var app = module.exports = express();
// settings
@@ -62,7 +62,9 @@ app.use(express.bodyParser());
app.use(express.methodOverride());
// load controllers
-require('./lib/boot')(app);
+require('./lib/boot')(app, { verbose: !module.parent });
-app.listen(3000);
-console.log('\n listening on port 3000\n');
+if (!module.parent) {
+ app.listen(3000);
+ console.log('\n listening on port 3000\n');
+}
View
9 examples/mvc/lib/boot.js
@@ -2,10 +2,11 @@
var express = require('../../..')
, fs = require('fs');
-module.exports = function(parent){
- console.log();
+module.exports = function(parent, options){
+ var verbose = options.verbose;
+ verbose && console.log();
fs.readdirSync(__dirname + '/../controllers').forEach(function(name){
- console.log(' %s:', name);
+ verbose && console.log(' %s:', name);
var obj = require('./../controllers/' + name)
, name = obj.name || name
, prefix = obj.prefix || ''
@@ -55,7 +56,7 @@ module.exports = function(parent){
path = prefix + path;
app[method](path, obj[key]);
- console.log(' %s %s -> %s', method.toUpperCase(), path, key);
+ verbose && console.log(' %s %s -> %s', method.toUpperCase(), path, key);
}
// mount the app
View
63 test/acceptance/mvc.js
@@ -0,0 +1,63 @@
+
+var request = require('../support/http')
+ , app = require('../../examples/mvc');
+
+describe('mvc', function(){
+ describe('GET /', function(){
+ it('should redirect to /users', function(done){
+ request(app)
+ .get('/')
+ .end(function(res){
+ res.should.have.status(302);
+ res.headers.location.should.include('/users');
+ done();
+ })
+ })
+ })
+
+ describe('GET /users', function(){
+ it('should display a list of users', function(done){
+ request(app)
+ .get('/users')
+ .end(function(res){
+ res.body.should.include('<h1>Users</h1>');
+ res.body.should.include('>TJ<');
+ res.body.should.include('>Guillermo<');
+ res.body.should.include('>Nathan<');
+ done();
+ })
+ })
+ })
+
+ describe('GET /user/:id', function(){
+ describe('when present', function(){
+ it('should display the user', function(done){
+ request(app)
+ .get('/user/0')
+ .end(function(res){
+ res.body.should.include('<h1>TJ <a href="/user/0/edit">edit');
+ done();
+ })
+ })
+
+ it('should display the users pets', function(done){
+ request(app)
+ .get('/user/0')
+ .end(function(res){
+ res.body.should.include('/pet/0">Tobi');
+ res.body.should.include('/pet/1">Loki');
+ res.body.should.include('/pet/2">Jane');
+ done();
+ })
+ })
+ })
+
+ describe('when not present', function(){
+ it('should 404', function(done){
+ request(app)
+ .get('/user/123')
+ .expect(404, done);
+ })
+ })
+ })
+})
Please sign in to comment.
Something went wrong with that request. Please try again.