Skip to content

Commit

Permalink
Add 'be_instance_of' matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
rossta committed Jan 24, 2010
1 parent 2cbf31d commit 9a67567
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/screw.css
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions lib/screw.matchers.js
Expand Up @@ -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);
25 changes: 25 additions & 0 deletions spec/matchers_spec.js
Expand Up @@ -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);
Expand Down

0 comments on commit 9a67567

Please sign in to comment.