diff --git a/examples/resource/app.js b/examples/resource/app.js index 7aa5b13d..ed1810e8 100644 --- a/examples/resource/app.js +++ b/examples/resource/app.js @@ -18,7 +18,10 @@ app.resource = function(path, obj) { obj.range(req, res, a, b, format); }); this.get(path + '/:id', obj.show); - this.delete(path + '/:id', obj.destroy); + this.delete(path + '/:id', function(req, res){ + var id = parseInt(req.params.id, 10); + obj.destroy(req, res, id); + }); }; // Fake records @@ -41,8 +44,7 @@ var User = { show: function(req, res){ res.send(users[req.params.id] || { error: 'Cannot find user' }); }, - destroy: function(req, res){ - var id = req.params.id; + destroy: function(req, res, id){ var destroyed = id in users; delete users[id]; res.send(destroyed ? 'destroyed' : 'Cannot find user'); diff --git a/package.json b/package.json index 786a5e9b..88e71591 100644 --- a/package.json +++ b/package.json @@ -65,8 +65,8 @@ "devDependencies": { "ejs": "~0.8.4", "istanbul": "0.2.10", - "mocha": "~1.19.0", - "should": "~3.3.1", + "mocha": "~1.20.0", + "should": "~4.0.0", "jade": "~0.30.0", "hjs": "~0.0.6", "stylus": "~0.40.0", diff --git a/test/acceptance/ejs.js b/test/acceptance/ejs.js index b51c03be..12defcb5 100644 --- a/test/acceptance/ejs.js +++ b/test/acceptance/ejs.js @@ -7,14 +7,11 @@ describe('ejs', function(){ it('should respond with html', function(done){ request(app) .get('/') - .end(function(err, res){ - res.should.have.status(200); - res.should.have.header('Content-Type', 'text/html; charset=utf-8'); - res.text.should.include('
{{user.name}}
'); - done(); - }); + .expect('Content-Type', 'text/html; charset=UTF-8') + .expect('Content-Disposition', 'attachment; filename="user.html"') + .expect(200, '{{user.name}}
', done) }) }) @@ -33,11 +30,9 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - res.should.have.header('Content-Type', 'text/html; charset=UTF-8'); - res.should.have.header('Content-Disposition', 'attachment; filename="document"'); - done(); - }); + .expect('Content-Type', 'text/html; charset=UTF-8') + .expect('Content-Disposition', 'attachment; filename="document"') + .expect(200, done) }) }) @@ -52,10 +47,11 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - res.should.have.header('Content-Type', 'text/html; charset=UTF-8'); - res.should.have.header('Content-Disposition', 'attachment; filename="user.html"'); - }); + .expect('Content-Type', 'text/html; charset=UTF-8') + .expect('Content-Disposition', 'attachment; filename="user.html"') + .expect(200, function(err){ + assert.ifError(err) + }) }) }) @@ -70,10 +66,11 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - res.should.have.header('Content-Type', 'text/html; charset=UTF-8'); - res.should.have.header('Content-Disposition', 'attachment; filename="document"'); - }); + .expect('Content-Type', 'text/html; charset=UTF-8') + .expect('Content-Disposition', 'attachment; filename="document"') + .expect(200, function(err){ + assert.ifError(err) + }) }) }) diff --git a/test/res.redirect.js b/test/res.redirect.js index f13a070c..c5aab7f1 100644 --- a/test/res.redirect.js +++ b/test/res.redirect.js @@ -13,11 +13,8 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - res.statusCode.should.equal(302); - res.headers.should.have.property('location', 'http://google.com'); - done(); - }) + .expect('location', 'http://google.com') + .expect(302, done) }) }) @@ -159,12 +156,11 @@ describe('res', function(){ request(app) .get('/') .set('Accept', 'application/octet-stream') - .end(function(err, res){ - res.should.have.status(302); - res.headers.should.have.property('location', 'http://google.com'); + .expect('location', 'http://google.com') + .expect('content-length', '0') + .expect(302, '', function(err, res){ + if (err) return done(err) res.headers.should.not.have.property('content-type'); - res.headers.should.have.property('content-length', '0'); - res.text.should.equal(''); done(); }) })