Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added true, false, null and undefined matchers

  • Loading branch information...
commit 5d64e8ebf539a9c8ff33d996569cab425a83ea6b 1 parent 67d83bb
@nathansobo nathansobo authored
Showing with 120 additions and 0 deletions.
  1. +40 −0 lib/screw.matchers.js
  2. +80 −0 spec/matchers_spec.js
View
40 lib/screw.matchers.js
@@ -60,6 +60,46 @@ Screw.Matchers = (function($) {
failure_message: function(expected, actual, not) {
return 'expected ' + $.print(actual) + (not ? ' to not be empty' : ' to be empty');
}
+ },
+
+ be_null: {
+ match: function(expected, actual) {
+ return actual == null;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be null' : ' to be null');
+ }
+ },
+
+ be_undefined: {
+ match: function(expected, actual) {
+ return actual == undefined;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be undefined' : ' to be undefined');
+ }
+ },
+
+ be_true: {
+ match: function(expected, actual) {
+ return actual;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be true' : ' to be true');
+ }
+ },
+
+ be_false: {
+ match: function(expected, actual) {
+ return !actual;
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected ' + $.print(actual) + (not ? ' to not be false' : ' to be false');
+ }
}
}
})(jQuery);
View
80 spec/matchers_spec.js
@@ -89,5 +89,85 @@ Screw.Unit(function() {
});
});
});
+
+ describe('#be_null', function() {
+ it("matches null", function() {
+ expect(null).to(be_null);
+ expect(1).to_not(be_null);
+ });
+
+ describe(".failure_message", function() {
+ it("prints 'expected [actual] to (not) be null", function() {
+ var message = null;
+ try { expect(1).to(be_null) } catch(e) { message = e }
+ expect(message).to(equal, 'expected 1 to be null');
+
+ try { expect(null).to_not(be_null) } catch(e) { message = e }
+ expect(message).to(equal, 'expected null to not be null');
+ });
+ });
+ });
+
+ describe('#be_undefined', function() {
+ it("matches undefined", function() {
+ expect(undefined).to(be_undefined);
+ expect(1).to_not(be_undefined);
+ });
+
+ describe(".failure_message", function() {
+ it("prints 'expected [actual] to (not) be undefined", function() {
+ var message = undefined;
+ try { expect(1).to(be_undefined) } catch(e) { message = e }
+ expect(message).to(equal, 'expected 1 to be undefined');
+
+ try { expect(undefined).to_not(be_undefined) } catch(e) { message = e }
+ expect(message).to(equal, 'expected undefined to not be undefined');
+ });
+ });
+ });
+
+ describe('#be_true', function() {
+ it("matches values that are considered true conditions", function() {
+ expect(true).to(be_true);
+ expect(1).to(be_true);
+ expect(false).to_not(be_true);
+ expect(undefined).to_not(be_true);
+ expect(null).to_not(be_true);
+ });
+
+ describe(".failure_message", function() {
+ it("prints 'expected [actual] to (not) be true", function() {
+ var message = true;
+ try { expect(false).to(be_true) } catch(e) { message = e }
+ expect(message).to(equal, 'expected false to be true');
+
+ try { expect(true).to_not(be_true) } catch(e) { message = e }
+ expect(message).to(equal, 'expected true to not be true');
+ });
+ });
+ });
+
+ describe('#be_false', function() {
+ it("matches values that are considered false conditions", function() {
+ expect(false).to(be_false);
+ expect(undefined).to(be_false);
+ expect(null).to(be_false);
+ expect(true).to_not(be_false);
+ expect(1).to_not(be_false);
+ });
+
+ describe(".failure_message", function() {
+ it("prints 'expected [actual] to (not) be false", function() {
+ var message = false;
+ try { expect(true).to(be_false) } catch(e) { message = e }
+ expect(message).to(equal, 'expected true to be false');
+
+ try { expect(false).to_not(be_false) } catch(e) { message = e }
+ expect(message).to(equal, 'expected false to not be false');
+ });
+ });
+ });
+
+
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.