Skip to content

Commit

Permalink
to be within: Don't put numeric ranges in quotes.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jan 20, 2015
1 parent ba0511e commit 8667f20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ module.exports = function (expect) {
});

expect.addAssertion(['number', 'string'], '[not] to be within', function (expect, subject, start, finish) {
this.args = [expect.output.clone().number(start).text('..').number(finish)];
this.args = [expect.output.clone().append(expect.inspect(start)).text('..').append(expect.inspect(finish))];
expect(subject >= start && subject <= finish, '[not] to be truthy');
});

Expand Down
8 changes: 7 additions & 1 deletion test/unexpected.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,19 @@ describe('unexpected', function () {
it('throws when the assertion fails', function () {
expect(function () {
expect(4, 'not to be within', 0, 4);
}, 'to throw exception', "expected 4 not to be within 0..4");
}, 'to throw exception', 'expected 4 not to be within 0..4');
expect(function () {
expect(null, 'not to be within', 0, 4);
}, 'to throw exception',
'The assertion "not to be within" is not defined for the type "null",\n' +
'but it is defined for these types: "number", "string"');
});

it('throws with the correct error message when the end points are strings', function () {
expect(function () {
expect('a', 'to be within', 'c', 'd');
}, 'to throw exception', "expected 'a' to be within 'c'..'d'");
});
});

describe('less than assertion', function () {
Expand Down

0 comments on commit 8667f20

Please sign in to comment.