Fixing route mocking
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 85721ee · Browse files · 2 files·+31 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+31 added−6 removed
- tests:+31 added−6 removed
Provenance
- Commit
7899e45- Tree
d99d6c5- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
85721ee
2 files changed+31 added−6 removed
modified:lib/express.spec.helpers.js+30 added-5 removed
12 unmodified lines131415161718192021222311 unmodified lines353637383940414243444546474849505152535455565758596061626364656667686970714872737475767778798081825657585983848586873 unmodified lines91929394959612 unmodified lines function mockRequest(request) { var mock = { method : 'GET', headers : [], uri : { path : '/', params : {} } } JSpec.extend(mock, request)11 unmodified lines function mockResponse(response) { var mock = { body : null, status : 200, headers : [], sendHeader : function(){}, sendBody : function(){}, finish : function(){ this.finished = true } } JSpec.extend(mock, response) return mock } /** * Mock server callback. * * @param {object} request * @param {object} response * @api private */ var orig = Express.server.callback function mockCallback(request, response) { orig(mockRequest(request), mockResponse(response)) } /** * Mock route function for HTTP _method_. * * @param {string} method * @return {function} * @api private */ function mockRouteFunctionFor(method) { var orig = Express.routeFunctionFor(method) return function(path, options, callback) { p(Express.argsArray(arguments)) if (options.constructor == Function) callback = options, options = {} if (callback) orig.apply(Express, arguments) var request = mockRequest({ method : method.toUpperCase(), path : path }) var response = mockResponse() Express.server.callback(request, response) return Express.response } } JSpec.include({ init : function() { var orig = Express.server.callback Express.server.callback = function(request, response) { orig(mockRequest(request), mockResponse(response)) } Express.server.callback = mockCallback }, utilities : { mockRequest : mockRequest,3 unmodified lines put : mockRouteFunctionFor('put'), del : mockRouteFunctionFor('delete') } }) })()No newline at end of fileNo newline at end of filemodified:spec/spec.spec.helpers.js+1 added-1 removed
22 unmodified lines2324252627272829303122 unmodified lines end describe '' get('users', function(){ 'User list' }) get('/users').body.should.eql 'User list' //.body.should.eql 'User list' end end endendNo newline at end of fileNo newline at end of file