Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use assert's messaging as much as possible

  • Loading branch information...
commit ef4224c359fb7903d9a6b4f349703fe853259abc 1 parent 02adf3f
@foobarfighter authored
Showing with 13 additions and 25 deletions.
  1. +7 −7 spec/matchers_spec.js
  2. +6 −18 src/matchers.js
View
14 spec/matchers_spec.js
@@ -53,11 +53,11 @@ foounit.add(function (kw){ with(kw){
describe('.beGt', function (){
describe('.match', function (){
- it('asserts expected is greater than actual', function (){
+ it('asserts actual is greater than expected', function (){
var matcher = new footest.keywords.beGt();
expect(function (){ matcher.match(4, 3); }).toNot(throwError);
- expect(function (){ matcher.match(4, 4); }).to(throwError, /Expected 4 to be greater than 4/);
- expect(function (){ matcher.match(4, 5); }).to(throwError, /Expected 4 to be greater than 5/);
+ expect(function (){ matcher.match(4, 4); }).to(throwError, /4 > 4/);
+ expect(function (){ matcher.match(4, 5); }).to(throwError, /5 > 4/);
});
});
describe('.notMatch', function (){
@@ -65,7 +65,7 @@ foounit.add(function (kw){ with(kw){
var matcher = new footest.keywords.beGt();
expect(function (){ matcher.notMatch(3, 4); }).toNot(throwError);
expect(function (){ matcher.notMatch(4, 4); }).toNot(throwError);
- expect(function (){ matcher.notMatch(5, 4); }).to(throwError, /Expected 5 to not be greater than 4/);
+ expect(function (){ matcher.notMatch(5, 4); }).to(throwError, /4 <= 5/);
});
});
});
@@ -75,8 +75,8 @@ foounit.add(function (kw){ with(kw){
it('asserts actual is less than expected', function (){
var matcher = new footest.keywords.beLt();
expect(function (){ matcher.match(3, 4); }).toNot(throwError);
- expect(function (){ matcher.match(4, 4); }).to(throwError, /Expected 4 to be less than 4/);
- expect(function (){ matcher.match(5, 4); }).to(throwError, /Expected 5 to be less than 4/);
+ expect(function (){ matcher.match(4, 4); }).to(throwError, /4 < 4/);
+ expect(function (){ matcher.match(5, 4); }).to(throwError, /4 < 5/);
});
});
@@ -85,7 +85,7 @@ foounit.add(function (kw){ with(kw){
var matcher = new footest.keywords.beLt();
expect(function (){ matcher.notMatch(5, 4); }).toNot(throwError);
expect(function (){ matcher.notMatch(4, 4); }).toNot(throwError);
- expect(function (){ matcher.notMatch(3, 4); }).to(throwError, /Expected 3 to not be less than 4/);
+ expect(function (){ matcher.notMatch(3, 4); }).to(throwError, /4 >= 3/);
});
});
});
View
24 src/matchers.js
@@ -62,20 +62,14 @@ foounit.addKeyword('include', function (){
* Assert that actual is greater than expected
*/
foounit.addKeyword('beGt', function (){
- this.format = function (actual, expected, not){
- var notStr = not ? ' not' : '';
- return 'Expected ' + actual + ' to' + notStr + ' be greater than ' + expected;
- }
-
this.match = function (actual, expected){
if (actual > expected){ return; }
- assert.fail(actual, expected, this.format(actual, expected), '>');
+ assert.fail(actual, expected, null, '>');
}
this.notMatch = function (actual, expected){
- if (actual > expected){
- assert.fail(actual, expected, this.format(actual, expected, true), '<=');
- }
+ if (actual <= expected){ return; }
+ assert.fail(actual, expected, null, '<=');
}
});
@@ -83,20 +77,14 @@ foounit.addKeyword('beGt', function (){
* Assert that actual is less than expected
*/
foounit.addKeyword('beLt', function (){
- this.format = function (actual, expected, not){
- var notStr = not ? ' not' : '';
- return 'Expected ' + actual + ' to' + notStr + ' be less than ' + expected;
- }
-
this.match = function (actual, expected){
if (actual < expected){ return; }
- assert.fail(actual, expected, this.format(actual, expected), '<');
+ assert.fail(actual, expected, null, '<');
}
this.notMatch = function (actual, expected){
- if (actual < expected){
- assert.fail(actual, expected, this.format(actual, expected, true), '<=');
- }
+ if (actual >= expected){ return };
+ assert.fail(actual, expected, null, '>=');
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.