Browse files

Added matches matcher.

  • Loading branch information...
1 parent 1ffefb4 commit 26120089e9e1a43468d6d2efd7800d9e62920550 @btakita btakita committed Apr 29, 2008
Showing with 84 additions and 1 deletion.
  1. +12 −1 lib/screw.builder.js
  2. +72 −0 spec/screwunit_spec.js
View
13 lib/screw.builder.js
@@ -9,7 +9,6 @@ var Screw = {
$(function() {
Screw.root_element = $('<div class="describe">');
Screw.root_element
- .addClass('describe')
.append($('<h3 class="status">'))
.append('<ol class="befores">')
.append('<ul class="its">')
@@ -108,6 +107,18 @@ var Screw = {
return actual.length == expected.length;
}
},
+ match: {
+ match: function(expected, actual) {
+ if(typeof expected == "string") {
+ return actual.indexOf(expected) > -1;
+ } else {
+ return expected.exec(actual);
+ }
+ },
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $([actual]).print() + (not ? ' to not match ' : ' to match ') + $([expected]).print();
+ }
+ },
be_empty: {
match: function(expected, actual) {
if(actual.length == undefined) {
View
72 spec/screwunit_spec.js
@@ -93,6 +93,78 @@ Screw.Unit(function() {
});
});
+ describe("#match", function() {
+ describe("when passed a Regex", function() {
+ describe(".matches", function() {
+ it("matches when expected =~ actual", function() {
+ expect("The wheels of the bus").to(match, /bus/);
+ expect("The wheels of the bus").to_not(match, /boat/);
+ });
+ });
+
+ describe(".failure_message", function() {
+ describe("on a positive failure", function() {
+ it("prints 'expected [actual] to match [expected]", function() {
+ var message = null;
+ try {
+ expect("Hello").to(match, /Goodbye/);
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [Hello] to match [/Goodbye/]");
+ });
+ });
+
+ describe("on a negative failure", function() {
+ it("prints 'expected [actual] to not match [expected]", function() {
+ var message = null;
+ try {
+ expect("Hello").to_not(match, /ello/);
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [Hello] to not match [/ello/]");
+ });
+ });
+ });
+ });
+
+ describe("when passed a String", function() {
+ describe(".matches", function() {
+ it("matches when expected is included in actual", function() {
+ expect("The wheels of the bus").to(match, "wheels");
+ expect("The wheels of the bus").to_not(match, "oars");
+ });
+ });
+
+ describe(".failure_message", function() {
+ describe("on a positive failure", function() {
+ it("prints 'expected [actual] to match [expected]", function() {
+ var message = null;
+ try {
+ expect("Hello").to(match, "goodbye");
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [Hello] to match [goodbye]");
+ });
+ });
+
+ describe("on a negative failure", function() {
+ it("prints 'expected [actual] to not match [expected]", function() {
+ var message = null;
+ try {
+ expect("Hello").to_not(match, "ello");
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [Hello] to not match [ello]");
+ });
+ });
+ });
+ });
+ });
+
describe("#be_empty", function() {
describe(".matches", function() {
it("matches when Array#length == 0", function() {

0 comments on commit 2612008

Please sign in to comment.