Browse files

refactor

  • Loading branch information...
1 parent c6d7352 commit a566624f2df70a4e2b06f33a8ebde404994e7b86 @tj tj committed Apr 1, 2013
Showing with 34 additions and 52 deletions.
  1. +34 −52 test/res.redirect.js
View
86 test/res.redirect.js
@@ -170,93 +170,75 @@ describe('res', function(){
})
})
- describe('responses redirected to dotted relative paths', function () {
-
- /* The requisite test fixtures are repetitive. */
- var makeApp = function (depth, parent) {
+ describe('responses redirected to relative paths', function(){
+ function create(depth, parent) {
var app = express();
if (parent) {
parent.use('/depth' + depth, app);
}
- app.get('/', function (req, res) {
+ app.get('/', function(req, res){
res.redirect('./index');
});
- app.get('/index', function (req, res) {
- res.json({depth : depth, content : 'index'});
+ app.get('/index', function(req, res){
+ res.json({ depth: depth, content: 'index' });
});
return app;
}
- var root = makeApp(0);
- var depth1 = makeApp(1, root);
- var depth2 = makeApp(2, depth1);
- var depth3 = makeApp(3, depth2);
+ var root = create(0);
+ var depth1 = create(1, root);
+ var depth2 = create(2, depth1);
+ var depth3 = create(3, depth2);
- /* Special cases for alias paths. */
root.use('/depth2', depth2);
root.use('/depth3', depth3);
- /*
- * The resulting structure resembles the following.
- *
- * / -> root
- *
- * /depth1 -> depth1
- * /depth1/depth2 -> depth2
- * /depth1/depth2/depth3 -> depth3
- *
- * /depth2 -> depth2
- * /depth3 -> depth3
- */
-
- it('should not contain redundant leading slashes in the location header', function (done) {
+ it('should not contain redundant leading slashes in the location header', function(done){
request(root)
- .get('/')
- .end(function (err, res) {
- res.headers.location.search(/^\/{2}/).should.equal(-1);
- done();
- })
+ .get('/')
+ .end(function(err, res){
+ res.headers.location.search(/^\/{2}/).should.equal(-1);
+ done();
+ })
})
it('should preserve context when redirecting nested applications at any depth', function(done){
request(root)
- .get('/depth1')
- .end(function(err, res) {
- res.headers.should.have.property('location', '/depth1/./index');
- });
+ .get('/depth1')
+ .end(function(err, res){
+ res.headers.should.have.property('location', '/depth1/./index');
- request(root)
+ request(root)
.get('/depth1/depth2')
- .end(function(err, res) {
+ .end(function(err, res){
res.headers.should.have.property('location', '/depth1/depth2/./index');
- })
- request(root)
- .get('/depth1/depth2/depth3')
- .end(function(err, res) {
- res.headers.should.have.property('location', '/depth1/depth2/depth3/./index');
- done();
+ request(root)
+ .get('/depth1/depth2/depth3')
+ .end(function(err, res){
+ res.headers.should.have.property('location', '/depth1/depth2/depth3/./index');
+ done();
+ })
})
+ });
})
- it('should redirect correctly for nested applications that have been remounted', function (done) {
- request(root)
- .get('/depth2')
- .end(function (err, res) {
- res.headers.should.have.property('location', '/depth2/./index');
- })
-
+ it('should redirect correctly for nested applications that have been remounted', function(done){
request(root)
+ .get('/depth2')
+ .end(function(err, res){
+ res.headers.should.have.property('location', '/depth2/./index');
+ request(root)
.get('/depth3')
- .end(function (err, res) {
+ .end(function(err, res){
res.headers.should.have.property('location', '/depth3/./index');
done();
})
+ })
})
-
})
})

0 comments on commit a566624

Please sign in to comment.