Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add less than or equal to matcher

  • Loading branch information...
commit 236394893a8f143359707eb98a5c4553d3bd0120 1 parent 4be1de5
@joshuaclayton authored
Showing with 23 additions and 1 deletion.
  1. +1 −0  README.markdown
  2. +8 −1 specit.js
  3. +14 −0 specit.tests.js
View
1  README.markdown
@@ -33,6 +33,7 @@ I don't have the patience to write my own JS testing framework so I figured I'd
* match (checks against a regular expression)
* respondTo (checks that a function exists)
* beLessThan (checks a number is less than another)
+* beLessThanOrEqualTo (checks a number is less than or equal to another)
## What's it do?
View
9 specit.js
@@ -84,7 +84,8 @@
beAn: "Expected {actual} {not} to be an",
match: "Expected {actual} {not} to match {expected}",
respondTo: "Expected {expected} {not} to be a method of {actual}",
- beLessThan: "Expected {actual} {not} to be less than {expected}"
+ beLessThan: "Expected {actual} {not} to be less than {expected}",
+ beLessThanOrEqualTo: "Expected {actual} {not} to be less than or equal to {expected}"
}, message, options = arguments[3];
message = matcherMessages[matcher];
@@ -156,6 +157,12 @@
expected: {value: arguments[0], parse: true},
actual: {value: this, parse: true}});
},
+ beLessThanOrEqualTo: function() {
+ Matcher("beLessThanOrEqualTo", "ok",
+ {assert: this <= arguments[0],
+ expected: {value: arguments[0], parse: true},
+ actual: {value: this, parse: true}});
+ },
}
});
View
14 specit.tests.js
@@ -113,4 +113,18 @@ describe("SpecIt", function() {
(0.1).shouldNot(beLessThan, 0.05);
( 5).shouldNot(beLessThan, 5);
});
+
+ it("should match on less than or equal to", function() {
+ ( 2).should(beLessThanOrEqualTo, 5);
+ ( -5).should(beLessThanOrEqualTo, 0);
+ ( 0).should(beLessThanOrEqualTo, 0.1);
+ ( 5).should(beLessThanOrEqualTo, 5);
+ "awesome".should(beLessThanOrEqualTo, "great");
+ "great".should(beLessThanOrEqualTo, "great");
+ (0.1).should(beLessThanOrEqualTo, 0.1);
+
+ ( 5).shouldNot(beLessThanOrEqualTo, 3);
+ (0.1).shouldNot(beLessThanOrEqualTo, 0);
+ (0.1).shouldNot(beLessThanOrEqualTo, 0.05);
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.