flatiron/nock — pull request #88 by rudyjahchan (2013-01-27 07:31:43+00:00)
Title: Output the http protocol in generated nock code from the recorder

This fix outputs the http protocol as part of the generated nock code.

### The Problem

The recorder in nock does not output the URL protocol in the generated code when using 'http'. As a result, when trying to reuse the code in tests, and calling .done() on a nock-ed call, the test will fail.

For example, if we record the following call:

```javascript
var req = http.request({
host: "www.google.com"
, path: '/'
, port: 80
}, function(res) {
// whatever happens here
});
```

The following code is generated by the nock recorder:

```javascript
nock('www.google.com:80')
.get('/')
.reply(200, "

Google

Search Images Maps Play YouTube News Gmail Drive

More

»

Web History | Settings | Sign in

Advanced searchLanguage tools

Advertising ProgramsBusiness Solutions+GoogleAbout Google

© 2012 - Privacy & Terms

", { date: 'Sun, 27 Jan 2013 06:37:16 GMT',
expires: '-1',
'cache-control': 'private, max-age=0',
'content-type': 'text/html; charset=ISO-8859-1',
'set-cookie':
[ 'PREF=ID=64acdb01bb6414bd:FF=0:TM=1359268636:LM=1359268636:S=Xbza0PQd_o2cNH2J; expires=Tue, 27-Jan-2015 06:37:16 GMT; path=/; domain=.google.com',
'NID=67=nrAXvKbIMvA3042X2mbM1yUOp_4-eu_KrIPl8vIsCX00UG2wFVulXJNXAE35p_PUT2H0z-A1GckcEFAY_qgIr0JrTsKBHsYDLWzNRosoLpBvvzdBrZfifXaGj_ddkZL9; expires=Mon, 29-Jul-2013 06:37:16 GMT; path=/; domain=.google.com; HttpOnly' ],
p3p: 'CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."',
server: 'gws',
'x-xss-protection': '1; mode=block',
'x-frame-options': 'SAMEORIGIN',
'transfer-encoding': 'chunked' });
```

However, using it will fail to match, and output the following:

```sh
AssertionError: Mocks not yet satisfied:
GET google.com://80:443/
```

You can recreate this problem in the tests. In the first test of test/test_intercept.js change the nock line:

```
var scope = nock('www.google.com')
```

Note the dropping of the protocol, matching the code generated by the recorder. The tests will fail after this change though!