Comparing version 0.2.1 to 0.2.2
var path = require('path') | ||
, http = require('http') | ||
, url = require('url') | ||
, EventEmitter = require('events').EventEmitter; | ||
@@ -14,2 +15,20 @@ | ||
function remove(interceptor) { | ||
var key = interceptor._key.split(' '); | ||
var u = url.parse(key[1]); | ||
var hostKey = u.protocol + '//' + u.host; | ||
var interceptors = allInterceptors[hostKey]; | ||
var interceptor; | ||
for(var i = 0; i < interceptors.length; i++) { | ||
thisInterceptor = interceptors[i]; | ||
if (thisInterceptor._key === interceptor._key) { | ||
interceptors.splice(i, 1); | ||
break; | ||
} | ||
} | ||
if (! interceptors) { delete allInterceptors[hostKey]; } | ||
} | ||
function stringifyRequest(options) { | ||
@@ -80,3 +99,3 @@ var method = options.method || 'GET'; | ||
if (interceptors.length < 1) { throw new Error("Nock: No match for HTTP request " + stringifyRequest(options)); } | ||
interceptor = interceptors.splice(0, 1)[0]; | ||
interceptor = interceptors.shift(); | ||
@@ -92,2 +111,3 @@ response.statusCode = interceptor.statusCode || 200; | ||
}; | ||
remove(interceptor); | ||
interceptor.discard(); | ||
@@ -94,0 +114,0 @@ |
{ "name" : "nock" | ||
, "description" : "HTTP Server mocking for Node.js" | ||
, "tags" : ["Mock", "HTTP", "testing", "isolation"] | ||
, "version" : "0.2.1" | ||
, "version" : "0.2.2" | ||
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "contributors" : |
@@ -25,3 +25,3 @@ # Nock | ||
It will intercept an HTTP GET request to '/users/1' and reply with a status 404. | ||
It will intercept an HTTP GET request to '/users/1' and reply with a status 200, and the body will contain a user representation in JSON. | ||
@@ -28,0 +28,0 @@ Then the test can call the module, and the module will do the HTTP requests. |
26238
766