Skip to content

Commit

Permalink
Add less than matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Jun 6, 2010
1 parent 199ebcc commit 4be1de5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ I don't have the patience to write my own JS testing framework so I figured I'd
* beA, beAn (checks type)
* match (checks against a regular expression)
* respondTo (checks that a function exists)
* beLessThan (checks a number is less than another)

## What's it do?

Expand Down
9 changes: 8 additions & 1 deletion specit.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
beA: "Expected {actual} {not} to be a",
beAn: "Expected {actual} {not} to be an",
match: "Expected {actual} {not} to match {expected}",
respondTo: "Expected {expected} {not} to be a method of {actual}"
respondTo: "Expected {expected} {not} to be a method of {actual}",
beLessThan: "Expected {actual} {not} to be less than {expected}"
}, message, options = arguments[3];

message = matcherMessages[matcher];
Expand Down Expand Up @@ -149,6 +150,12 @@
expected: {value: arguments[0], parse: true},
actual: {value: this, parse: true}});
},
beLessThan: function() {
Matcher("beLessThan", "ok",
{assert: this < arguments[0],
expected: {value: arguments[0], parse: true},
actual: {value: this, parse: true}});
},
}
});

Expand Down
11 changes: 11 additions & 0 deletions specit.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ describe("SpecIt", function() {
john.shouldNot(respondTo, "age");
john.shouldNot(respondTo, "sayGoodbye");
});

it("should match on less than", function() {
( 2).should(beLessThan, 5);
( -5).should(beLessThan, 0);
( 0).should(beLessThan, 0.1);
"awesome".should(beLessThan, "great");
( 5).shouldNot(beLessThan, 3);
(0.1).shouldNot(beLessThan, 0);
(0.1).shouldNot(beLessThan, 0.05);
( 5).shouldNot(beLessThan, 5);
});
});

0 comments on commit 4be1de5

Please sign in to comment.