Skip to content
Browse files

Adding failure_message for be_empty matchers. Added specs for equal f…

…ailure_messages.
  • Loading branch information...
1 parent f803f22 commit 38aaef421fab24f6c8c8cddb8038b15a9ee2cb58 @btakita btakita committed Apr 27, 2008
Showing with 104 additions and 12 deletions.
  1. +3 −1 lib/screw.builder.js
  2. +101 −11 spec/screwunit_spec.js
View
4 lib/screw.builder.js
@@ -92,7 +92,6 @@ var Screw = {
return actual == expected;
},
failure_message: function(expected, actual, not) {
- // TESTME
return 'expected ' + $([actual]).print() + (not ? ' to not equal ' : ' to equal ') + $([expected]).print();
}
},
@@ -109,6 +108,9 @@ var Screw = {
throw(actual.toString() + " does not respond to length");
}
return actual.length == 0;
+ },
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $([actual]).print() + (not ? ' to not be empty' : ' to be empty');
}
}
}
View
112 spec/screwunit_spec.js
@@ -1,21 +1,111 @@
Screw.Unit(function() {
describe('Screw.Unit', function() {
describe("Matchers", function() {
- it("invokes the provided matcher on a call to expect", function() {
- expect(true).to(equal, true);
- expect(true).to_not(equal, false);
- });
+ describe("#equal", function() {
+ describe("when actual is not an Array", function() {
+ describe(".matches", function() {
+ it("matches when expected == actual", function() {
+ expect(true).to(equal, true);
+ expect(true).to_not(equal, false);
+ });
+ });
+
+ describe(".failure_message", function() {
+ describe("on a positive failure", function() {
+ it("prints 'expected [actual] to equal [expected]", function() {
+ var message = null;
+ try {
+ expect(true).to(equal, false);
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [true] to equal [false]");
+ });
+ });
+
+ describe("on a negative failure", function() {
+ it("prints 'expected [actual] to not equal [expected]", function() {
+ var message = null;
+ try {
+ expect(true).to_not(equal, true);
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [true] to not equal [true]");
+ });
+ });
+ });
+ });
+
+ describe("when actual is an Array", function() {
+ describe(".matches", function() {
+ it("matches when Arrays the expected and actual have the same contents", function() {
+ expect([1, 2, 3]).to(equal, [1, 2, 3]);
+ expect([1, 2, 3]).to_not(equal, [3, 2, 1]);
+ });
+ });
+
+ describe(".failure_message", function() {
+ describe("on a positive failure", function() {
+ it("prints 'expected [actual] to equal [expected]", function() {
+ var message = null;
+ try {
+ expect([1, 2, 3]).to(equal, [1, 2, 4]);
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [1,2,3] to equal [1,2,4]");
+ });
+ });
- it("equal matches Arrays with the same elements", function() {
- expect([1, 2, 4]).to(equal, [1, 2, 3]);
- expect([1, 2, 3]).to_not(equal, [3, 2, 1]);
+ describe("on a negative failure", function() {
+ it("prints 'expected [actual] to not equal [expected]", function() {
+ var message = null;
+ try {
+ expect([1, 2, 3]).to_not(equal, [1, 2, 3]);
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [1,2,3] to not equal [1,2,3]");
+ });
+ });
+ });
+ });
});
describe("#be_empty", function() {
- it("matches on Array#lenth == 0", function() {
- expect([]).to(be_empty);
- expect([1]).to_not(be_empty);
- })
+ describe(".matches", function() {
+ it("matches when Array#length == 0", function() {
+ expect([]).to(be_empty);
+ expect([1]).to_not(be_empty);
+ });
+ });
+
+ describe(".failure_message", function() {
+ describe("on a positive failure", function() {
+ it("prints 'expected ... to be empty'", function() {
+ var message = null;
+ try {
+ expect([1]).to(be_empty);
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [1] to be empty");
+ });
+ });
+
+ describe("on a negative failure", function() {
+ it("prints 'expected ... to not be empty'", function() {
+ var message = null;
+ try {
+ expect([]).to_not(be_empty);
+ } catch(e) {
+ message = e;
+ }
+ expect(message).to(equal, "expected [] to not be empty");
+ });
+ });
+ });
});
});

0 comments on commit 38aaef4

Please sign in to comment.
Something went wrong with that request. Please try again.