Permalink
Browse files

Add 'be_instance_of' matcher

  • Loading branch information...
1 parent 2cbf31d commit 9a675675cc760da943f2cde2b091f5b4af3b2b37 @rossta committed Jan 24, 2010
Showing with 41 additions and 2 deletions.
  1. +6 −2 lib/screw.css
  2. +10 −0 lib/screw.matchers.js
  3. +25 −0 spec/matchers_spec.js
View
@@ -3,7 +3,12 @@ html {
margin:0;
padding:0;
list-style-position:inside;
+ background-color: SeaGreen;
}
+ body > div.describe {
+ margin:0 auto;
+ width:75%;
+ }
li {
list-style-type: none;
@@ -87,14 +92,13 @@ html {
}
.describes .describe .its .it.failed h2 {
- background-color: #993300;
+ background-color: #EE5757;
color: white !important;
}
.describes .describe .its .it.failed p {
margin-left: 1em;
color: #993300;
- background-color:#EE5757;
}
.describes .describe .its .it h2:hover {
View
@@ -249,6 +249,16 @@ Screw.Matchers = (function($) {
failure_message: function(expected, actual, not) {
return 'expected ' + $.print(actual) + (not ? ' to not contain selector ' : ' to contain selector ') + expected;
}
+ },
+
+ be_instance_of: {
+ match: function(expected, actual) {
+ return (actual instanceof expected);
+ },
+
+ failure_message: function(expected, actual, not) {
+ return 'expected instance of ' + $.print(expected.toString());
+ }
}
};
})(jQuery);
View
@@ -136,6 +136,31 @@ Screw.Unit(function() {
});
});
+ describe('#be_instance_of', function() {
+ var TestClass = function() {};
+
+ it('matches an instance of given function', function () {
+ expect(new TestClass()).to(be_instance_of, TestClass);
+ });
+
+ it('does not match an instance unrelated function', function () {
+ expect(new RegExp()).to_not(be_instance_of, TestClass);
+ });
+
+ // describe(".failure_message", function() {
+ // it('prints "expected [actual] to be an instance of [expected]', function() {
+ // try { expect(new TestClass()).to(be_instance_of, RegExp); } catch(e) { message = e; }
+ // expect(message).to(equal, '');
+ // });
+ //
+ // it('prints "expected [actual] to not be an instance of [expected]', function() {
+ // var message = null;
+ // try { expect(new TestClass()).to_not(be_instance_of, TestClass); } catch(e) { message = e; }
+ // expect(message).to(equal, 'expected [ new "TestClass" ] to be an instance of "TestClass"');
+ // });
+ });
+ });
+
describe('#be_empty', function() {
it("matches Arrays with no elements", function() {
expect([]).to(be_empty);

0 comments on commit 9a67567

Please sign in to comment.