Skip to content

Commit dfd7bb3

Browse files
committed
Got rid of all the custom assertion in bootstrap
1 parent 0a7dc18 commit dfd7bb3

File tree

2 files changed

+10
-44
lines changed

2 files changed

+10
-44
lines changed

bootstrap-unexpected-markdown.js

-20
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,4 @@ unexpected = require('unexpected').clone();
33
unexpected.output.preferredWidth = 80;
44
unexpected.use(require('./lib/unexpected-check'));
55

6-
unexpected.addAssertion('<number> to be less than or equal to all <array>', function (expect, subject, array) {
7-
expect(array, 'to have items satisfying', expect.it('to be greater than or equal to', subject));
8-
});
9-
10-
unexpected.addAssertion('<number> to be greater than or equal to all <array>', function (expect, subject, array) {
11-
expect(array, 'to have items satisfying', expect.it('to be less than or equal to', subject));
12-
});
13-
14-
unexpected.addAssertion('<array> first item <assertion>', function (expect, subject) {
15-
return expect.shift(subject[0]);
16-
});
17-
18-
unexpected.addAssertion('<array> last item <assertion>', function (expect, subject) {
19-
return expect.shift(subject[subject.length - 1]);
20-
});
21-
22-
unexpected.addAssertion('<any> to be contained by <array>', function (expect, item, array) {
23-
expect(array.indexOf(item) !== -1, 'to be true');
24-
});
25-
266
expect = unexpected.clone();

test/unexpected-check.spec.js

+10-24
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@ expect.output.preferredWidth = 80;
55

66
expect.use(require('../lib/unexpected-check'));
77

8-
expect.addAssertion('<number> to be less than or equal to all <array>', function (expect, subject, array) {
9-
expect(array, 'to have items satisfying', expect.it('to be greater than or equal to', subject));
10-
});
11-
12-
expect.addAssertion('<number> to be greater than or equal to all <array>', function (expect, subject, array) {
13-
expect(array, 'to have items satisfying', expect.it('to be less than or equal to', subject));
14-
});
15-
16-
expect.addAssertion('<array> first item <assertion>', function (expect, subject) {
17-
return expect.shift(subject[0]);
18-
});
19-
20-
expect.addAssertion('<array> last item <assertion>', function (expect, subject) {
21-
return expect.shift(subject[subject.length - 1]);
8+
expect.addAssertion('<array> to be sorted', function (expect, subject) {
9+
var isSorted = subject.every(function (x, i) {
10+
return subject.slice(i).every(function (y) {
11+
return x <= y;
12+
});
13+
});
14+
expect(isSorted, 'to be true');
2215
});
2316

2417
function sort(arr, cmp) {
@@ -39,8 +32,7 @@ describe('unexpected-check', function () {
3932
var sorted = sort(arr);
4033

4134
expect(sorted, 'to have length', arr.length)
42-
.and('first item to be less than or equal to all', arr)
43-
.and('last item to be greater than or equal to all', arr);
35+
.and('to be sorted');
4436
}, 'to be valid for all', {
4537
generators: [arrays],
4638
maxIterations: 50,
@@ -53,12 +45,7 @@ describe('unexpected-check', function () {
5345
'\n' +
5446
' Generated input: [ -1, -2 ]\n' +
5547
'\n' +
56-
' expected [ -1, -2 ] first item to be less than or equal to all [ -1, -2 ]\n' +
57-
'\n' +
58-
' [\n' +
59-
' -1,\n' +
60-
' -2 // should be greater than or equal to -1\n' +
61-
' ]');
48+
' expected [ -1, -2 ] to be sorted');
6249
});
6350

6451
it('find errors in the specification', function () {
@@ -84,8 +71,7 @@ describe('unexpected-check', function () {
8471
var sorted = sort(arr, function (a, b) { return a - b; });
8572

8673
expect(sorted, 'to have length', arr.length)
87-
.and('first item to be less than or equal to all', arr)
88-
.and('last item to be greater than or equal to all', arr);
74+
.and('to be sorted');
8975
}, 'to be valid for all', arrays);
9076
});
9177

0 commit comments

Comments
 (0)