Skip to content

Commit

Permalink
Merge branch 'head-should-be-first-class' of https://github.com/brian…
Browse files Browse the repository at this point in the history
…loveswords/nock

Conflicts:
	tests/test_intercept.js
  • Loading branch information
pgte committed Apr 13, 2012
2 parents 3011ff2 + f190d7f commit 1f0315c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ You can also specify default reply headers for all responses like this:

## HTTP Verbs

Nock supports any HTTP verb, and it has convenience methods for the GET, POST, PUT and DELETE HTTP verbs.
Nock supports any HTTP verb, and it has convenience methods for the GET, POST, PUT, HEAD and DELETE HTTP verbs.

You can intercept any HTTP verb using `.intercept(path, verb [, requestBody [, options]])`:

scope('http://my.domain.com')
.intercept('/path', 'HEAD')
.intercept('/path', 'PATCH')
.reply(304);

## Support for HTTP and HTTPS
Expand Down
5 changes: 5 additions & 0 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ function startScope(basePath, options) {
function put(uri, requestBody, options) {
return intercept(uri, 'PUT', requestBody, options);
}

function head(uri, requestBody, options) {
return intercept(uri, 'HEAD', requestBody, options);
}

function _delete(uri, requestBody, options) {
return intercept(uri, 'DELETE', requestBody, options);
Expand Down Expand Up @@ -293,6 +297,7 @@ function startScope(basePath, options) {
, post: post
, delete: _delete
, put: put
, head: head
, intercept: intercept
, done: done
, isDone: isDone
Expand Down
26 changes: 26 additions & 0 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ tap.test("post", function(t) {
req.end();
});



tap.test("post with empty response body", function(t) {
var dataCalled = false;

Expand Down Expand Up @@ -405,6 +407,30 @@ tap.test("header manipulation", function(t) {
req.end();
});

tap.test("head", function(t) {
var dataCalled = false;

var scope = nock('http://www.google.com')
.head('/form')
.reply(201, "OK!");

var req = http.request({
host: "www.google.com"
, method: 'HEAD'
, path: '/form'
, port: 80
}, function(res) {

t.equal(res.statusCode, 201);
res.on('end', function() {
scope.done();
t.end();
});
});

req.end();
});

tap.test("body data is differentiating", function(t) {
var doneCount = 0
, scope = nock('http://www.boddydiff.com')
Expand Down

0 comments on commit 1f0315c

Please sign in to comment.