From 8cc68d7000593f950a586745fca3a390e4aea028 Mon Sep 17 00:00:00 2001 From: Matthijs Groen Date: Fri, 8 Feb 2013 15:01:36 +0100 Subject: [PATCH] Fix negation of backbone routes --- chai-backbone.coffee | 5 ++++- chai-backbone.js | 7 +++++-- package.json | 4 ++-- test/chai-backbone_spec.coffee | 11 +++++++++++ test/chai-backbone_spec.js | 15 ++++++++++++++- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/chai-backbone.coffee b/chai-backbone.coffee index 01f6237..7254a52 100644 --- a/chai-backbone.coffee +++ b/chai-backbone.coffee @@ -77,8 +77,11 @@ # reset history to clear active routes Backbone.history = new Backbone.History + unless (utils.type(router) is 'object') and (router instanceof Backbone.Router) + throw TypeError 'provided router is not a Backbone.Router' + expect(router).to.be.an.instanceOf Backbone.Router + stub = sinon.stub router, methodName # stub on our expected method call - @assert router._bindRoutes?, 'provided router is not a Backbone.Router' router._bindRoutes() # inject router routes into our history if options.considering? # if multiple routers are provided load their routes aswell diff --git a/chai-backbone.js b/chai-backbone.js index 602b725..6de5273 100644 --- a/chai-backbone.js +++ b/chai-backbone.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.4.0 (function() { (function(chaiBackbone) { @@ -50,8 +50,11 @@ } current_history = Backbone.history; Backbone.history = new Backbone.History; + if (!((utils.type(router) === 'object') && (router instanceof Backbone.Router))) { + throw TypeError('provided router is not a Backbone.Router'); + } + expect(router).to.be.an.instanceOf(Backbone.Router); stub = sinon.stub(router, methodName); - this.assert(router._bindRoutes != null, 'provided router is not a Backbone.Router'); router._bindRoutes(); if (options.considering != null) { _ref = options.considering; diff --git a/package.json b/package.json index e569e99..953bec9 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "chai-backbone", "description": "Backbone assertions for the Chai assertion library", "keywords": [ "test", "assertion", "assert", "testing", "backbone" ], - "version": "0.8.4", + "version": "0.9.0", "repository": { "type": "git", "url": "https://github.com/matthijsgroen/chai-backbone" @@ -23,7 +23,7 @@ "backbone": ">= 0.9.2" }, "scripts": { - "test": "mocha", + "test": "mocha test/chai-backbone_spec.coffee", "test-browser": "./test.sh" }, "licenses": [ diff --git a/test/chai-backbone_spec.coffee b/test/chai-backbone_spec.coffee index 55404fb..c9ca85b 100644 --- a/test/chai-backbone_spec.coffee +++ b/test/chai-backbone_spec.coffee @@ -39,12 +39,23 @@ describe 'Chai-Backbone matchers', -> beforeEach -> router = new routerClass + it 'validates if provided router is a Backbone.Router', -> + expect(-> + "route1/ere".should.route.to { noRouter: 'check' }, 'subRoute' + ).to.throw TypeError, 'provided router is not a Backbone.Router' + it 'checks if a method is trigger by route', -> "route1/sub".should.route.to router, 'subRoute' expect(-> "route1/ere".should.route.to router, 'subRoute' ).to.throw 'expected `route1/ere` to route to subRoute' + it 'allows negation in route assertion', -> + "route1/ere".should.not.route.to router, 'subRoute' + expect(-> + "route1/sub".should.not.route.to router, 'subRoute' + ).to.throw 'expected `route1/sub` not to route to subRoute' + it 'verifies argument parsing', -> "route2/argVal".should.route.to router, 'routeWithArg', arguments: ['argVal'] expect(-> diff --git a/test/chai-backbone_spec.js b/test/chai-backbone_spec.js index fcb59b7..7ee15c6 100644 --- a/test/chai-backbone_spec.js +++ b/test/chai-backbone_spec.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.4.0 (function() { var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -74,12 +74,25 @@ beforeEach(function() { return router = new routerClass; }); + it('validates if provided router is a Backbone.Router', function() { + return expect(function() { + return "route1/ere".should.route.to({ + noRouter: 'check' + }, 'subRoute'); + }).to["throw"](TypeError, 'provided router is not a Backbone.Router'); + }); it('checks if a method is trigger by route', function() { "route1/sub".should.route.to(router, 'subRoute'); return expect(function() { return "route1/ere".should.route.to(router, 'subRoute'); }).to["throw"]('expected `route1/ere` to route to subRoute'); }); + it('allows negation in route assertion', function() { + "route1/ere".should.not.route.to(router, 'subRoute'); + return expect(function() { + return "route1/sub".should.not.route.to(router, 'subRoute'); + }).to["throw"]('expected `route1/sub` not to route to subRoute'); + }); it('verifies argument parsing', function() { "route2/argVal".should.route.to(router, 'routeWithArg', { "arguments": ['argVal']