Docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 2bd7a57 · Browse files · 1 file·+66 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+66 added−0 removed
- tests:+66 added−0 removed
Provenance
- Commit
7f111bf- Tree
26d6ec5- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
2bd7a57
1 file changed+66 added−0 removed
modified:lib/express/spec/mock-routes.js+66 added
2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455562 unmodified lines596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012126 unmodified lines2 unmodified lines
// --- MockRequest
var MockRequest = Class({ /** * Default uri properties. */ uri: { queryString: '', fragment: '', params: {}, }, /** * Default HTTP version. */ httpVersion: '1.1', /** * Connection defaults. */ connection: { remoteAddress: '127.0.0.1' }, /** * Request header defaults. */ headers: { 'host': 'localhost:3000', 'user-agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19', 'accept': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'accept-language': 'en-us', 'connection': 'keep-alive' }, /** * Initialize with _method_, _path_ and _options_. * * @param {string} method * @param {string} path * @param {hash} options * @api private */ init: function(method, path, options) { this.method = method this.uri.path = this.uri.full = path process.mixin(true, this, options)2 unmodified lines
// --- MockResponse
var MockResponse = Class({ /** * Store _code_ and _headers_. */ sendHeader: function(code, headers) { this.status = code this.headers = headers }, /** * Store _body_. */ sendBody: function(body) { this.body = body }, /** * Flag response as finished. */ finish: function() { this.finished = true }})
/** * Mock a request with the given _method_, _path_, * and _options_. Returns the response for assertions. * * All _options_ are passed to MockRequest which * performs a deep copy so you may alter headers etc. * * @param {string} method * @param {string} path * @param {hash} options * @return {MockResponse} * @api private */
function request(method, path, options, fn) { var response = new MockResponse var request = new MockRequest(method, path, options) Express.server.route(request, response) return response}
/** * Request Express data which may have been * manipulated by the mock request. * * @api public */
reset = function() { Express.routes = [] Express.settings = {}}26 unmodified lines