Added mockRequest() and mockResponse()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 27dc193 · Browse files · 4 files·+86 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
4 files+86 added−6 removed
- tests:+86 added−6 removed
Provenance
- Commit
637ac18- Tree
5f9524d- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
27dc193
4 files changed+86 added−6 removed
added:lib/express.spec.helpers.js+58 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
// Express - Spec Helpers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
(function(){ /** * Mock _request_ object. Optionally pass hash of properties. * * @param {hash} request * @return {hash} * @api public */ function mockRequest(request) { var mock = { method : 'GET', uri : { params : {} } } JSpec.extend(mock, request) return mock } /** * Mock _response_ object. Optionally pass hash of properties. * * @param {hash} response * @return {hash} * @api public */ function mockResponse(response) { var mock = { body : null, status : 200, sendHeader : function(){}, sendBody : function(){}, finish : function(){ this.finished = true } } JSpec.extend(mock, response) return mock } JSpec.include({ init : function() { var oldCallback = Express.server.callback Express.server.callback = function(request, response) { oldCallback(mockRequest(request), mockResponse(response)) } }, utilities : { mockRequest : mockRequest, mockResponse : mockResponse } })})()No newline at end of filemodified:spec/spec.node.js+2 added
24 unmodified lines25262728293031323334353637383940414 unmodified lines24 unmodified linesload('/Users/tjholowaychuk/scripts/gems/JSpec/lib/jspec.js')load('lib/express.core.js')load('lib/express.mime.js')load('lib/express.view.js')load('lib/express.spec.helpers.js')
setTimeout(function(){ JSpec .exec('spec/spec.core.js') .exec('spec/spec.routing.js') .exec('spec/spec.mime.js') .exec('spec/spec.view.js') .exec('spec/spec.spec.helpers.js') setTimeout(function(){ JSpec.run({ formatter : JSpec.formatters.Terminal, failuresOnly : true }) setTimeout(function() { JSpec.report()4 unmodified linesmodified:spec/spec.routing.js-6 removed
89 unmodified lines90919293949596979899949589 unmodified lines Express.regexpKeys.should.eql ['page'] end end describe 'get()' get('/user/:name', function(){ 'User ' + param('name') }) end endendNo newline at end of fileNo newline at end of fileadded:spec/spec.spec.helpers.js+26 added
1234567891011121314151617181920212223242526
describe 'Express' describe 'Spec' describe 'Helpers' describe 'mockRequest()' it 'should return a mock request' mockRequest().method.should.eql 'GET' end it 'should merge hash passed' mockRequest({ method : 'POST' }).method.should.eql 'POST' end end describe 'mockResponse()' it 'should return a mock response' mockResponse().status.should.eql 200 end it 'should merge hash passed' mockResponse({ status : 404 }).status.should.eql 404 end end end endendNo newline at end of file