Skip to content

Commit

Permalink
Add helpers: shouldBeForbidden and shouldBeRejected
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicMahieu committed Jan 14, 2016
1 parent 5b99f2d commit 36a9199
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,33 @@ _it.shouldNotBeFound = function() {
});
}

_it.shouldBeForbidden = function() {
it('should be forbidden', function() {
assert(this.res);
if (this.res.statusCode !== 403) {
console.log(this.res.body);
}
assert.equal(this.res.statusCode, 403);
});
}

_it.shouldBeRejected = function(statusCode) {
it('should be rejected' + (statusCode ? ' with status code ' + statusCode : ''), function() {
assert(this.res);
if (statusCode) {
if (this.res.statusCode !== statusCode) {
console.log(this.res.body);
}
expect(this.res.statusCode).to.equal(statusCode);
} else {
if (this.res.statusCode < 400 || this.res.statusCode > 499) {
console.log(this.res.body);
}
expect(this.res.statusCode).to.be.within(400, 499);
}
});
}

_it.shouldBeAllowedWhenCalledAnonymously =
function(verb, url, data) {
_describe.whenCalledAnonymously(verb, url, data, function() {
Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe('helpers', function () {
['shouldBeAllowed',
'shouldBeDenied',
'shouldNotBeFound',
'shouldBeForbidden',
'shouldBeRejected',
'shouldBeAllowedWhenCalledAnonymously',
'shouldBeDeniedWhenCalledAnonymously',
'shouldBeAllowedWhenCalledUnauthenticated',
Expand Down

0 comments on commit 36a9199

Please sign in to comment.