Updated resource example with acceptnce test.

Esse commit está contido em:
Robert Sköld
2011-12-18 23:47:30 +01:00
commit de TJ Holowaychuk
commit 8120a06cd6
2 arquivos alterados com 70 adições e 4 exclusões
+6 -4
Ver Arquivo
@@ -3,9 +3,9 @@
* Module dependencies.
*/
var express = require('../../lib/express');
var express = require('../../');
var app = express.createServer();
var app = module.exports = express();
// Ad-hoc example resource method
@@ -85,5 +85,7 @@ app.get('/', function(req, res){
].join('\n'));
});
app.listen(3000);
console.log('Express app started on port 3000');
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}
+64
Ver Arquivo
@@ -0,0 +1,64 @@
var app = require('../../examples/resource/app')
, request = require('../support/http');
describe('resource', function(){
describe('GET /', function(){
it('should respond with instructions', function(done){
request(app)
.get('/')
.expect(/^<h1>Examples:<\/h1>/,done)
})
})
describe('GET /users', function(){
it('should respond with all users', function(done){
request(app)
.get('/users')
.expect(/^\[{"name":"tj"},{"name":"ciaran"},{"name":"aaron"},{"name":"guillermo"},{"name":"simon"},{"name":"tobi"}\]/,done)
})
})
describe('GET /users/1', function(){
it('should respond with user 1', function(done){
request(app)
.get('/users/1')
.expect(/^{"name":"ciaran"}/,done)
})
})
describe('GET /users/1..3', function(){
it('should respond with users 1 through 3', function(done){
request(app)
.get('/users/1..3')
.expect(/^<ul><li>ciaran<\/li>\n<li>aaron<\/li>\n<li>guillermo<\/li><\/ul>/,done)
})
})
describe('DELETE /users/1', function(){
it('should respond with users 1 through 3', function(done){
request(app)
.delete('/users/1')
.expect(/^destroyed/,done)
})
})
describe('GET /users/1..3.json', function(){
it('should respond with users 2 and 3 as json', function(done){
request(app)
.get('/users/1..3.json')
.expect(/^\[null,{"name":"aaron"},{"name":"guillermo"}\]/,done)
})
})
})
// curl http://localhost:3000/users -- responds with all users
// curl http://localhost:3000/users/1 -- responds with user 1
// curl http://localhost:3000/users/4 -- responds with error
// curl http://localhost:3000/users/1..3 -- responds with several users
// curl -X DELETE http://localhost:3000/users/1 -- deletes the user
// , '<li>GET /users</li>'
// , '<li>GET /users/1</li>'
// , '<li>GET /users/3</li>'
// , '<li>GET /users/1..3</li>'
// , '<li>GET /users/1..3.json</li>'
// , '<li>DELETE /users/4</li>'