Skip to content

Commit

Permalink
Merge branch 'unexpected-8.5.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Jun 24, 2015
2 parents dc12823 + 89c3cb5 commit 6b62961
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 47 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"jshint": "2.7.0",
"messy": "6.3.0",
"mocha": "2.2.4",
"unexpected": "8.4.1",
"unexpected": "8.5.0",
"unexpected-messy": "4.1.0",
"unexpected-mitm": "7.0.1"
"unexpected-mitm": "7.1.0"
}
}
68 changes: 23 additions & 45 deletions test/BeanBag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,7 @@ var BeanBag = require('../lib/BeanBag'),

describe('BeanBag', function () {
var expect = unexpected.clone()
.installPlugin(require('unexpected-mitm'))
.addAssertion('to call the callback with no error', function (expect, subject, assertFn) {
this.errorMode = 'nested';
return expect.promise(function (run) {
subject(run(function (err, response, body) {
if (err) {
throw err;
}

if (assertFn) {
assertFn(response, body);
}
}));
});
})
.addAssertion('to call the callback with error', function (expect, subject, expectedError) {
this.errorMode = 'nested';
return expect.promise(function (run) {
subject(run(function (err) {
expect(err, 'to equal', expectedError);
}));
});
});
.installPlugin(require('unexpected-mitm'));

it('should not overwrite a built-in method with a config object property', function () {
expect(new BeanBag({
Expand All @@ -46,7 +24,7 @@ describe('BeanBag', function () {
}, 'with http mocked out', {
request: 'GET http://localhost:5984/bar/quux',
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should allow specifying custom headers', function () {
Expand All @@ -58,7 +36,7 @@ describe('BeanBag', function () {
headers: { Foo: 'bar' }
},
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should resolve the path from the base url', function () {
Expand All @@ -69,7 +47,7 @@ describe('BeanBag', function () {
url: 'GET http://localhost:5984/hey/quux'
},
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should allow specifying the request body as a Buffer', function () {
Expand All @@ -84,7 +62,7 @@ describe('BeanBag', function () {
body: new Buffer([1, 2, 3])
},
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should allow specifying the request body as a string', function () {
Expand All @@ -99,7 +77,7 @@ describe('BeanBag', function () {
body: new Buffer('foobar', 'utf-8')
},
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should allow specifying the request body as an object, implying JSON', function () {
Expand All @@ -114,7 +92,7 @@ describe('BeanBag', function () {
body: { what: 'gives' }
},
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should return an object with an abort method', function () {
Expand All @@ -124,7 +102,7 @@ describe('BeanBag', function () {
});
}, 'with http mocked out', {
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

describe('retrying on failure', function () {
Expand All @@ -135,7 +113,7 @@ describe('BeanBag', function () {
{ response: new socketErrors.ETIMEDOUT() },
{ response: new socketErrors.ETIMEDOUT() },
{ response: 200 }
], 'to call the callback with no error');
], 'to call the callback without error');
});

it('should give up if the request fails 1 + `numRetries` times', function () {
Expand Down Expand Up @@ -197,7 +175,7 @@ describe('BeanBag', function () {
},
body: responseStream
}
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should allow any valid formulation of application/json', function () {
Expand All @@ -223,8 +201,8 @@ describe('BeanBag', function () {
},
body: responseStream
}
}, 'to call the callback with no error', function (response, body) {
expect(body, 'to equal', responseObject);
}, 'to call the callback without error').spread(function (response, body) {
return expect(body, 'to equal', responseObject);
});
});

Expand Down Expand Up @@ -259,7 +237,7 @@ describe('BeanBag', function () {
}, 'with http mocked out', {
request: 'GET http://localhost:5984/bar/quux?blabla',
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should allow specifying the query string as an object', function () {
Expand All @@ -277,7 +255,7 @@ describe('BeanBag', function () {
'&multiple=%22foo%22' +
'&multiple=%22n%C3%B8nasc%C3%AF%C3%AE%22',
response: 200
}, 'to call the callback with no error');
}, 'to call the callback without error');
});
});

Expand All @@ -295,7 +273,7 @@ describe('BeanBag', function () {
}, cb);
}, 'with http mocked out', {
request: 'http://example.com.contacts/foo/hey'
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should substitute a complex expression in a placeholder', function () {
Expand Down Expand Up @@ -333,7 +311,7 @@ describe('BeanBag', function () {
}, 'with http mocked out', [
{ request: 'http://couchdb3.example.com/contacts0/hey' },
{ request: 'http://couchdb4.example.com/contacts1/there' }
], 'to call the callback with no error');
], 'to call the callback without error');
});

it('should support passing a falsy value in request options', function () {
Expand All @@ -348,7 +326,7 @@ describe('BeanBag', function () {
}, cb);
}, 'with http mocked out', {
request: 'http://couchdb3.example.com/contacts0/hey'
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should substitute a placeholder with a value found in the options object passed to the constructor', function () {
Expand All @@ -361,7 +339,7 @@ describe('BeanBag', function () {
beanBag.request({path: 'hey'}, cb);
}, 'with http mocked out', {
request: 'http://example.com.contacts/foo/hey'
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should substitute a placeholder with the result of calling a function of that name passed to the request method', function () {
Expand All @@ -376,7 +354,7 @@ describe('BeanBag', function () {
beanBag.request({path: 'hey', owner: 'andreas@example.com'}, cb);
}, 'with http mocked out', {
request: 'http://example.com.contacts/foo/hey'
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

describe('with a design document', function () {
Expand All @@ -402,7 +380,7 @@ describe('BeanBag', function () {
}, cb);
}, 'with http mocked out', {
request: 'http://example.com.contacts/foo/_design/c5f85a319e5af7e66e88b89782890461/_view/foo'
}, 'to call the callback with no error');
}, 'to call the callback without error');
});

it('should substitute a placeholder with a value found in the options object passed to queryDesignDocument when the design document does not exist yet', function () {
Expand Down Expand Up @@ -433,7 +411,7 @@ describe('BeanBag', function () {
{
request: 'http://example.com.contacts/foo/_design/c5f85a319e5af7e66e88b89782890461/_view/foo'
}
], 'to call the callback with no error');
], 'to call the callback without error');
});
});
});
Expand Down Expand Up @@ -465,7 +443,7 @@ describe('BeanBag', function () {
key: one,
ca: two
}
}, 'to call the callback with no error');
}, 'to call the callback without error');
});
});

Expand Down Expand Up @@ -499,7 +477,7 @@ describe('BeanBag', function () {
key: one,
ca: [two, three]
}
}, 'to call the callback with no error');
}, 'to call the callback without error');
});
});
});
Expand Down

0 comments on commit 6b62961

Please sign in to comment.