From 9a675675cc760da943f2cde2b091f5b4af3b2b37 Mon Sep 17 00:00:00 2001 From: rosskaff Date: Sun, 24 Jan 2010 14:10:57 -0500 Subject: [PATCH] Add 'be_instance_of' matcher --- lib/screw.css | 8 ++++++-- lib/screw.matchers.js | 10 ++++++++++ spec/matchers_spec.js | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/screw.css b/lib/screw.css index e277b65..5c0ce72 100644 --- a/lib/screw.css +++ b/lib/screw.css @@ -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 { diff --git a/lib/screw.matchers.js b/lib/screw.matchers.js index 82784b0..0415c8e 100644 --- a/lib/screw.matchers.js +++ b/lib/screw.matchers.js @@ -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); diff --git a/spec/matchers_spec.js b/spec/matchers_spec.js index 19b9c0f..b574e9c 100644 --- a/spec/matchers_spec.js +++ b/spec/matchers_spec.js @@ -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);