From 1260e410bbf03e4901030e91e9ce20288c37f429 Mon Sep 17 00:00:00 2001 From: James Kyle Date: Fri, 23 May 2014 00:11:08 -0400 Subject: [PATCH] thisify sinon --- spec/javascripts/appRouter.spec.js | 86 ++++---- .../application.appRegions.spec.js | 17 +- spec/javascripts/application.spec.js | 10 +- spec/javascripts/behaviors.spec.js | 58 +++--- spec/javascripts/bindEntityEvents.spec.js | 18 +- spec/javascripts/callbacks.spec.js | 12 +- .../collectionView.emptyView.spec.js | 12 +- .../collectionView.itemViewOptions.spec.js | 6 +- spec/javascripts/collectionView.reset.spec.js | 9 +- spec/javascripts/collectionView.spec.js | 195 +++++------------- .../compositeView-childViewContainer.spec.js | 20 +- spec/javascripts/compositeView.spec.js | 45 +--- spec/javascripts/controller.spec.js | 38 ++-- spec/javascripts/destroyingViews.spec.js | 20 +- spec/javascripts/itemView.spec.js | 86 +++----- .../layoutView.dynamicRegions.spec.js | 30 +-- spec/javascripts/layoutView.spec.js | 42 ++-- spec/javascripts/module.spec.js | 69 +++---- spec/javascripts/module.stop.spec.js | 28 +-- spec/javascripts/onDomRefresh.spec.js | 3 +- spec/javascripts/region.spec.js | 168 +++++---------- spec/javascripts/regionManager.spec.js | 53 ++--- spec/javascripts/renderer.spec.js | 12 +- spec/javascripts/sortedViews.spec.js | 6 +- spec/javascripts/templateCache.spec.js | 12 +- spec/javascripts/templateHelpers.spec.js | 15 +- spec/javascripts/triggerMethod.spec.js | 6 +- spec/javascripts/unbindEntityEvents.spec.js | 18 +- spec/javascripts/view.entityEvents.spec.js | 59 +++--- spec/javascripts/view.spec.js | 45 ++-- spec/javascripts/view.triggers.spec.js | 27 +-- .../view.uiEventAndTriggers.spec.js | 14 +- 32 files changed, 440 insertions(+), 799 deletions(-) diff --git a/spec/javascripts/appRouter.spec.js b/spec/javascripts/appRouter.spec.js index 287c22f90f..964001ffe4 100644 --- a/spec/javascripts/appRouter.spec.js +++ b/spec/javascripts/appRouter.spec.js @@ -36,11 +36,13 @@ describe('app router', function() { } }); - var controller = { - method1: sinon.stub() - }; + var controller; beforeEach(function() { + controller = { + method1: this.sinon.stub() + }; + var router = new Router({ controller: controller }); @@ -63,19 +65,21 @@ describe('app router', function() { }); describe('when a controller is provided in the router definition and a route fires', function() { - var controller = { - method1: sinon.stub() - }; + var controller, Router; - var Router = Backbone.Marionette.AppRouter.extend({ - appRoutes: { - 'm1': 'method1' - }, + beforeEach(function() { + controller = { + method1: this.sinon.stub() + }; - controller: controller - }); + Router = Backbone.Marionette.AppRouter.extend({ + appRoutes: { + 'm1': 'method1' + }, + + controller: controller + }); - beforeEach(function() { var router = new Router(); Backbone.history.start(); @@ -105,14 +109,18 @@ describe('app router', function() { } }); - var Controller = function() { - return { - method1: function() {}, - method2: sinon.stub() - }; - }; + var Controller; beforeEach(function() { + var self = this; + + Controller = function() { + return { + method1: function() {}, + method2: self.sinon.stub() + }; + }; + controller = new Controller(); var router = new Router({ @@ -140,19 +148,20 @@ describe('app router', function() { describe('when a route fires with parameters', function() { var spy, router; - var Router = Backbone.Marionette.AppRouter.extend({ - onRoute: sinon.stub(), - appRoutes: { - 'm2/:id': 'withParam' - } - }); + var Router; var controller = { withParam: function() {} }; beforeEach(function() { - spy = sinon.spy(controller, 'withParam'); + Router = Backbone.Marionette.AppRouter.extend({ + onRoute: this.sinon.stub(), + appRoutes: { + 'm2/:id': 'withParam' + } + }); + spy = this.sinon.spy(controller, 'withParam'); router = new Router({ controller: controller @@ -163,9 +172,7 @@ describe('app router', function() { }); afterEach(function() { - controller.withParam.restore(); Backbone.history.stop(); - router.onRoute.reset(); }); it('should call the configured method with parameters', function() { @@ -191,7 +198,7 @@ describe('app router', function() { var router; beforeEach(function() { - sinon.spy(Router.prototype, 'standardRoute'); + this.sinon.spy(Router.prototype, 'standardRoute'); router = new Router(); Backbone.history.start(); @@ -200,7 +207,6 @@ describe('app router', function() { }); afterEach(function() { - Router.prototype.standardRoute.restore(); Backbone.history.stop(); }); @@ -221,8 +227,8 @@ describe('app router', function() { }); controller = { - showPostsTop: sinon.stub(), - showPost: sinon.stub() + showPostsTop: this.sinon.stub(), + showPost: this.sinon.stub() }; Backbone.history.start(); @@ -253,8 +259,8 @@ describe('app router', function() { }); controller = { - showPostsTop: sinon.stub(), - showPost: sinon.stub() + showPostsTop: this.sinon.stub(), + showPost: this.sinon.stub() }; Backbone.history.start(); @@ -280,7 +286,7 @@ describe('app router', function() { var Router = Backbone.Marionette.AppRouter.extend({}); controller = { - showPost: sinon.stub() + showPost: this.sinon.stub() }; Backbone.history.start(); @@ -307,12 +313,14 @@ describe('app router', function() { } }); - var controller = { - originalFunc: sinon.stub(), - overrideFunc: sinon.stub() - }; + var controller; beforeEach(function() { + controller = { + originalFunc: this.sinon.stub(), + overrideFunc: this.sinon.stub() + }; + var appRouter = new AppRouter({ controller: controller, appRoutes: { diff --git a/spec/javascripts/application.appRegions.spec.js b/spec/javascripts/application.appRegions.spec.js index 81d24ef062..9b0f5b3c65 100644 --- a/spec/javascripts/application.appRegions.spec.js +++ b/spec/javascripts/application.appRegions.spec.js @@ -13,8 +13,8 @@ describe('application regions', function() { this.setFixtures('
'); this.setFixtures('
'); - beforeAddHandler = sinon.spy(); - addHandler = sinon.spy(); + beforeAddHandler = this.sinon.spy(); + addHandler = this.sinon.spy(); MyApp.on('before:add:region', beforeAddHandler); MyApp.on('add:region', addHandler); @@ -141,17 +141,12 @@ describe('application regions', function() { r1 = app.myRegion; r2 = app.r2; - sinon.spy(r1, 'destroy'); - sinon.spy(r2, 'destroy'); + this.sinon.spy(r1, 'destroy'); + this.sinon.spy(r2, 'destroy'); app.destroyRegions(); }); - afterEach(function () { - r1.destroy.restore(); - r2.destroy.restore(); - }); - it('should destroy the regions', function() { expect(r1.destroy).to.have.been.called; expect(r2.destroy).to.have.been.called; @@ -167,8 +162,8 @@ describe('application regions', function() { this.setFixtures('
'); this.setFixtures('
'); - beforeRemoveHandler = sinon.spy(); - removeHandler = sinon.spy(); + beforeRemoveHandler = this.sinon.spy(); + removeHandler = this.sinon.spy(); MyApp.on('before:remove:region', beforeRemoveHandler); MyApp.on('remove:region', removeHandler); diff --git a/spec/javascripts/application.spec.js b/spec/javascripts/application.spec.js index 99cc74f044..1b31d0ef02 100644 --- a/spec/javascripts/application.spec.js +++ b/spec/javascripts/application.spec.js @@ -9,28 +9,24 @@ describe('marionette application', function() { var someOptions = {}; beforeEach(function() { + var self = this; MyApp = new Backbone.Marionette.Application(); MyModule = (function(MyApp) { var module = {}; module.initializer = function() {}; - sinon.spy(module, 'initializer'); + self.sinon.spy(module, 'initializer'); MyApp.addInitializer(module.initializer); return module; })(MyApp); - sinon.spy(MyApp, 'trigger'); + this.sinon.spy(MyApp, 'trigger'); MyApp.start(someOptions); }); - afterEach(function() { - MyModule.initializer.restore(); - MyApp.trigger.restore(); - }); - it('should notify me before the starts', function() { expect(MyApp.trigger).to.have.been.calledWith('before:start', someOptions); }); diff --git a/spec/javascripts/behaviors.spec.js b/spec/javascripts/behaviors.spec.js index 52f7ed4561..fa9a5fe523 100644 --- a/spec/javascripts/behaviors.spec.js +++ b/spec/javascripts/behaviors.spec.js @@ -13,7 +13,7 @@ describe('Behaviors', function() { var Obj, View, Tooltip; beforeEach(function() { - Tooltip = sinon.spy(); + Tooltip = this.sinon.spy(); Obj = { Tooltip: Tooltip }; @@ -48,7 +48,7 @@ describe('Behaviors', function() { var Obj, View, Tooltip; beforeEach(function() { - Tooltip = sinon.spy(); + Tooltip = this.sinon.spy(); Obj = { Tooltip: Tooltip }; @@ -151,7 +151,7 @@ describe('Behaviors', function() { beforeEach(function() { Behavior = Marionette.Behavior.extend({ - initialize: sinon.spy() + initialize: this.sinon.spy() }); Obj = { @@ -194,10 +194,10 @@ describe('Behaviors', function() { var View, view, Obj, spy, spy2, spy3, viewSpy; beforeEach(function() { - spy = sinon.spy(); - spy2 = sinon.spy(); - spy3 = sinon.spy(); - viewSpy = sinon.spy(); + spy = this.sinon.spy(); + spy2 = this.sinon.spy(); + spy3 = this.sinon.spy(); + viewSpy = this.sinon.spy(); Obj = { Tooltip: Marionette.Behavior.extend({ @@ -292,11 +292,11 @@ describe('Behaviors', function() { beforeEach(function() { hold = {}; - spy = new sinon.spy(); - onShowSpy = new sinon.spy(); - onDestroySpy = new sinon.spy(); - onDogeClickSpy = new sinon.spy(); - onCoinsClickSpy = new sinon.spy(); + spy = this.sinon.spy(); + onShowSpy = this.sinon.spy(); + onDestroySpy = this.sinon.spy(); + onDogeClickSpy = this.sinon.spy(); + onCoinsClickSpy = this.sinon.spy(); hold.test = Marionette.Behavior.extend({ ui: { @@ -470,8 +470,8 @@ describe('Behaviors', function() { var model, v, listenToSpy, onSpy; beforeEach(function() { - listenToSpy = new sinon.spy(); - onSpy = new sinon.spy(); + listenToSpy = this.sinon.spy(); + onSpy = this.sinon.spy(); model = new Backbone.Model(); v = new (Marionette.View.extend({ @@ -540,9 +540,9 @@ describe('Behaviors', function() { var modelSpy, collectionSpy, fooChangedSpy, View, view, CollectionView, hold, model, testBehavior, collection; beforeEach(function() { - modelSpy = sinon.spy(); - collectionSpy = sinon.spy(); - fooChangedSpy = sinon.spy(); + modelSpy = this.sinon.spy(); + collectionSpy = this.sinon.spy(); + fooChangedSpy = this.sinon.spy(); hold = {}; @@ -632,7 +632,7 @@ describe('Behaviors', function() { describe('behavior trigger calls', function() { var onRenderSpy, View, hold; beforeEach(function() { - onRenderSpy = sinon.spy(); + onRenderSpy = this.sinon.spy(); hold = {}; hold.testB = Marionette.Behavior.extend({ onRender: onRenderSpy @@ -657,7 +657,7 @@ describe('Behaviors', function() { describe('behavior is evented', function() { var spy, behavior, model; beforeEach(function() { - spy = sinon.spy(); + spy = this.sinon.spy(); behavior = new Marionette.Behavior({}, {}); model = new Backbone.Model(); @@ -689,13 +689,13 @@ describe('Behaviors', function() { var viewEventSpy, childEventSpy, parentEventSpy; var View, v, m, c, hold, parentBehavior, groupedBehavior; beforeEach(function() { - initSpy = sinon.spy(); - renderSpy = sinon.spy(); - childRenderSpy = sinon.spy(); - entityEventSpy = sinon.spy(); - childEventSpy = sinon.spy(); - parentEventSpy = sinon.spy(); - viewEventSpy = sinon.spy(); + initSpy = this.sinon.spy(); + renderSpy = this.sinon.spy(); + childRenderSpy = this.sinon.spy(); + entityEventSpy = this.sinon.spy(); + childEventSpy = this.sinon.spy(); + parentEventSpy = this.sinon.spy(); + viewEventSpy = this.sinon.spy(); hold = {}; hold.parentB = Marionette.Behavior.extend({ @@ -753,11 +753,7 @@ describe('Behaviors', function() { c = new Backbone.Collection(); v = new View({model: m, collection: c}); - sinon.spy(v, 'undelegateEvents'); - }); - - afterEach(function () { - v.undelegateEvents.restore(); + this.sinon.spy(v, 'undelegateEvents'); }); it('should call initialize on grouped behaviors', function() { diff --git a/spec/javascripts/bindEntityEvents.spec.js b/spec/javascripts/bindEntityEvents.spec.js index b1fd128c9f..eff9a2c768 100644 --- a/spec/javascripts/bindEntityEvents.spec.js +++ b/spec/javascripts/bindEntityEvents.spec.js @@ -8,12 +8,12 @@ describe('Marionette.bindEntityEvents', function() { beforeEach(function() { target = { - foo: sinon.spy(), - bar: sinon.spy(), - listenTo: sinon.spy() + foo: this.sinon.spy(), + bar: this.sinon.spy(), + listenTo: this.sinon.spy() }; - entity = sinon.spy(); + entity = this.sinon.spy(); }); describe('when entity isnt passed', function() { @@ -40,7 +40,7 @@ describe('Marionette.bindEntityEvents', function() { var bindingsSpy; beforeEach(function() { - bindingsSpy = sinon.spy(function() { + bindingsSpy = this.sinon.spy(function() { return {'eventNameMock': 'foo'}; }); @@ -126,13 +126,13 @@ describe('Marionette.bindEntityEvents', function() { describe('when bindEntityEvents is proxied', function() { beforeEach(function() { target = { - foo: sinon.spy(), - bar: sinon.spy(), - listenTo: sinon.spy(), + foo: this.sinon.spy(), + bar: this.sinon.spy(), + listenTo: this.sinon.spy(), bindEntityEvents: Marionette.proxyBindEntityEvents }; - entity = sinon.spy(); + entity = this.sinon.spy(); target.bindEntityEvents(entity, {'eventNameMock': target.foo}); }); diff --git a/spec/javascripts/callbacks.spec.js b/spec/javascripts/callbacks.spec.js index 2ed3c02e1e..7310917abc 100644 --- a/spec/javascripts/callbacks.spec.js +++ b/spec/javascripts/callbacks.spec.js @@ -9,8 +9,8 @@ describe('callbacks', function() { spyOne, spyTwo; beforeEach(function() { - spyOne = sinon.spy(); - spyTwo = sinon.spy(); + spyOne = this.sinon.spy(); + spyTwo = this.sinon.spy(); var callbacks = new Backbone.Marionette.Callbacks(); specifiedOptions = {}; @@ -43,8 +43,8 @@ describe('callbacks', function() { var spyOne, spyTwo; beforeEach(function() { - spyOne = sinon.spy(); - spyTwo = sinon.spy(); + spyOne = this.sinon.spy(); + spyTwo = this.sinon.spy(); var callbacks = new Backbone.Marionette.Callbacks(); callbacks.run(); @@ -65,7 +65,7 @@ describe('callbacks', function() { var spyOne, context; beforeEach(function() { - spyOne = sinon.spy(); + spyOne = this.sinon.spy(); context = {}; var callbacks = new Backbone.Marionette.Callbacks(); @@ -85,7 +85,7 @@ describe('callbacks', function() { beforeEach(function() { var callbacks = new Backbone.Marionette.Callbacks(); - spy = sinon.spy(); + spy = this.sinon.spy(); callbacks.add(spy); callbacks.run(); diff --git a/spec/javascripts/collectionView.emptyView.spec.js b/spec/javascripts/collectionView.emptyView.spec.js index d402793038..dd600cb4a2 100644 --- a/spec/javascripts/collectionView.emptyView.spec.js +++ b/spec/javascripts/collectionView.emptyView.spec.js @@ -48,15 +48,11 @@ describe('collectionview - emptyView', function() { var destroySpy; beforeEach(function() { - destroySpy = sinon.spy(EmptyView.prototype, 'destroy'); + destroySpy = this.sinon.spy(EmptyView.prototype, 'destroy'); collection.add({foo: 'wut'}); }); - afterEach(function () { - EmptyView.prototype.destroy.restore(); - }); - it('should destroy the emptyView', function() { expect(destroySpy).to.have.been.called; }); @@ -78,17 +74,13 @@ describe('collectionview - emptyView', function() { collectionView.render(); - destroySpy = sinon.spy(EmptyView.prototype, 'destroy'); + destroySpy = this.sinon.spy(EmptyView.prototype, 'destroy'); collection.reset([{foo: 'bar'}, {foo: 'baz'}]); collection.add({foo: 'wut'}); }); - afterEach(function () { - EmptyView.prototype.destroy.restore(); - }); - it('should destroy the emptyView', function() { expect(destroySpy).to.have.been.called; }); diff --git a/spec/javascripts/collectionView.itemViewOptions.spec.js b/spec/javascripts/collectionView.itemViewOptions.spec.js index 3af6cdd458..da4ac997c0 100644 --- a/spec/javascripts/collectionView.itemViewOptions.spec.js +++ b/spec/javascripts/collectionView.itemViewOptions.spec.js @@ -55,16 +55,12 @@ describe('collection view - childViewOptions', function() { collectionView = new CollectionView({ collection: collection }); - sinon.spy(collectionView, 'childViewOptions'); + this.sinon.spy(collectionView, 'childViewOptions'); collectionView.render(); view = collectionView.children.findByIndex(0); }); - afterEach(function () { - collectionView.childViewOptions.restore(); - }); - it('should pass the options to every view instance', function() { expect(view.options.hasOwnProperty('foo')).to.be.true; }); diff --git a/spec/javascripts/collectionView.reset.spec.js b/spec/javascripts/collectionView.reset.spec.js index 88e33c8cce..692de1d15e 100644 --- a/spec/javascripts/collectionView.reset.spec.js +++ b/spec/javascripts/collectionView.reset.spec.js @@ -32,19 +32,14 @@ describe('collection view - reset', function() { collection: collection }); - sinon.spy(collectionView, 'onRender'); - sinon.spy(collectionView, 'destroyChildren'); + this.sinon.spy(collectionView, 'onRender'); + this.sinon.spy(collectionView, 'destroyChildren'); collectionView.render(); collection.reset([{foo: 'bar'}, {foo: 'baz'}]); }); - afterEach(function () { - collectionView.onRender.restore(); - collectionView.destroyChildren.restore(); - }); - it('should destroy all open child views', function() { expect(collectionView.destroyChildren).to.have.been.called; }); diff --git a/spec/javascripts/collectionView.spec.js b/spec/javascripts/collectionView.spec.js index fa2aa15535..20db711ad6 100644 --- a/spec/javascripts/collectionView.spec.js +++ b/spec/javascripts/collectionView.spec.js @@ -52,7 +52,7 @@ describe('collection view', function() { var collectionView, childViewRender; beforeEach(function() { - childViewRender = sinon.stub(); + childViewRender = this.sinon.stub(); collectionView = new MockCollectionView({ collection: collection @@ -60,31 +60,19 @@ describe('collection view', function() { collectionView.on('childview:render', childViewRender); - sinon.spy(collectionView, 'onRender'); - sinon.spy(collectionView, 'onBeforeAddChild'); - sinon.spy(collectionView, 'onAddChild'); - sinon.spy(collectionView, 'onBeforeRender'); - sinon.spy(collectionView, 'trigger'); - sinon.spy(collectionView, 'attachHtml'); - sinon.spy(collectionView.$el, 'append'); - sinon.spy(collectionView, 'startBuffering'); - sinon.spy(collectionView, 'endBuffering'); + this.sinon.spy(collectionView, 'onRender'); + this.sinon.spy(collectionView, 'onBeforeAddChild'); + this.sinon.spy(collectionView, 'onAddChild'); + this.sinon.spy(collectionView, 'onBeforeRender'); + this.sinon.spy(collectionView, 'trigger'); + this.sinon.spy(collectionView, 'attachHtml'); + this.sinon.spy(collectionView.$el, 'append'); + this.sinon.spy(collectionView, 'startBuffering'); + this.sinon.spy(collectionView, 'endBuffering'); collectionView.render(); }); - afterEach(function () { - collectionView.onRender.restore(); - collectionView.onBeforeAddChild.restore(); - collectionView.onAddChild.restore(); - collectionView.onBeforeRender.restore(); - collectionView.trigger.restore(); - collectionView.attachHtml.restore(); - collectionView.$el.append.restore(); - collectionView.startBuffering.restore(); - collectionView.endBuffering.restore(); - }); - it('should only call $el.append once', function() { expect(collectionView.$el.append.callCount).to.equal(1); }); @@ -166,19 +154,13 @@ describe('collection view', function() { beforeEach(function() { collectionView = new MockCollectionView(); - sinon.spy(collectionView, 'onRender'); - sinon.spy(collectionView, 'onBeforeRender'); - sinon.spy(collectionView, 'trigger'); + this.sinon.spy(collectionView, 'onRender'); + this.sinon.spy(collectionView, 'onBeforeRender'); + this.sinon.spy(collectionView, 'trigger'); collectionView.render(); }); - afterEach(function () { - collectionView.onRender.restore(); - collectionView.onBeforeRender.restore(); - collectionView.trigger.restore(); - }); - it('should not append any html', function() { expect($(collectionView.$el)).not.to.have.$html('barbaz'); }); @@ -199,19 +181,15 @@ describe('collection view', function() { }); collectionView.render(); - childViewRender = sinon.stub(); + childViewRender = this.sinon.stub(); collectionView.on('childview:render', childViewRender); - sinon.spy(collectionView, 'attachHtml'); + this.sinon.spy(collectionView, 'attachHtml'); model = new Backbone.Model({foo: 'bar'}); collection.add(model); }); - afterEach(function () { - collectionView.attachHtml.restore(); - }); - it('should add the model to the list', function() { expect(_.size(collectionView.children)).to.equal(1); }); @@ -241,19 +219,15 @@ describe('collection view', function() { }); collectionView.render(); - childViewRender = sinon.stub(); + childViewRender = this.sinon.stub(); collectionView.on('childview:render', childViewRender); - sinon.spy(collectionView, 'attachHtml'); + this.sinon.spy(collectionView, 'attachHtml'); model = new Backbone.Model({foo: 'baz'}); collection.add(model); }); - afterEach(function () { - collectionView.attachHtml.restore(); - }); - it('should add the model to the list', function() { expect(_.size(collectionView.children)).to.equal(2); }); @@ -302,22 +276,15 @@ describe('collection view', function() { childView = collectionView.children.findByIndex(0); - beforeRenderSpy = sinon.spy(collectionView, 'onBeforeRenderEmpty'); - renderSpy = sinon.spy(collectionView, 'onRenderEmpty'); + beforeRenderSpy = this.sinon.spy(collectionView, 'onBeforeRenderEmpty'); + renderSpy = this.sinon.spy(collectionView, 'onRenderEmpty'); - sinon.spy(childView, 'destroy'); - sinon.spy(EmptyView.prototype, 'render'); + this.sinon.spy(childView, 'destroy'); + this.sinon.spy(EmptyView.prototype, 'render'); collectionView._onCollectionRemove(model); }); - afterEach(function () { - collectionView.onBeforeRenderEmpty.restore(); - collectionView.onRenderEmpty.restore(); - childView.destroy.restore(); - EmptyView.prototype.render.restore(); - }); - it('should destroy the models view', function() { expect(childView.destroy).to.have.been.called; }); @@ -356,20 +323,14 @@ describe('collection view', function() { childView = collectionView.children.findByIndex(0); - sinon.spy(childView, 'destroy'); + this.sinon.spy(childView, 'destroy'); - onBeforeRemoveChildSpy = sinon.spy(collectionView, 'onBeforeRemoveChild'); - onRemoveChildSpy = sinon.spy(collectionView, 'onRemoveChild'); + onBeforeRemoveChildSpy = this.sinon.spy(collectionView, 'onBeforeRemoveChild'); + onRemoveChildSpy = this.sinon.spy(collectionView, 'onRemoveChild'); collection.remove(model); }); - afterEach(function() { - childView.destroy.restore(); - collectionView.onBeforeRemoveChild.restore(); - collectionView.onRemoveChild.restore(); - }); - it('should destroy the models view', function() { expect(childView.destroy).to.have.been.called; }); @@ -413,9 +374,10 @@ describe('collection view', function() { var collection; var childView; var childModel; - var destroyHandler = sinon.stub(); + var destroyHandler; beforeEach(function() { + destroyHandler = this.sinon.stub(); collection = new Backbone.Collection([{foo: 'bar'}, {foo: 'baz'}]); collectionView = new EventedView({ @@ -432,16 +394,16 @@ describe('collection view', function() { collectionView.listenTo(collection, 'foo', collectionView.someCallback); collectionView.listenTo(collectionView, 'item:foo', collectionView.someItemViewCallback); - sinon.spy(childView, 'destroy'); - sinon.spy(collectionView, '_onCollectionRemove'); - sinon.spy(collectionView, 'stopListening'); - sinon.spy(collectionView, 'remove'); - sinon.spy(collectionView, 'someCallback'); - sinon.spy(collectionView, 'someItemViewCallback'); - sinon.spy(collectionView, 'destroy'); - sinon.spy(collectionView, 'onDestroy'); - sinon.spy(collectionView, 'onBeforeDestroy'); - sinon.spy(collectionView, 'trigger'); + this.sinon.spy(childView, 'destroy'); + this.sinon.spy(collectionView, '_onCollectionRemove'); + this.sinon.spy(collectionView, 'stopListening'); + this.sinon.spy(collectionView, 'remove'); + this.sinon.spy(collectionView, 'someCallback'); + this.sinon.spy(collectionView, 'someItemViewCallback'); + this.sinon.spy(collectionView, 'destroy'); + this.sinon.spy(collectionView, 'onDestroy'); + this.sinon.spy(collectionView, 'onBeforeDestroy'); + this.sinon.spy(collectionView, 'trigger'); collectionView.bind('destroy:collection', destroyHandler); @@ -453,19 +415,6 @@ describe('collection view', function() { collection.remove(childModel); }); - afterEach(function () { - childView.destroy.restore(); - collectionView._onCollectionRemove.restore(); - collectionView.stopListening.restore(); - collectionView.remove.restore(); - collectionView.someCallback.restore(); - collectionView.someItemViewCallback.restore(); - collectionView.destroy.restore(); - collectionView.onDestroy.restore(); - collectionView.onBeforeDestroy.restore(); - collectionView.trigger.restore(); - }); - it('should destroy all of the child views', function() { expect(childView.destroy).to.have.been.called; }); @@ -531,15 +480,11 @@ describe('collection view', function() { collectionView.render(); childView = collectionView.children.findByIndex(0); - sinon.spy(childView, 'remove'); + this.sinon.spy(childView, 'remove'); collectionView.destroyChildren(); }); - afterEach(function() { - childView.remove.restore(); - }); - it('should call the "remove" method', function() { expect(childView.remove).to.have.been.called; }); @@ -575,7 +520,7 @@ describe('collection view', function() { var model, collection, collectionView, childView, someEventSpy; beforeEach(function() { - someEventSpy = sinon.stub(); + someEventSpy = this.sinon.stub(); model = new Backbone.Model({foo: 'bar'}); collection = new Backbone.Collection([model]); @@ -584,15 +529,11 @@ describe('collection view', function() { collectionView.on('childview:some:event', someEventSpy); collectionView.render(); - sinon.spy(collectionView, 'trigger'); + this.sinon.spy(collectionView, 'trigger'); childView = collectionView.children.findByIndex(0); childView.trigger('some:event', 'test', model); }); - afterEach(function() { - collectionView.trigger.restore(); - }); - it('should bubble up through the parent collection view', function() { expect(collectionView.trigger).to.have.been.calledWith('childview:some:event', childView, 'test', model); }); @@ -610,7 +551,7 @@ describe('collection view', function() { }); beforeEach(function() { - someEventSpy = sinon.stub(); + someEventSpy = this.sinon.stub(); model = new Backbone.Model({foo: 'bar'}); collection = new Backbone.Collection([model]); @@ -619,15 +560,11 @@ describe('collection view', function() { collectionView.on('myPrefix:some:event', someEventSpy); collectionView.render(); - sinon.spy(collectionView, 'trigger'); + this.sinon.spy(collectionView, 'trigger'); childView = collectionView.children.findByIndex(0); childView.trigger('some:event', 'test', model); }); - afterEach(function() { - collectionView.trigger.restore(); - }); - it('should bubble up through the parent collection view', function() { expect(collectionView.trigger).to.have.been.calledWith('myPrefix:some:event', childView, 'test', model); }); @@ -656,8 +593,8 @@ describe('collection view', function() { var beforeSpy, renderSpy; beforeEach(function() { - beforeSpy = sinon.stub(); - renderSpy = sinon.stub(); + beforeSpy = this.sinon.stub(); + renderSpy = this.sinon.stub(); collectionView.on('childview:before:render', beforeSpy); collectionView.on('childview:render', renderSpy); @@ -680,8 +617,8 @@ describe('collection view', function() { var beforeSpy, destroySpy; beforeEach(function() { - beforeSpy = sinon.stub(); - destroySpy = sinon.stub(); + beforeSpy = this.sinon.stub(); + destroySpy = this.sinon.stub(); collectionView.on('childview:before:destroy', beforeSpy); collectionView.on('childview:destroy', destroySpy); @@ -784,8 +721,8 @@ describe('collection view', function() { var collectionView; beforeEach(function() { - sinon.spy(ChildView.prototype, 'onShow'); - sinon.spy(ChildView.prototype, 'onDomRefresh'); + this.sinon.spy(ChildView.prototype, 'onShow'); + this.sinon.spy(ChildView.prototype, 'onDomRefresh'); model1 = new Backbone.Model(); model2 = new Backbone.Model(); @@ -799,18 +736,12 @@ describe('collection view', function() { collectionView.onShow(); collectionView.trigger('show'); - sinon.spy(collectionView, 'attachBuffer'); + this.sinon.spy(collectionView, 'attachBuffer'); collection.add(model2); view = collectionView.children.findByIndex(1); }); - afterEach(function() { - ChildView.prototype.onShow.restore(); - ChildView.prototype.onDomRefresh.restore(); - collectionView.attachBuffer.restore(); - }); - it('should not use the render buffer', function() { expect(collectionView.attachBuffer).not.to.have.been.called; }); @@ -865,7 +796,7 @@ describe('collection view', function() { }); beforeEach(function() { - someEventSpy = sinon.stub(); + someEventSpy = this.sinon.stub(); model = new Backbone.Model({foo: 'bar'}); collection = new Backbone.Collection([model]); @@ -874,15 +805,11 @@ describe('collection view', function() { collectionView.someEvent = someEventSpy; collectionView.render(); - sinon.spy(collectionView, 'trigger'); + this.sinon.spy(collectionView, 'trigger'); childView = collectionView.children.findByIndex(0); childView.trigger('some:event', 'test', model); }); - afterEach(function() { - collectionView.trigger.restore(); - }); - it('should bubble up through the parent collection view', function() { expect(collectionView.trigger).to.have.been.calledWith('childview:some:event', childView, 'test', model); }); @@ -896,7 +823,7 @@ describe('collection view', function() { var model, collection, collectionView, childView, onSomeEventSpy; beforeEach(function() { - onSomeEventSpy = sinon.stub(); + onSomeEventSpy = this.sinon.stub(); var CollectionView = MockCollectionView.extend({ childEvents: { @@ -910,15 +837,11 @@ describe('collection view', function() { collectionView = new CollectionView({collection: collection}); collectionView.render(); - sinon.spy(collectionView, 'trigger'); + this.sinon.spy(collectionView, 'trigger'); childView = collectionView.children.findByIndex(0); childView.trigger('some:event', 'test', model); }); - afterEach(function() { - collectionView.trigger.restore(); - }); - it('should bubble up through the parent collection view', function() { expect(collectionView.trigger).to.have.been.calledWith('childview:some:event', childView, 'test', model); }); @@ -938,7 +861,7 @@ describe('collection view', function() { }); beforeEach(function() { - someEventSpy = sinon.stub(); + someEventSpy = this.sinon.stub(); model = new Backbone.Model({foo: 'bar'}); collection = new Backbone.Collection([model]); @@ -947,15 +870,11 @@ describe('collection view', function() { collectionView.someEvent = someEventSpy; collectionView.render(); - sinon.spy(collectionView, 'trigger'); + this.sinon.spy(collectionView, 'trigger'); childView = collectionView.children.findByIndex(0); childView.trigger('some:event', 'test', model); }); - afterEach(function() { - collectionView.trigger.restore(); - }); - it('should bubble up through the parent collection view', function() { expect(collectionView.trigger).to.have.been.calledWith('childview:some:event', childView, 'test', model); }); @@ -990,14 +909,10 @@ describe('collection view', function() { var constructor, collectionView; beforeEach(function() { - constructor = sinon.spy(Marionette, 'View'); + constructor = this.sinon.spy(Marionette, 'View'); collectionView = new Marionette.CollectionView(); }); - afterEach(function () { - Marionette.View.restore(); - }); - it('calls the parent Marionette.Views constructor function on instantiation', function() { expect(constructor).to.have.been.called; }); diff --git a/spec/javascripts/compositeView-childViewContainer.spec.js b/spec/javascripts/compositeView-childViewContainer.spec.js index 1a27d076e5..6680d66209 100644 --- a/spec/javascripts/compositeView-childViewContainer.spec.js +++ b/spec/javascripts/compositeView-childViewContainer.spec.js @@ -50,15 +50,11 @@ describe('composite view - childViewContainer', function() { beforeEach(function() { compositeView = viewCreation(); - sinon.spy(compositeView, 'resetChildViewContainer'); + this.sinon.spy(compositeView, 'resetChildViewContainer'); compositeView.render(); }); - afterEach(function () { - compositeView.resetChildViewContainer.restore(); - }); - it('should reset any existing childViewContainer', function() { expect(compositeView.resetChildViewContainer).to.have.been.called; }); @@ -113,11 +109,7 @@ describe('composite view - childViewContainer', function() { collection: collection }); - sinon.spy(compositeView, 'resetChildViewContainer'); - }); - - afterEach(function () { - compositeView.resetChildViewContainer.restore(); + this.sinon.spy(compositeView, 'resetChildViewContainer'); }); it('should throw an error', function() { @@ -228,11 +220,7 @@ describe('composite view - childViewContainer', function() { compositeView = new CompositeView({ collection: collection }); - sinon.spy(compositeView, '_onCollectionAdd'); - }); - - afterEach(function() { - compositeView._onCollectionAdd.restore(); + this.sinon.spy(compositeView, '_onCollectionAdd'); }); it('should not raise any errors when item is added to collection', function() { @@ -264,7 +252,7 @@ describe('composite view - childViewContainer', function() { beforeEach(function() { compositeView = new CompositeView(); - compositeView.childViewContainer = sinon.stub().returns('ul'); + compositeView.childViewContainer = this.sinon.stub().returns('ul'); compositeView.render(); }); diff --git a/spec/javascripts/compositeView.spec.js b/spec/javascripts/compositeView.spec.js index 3425a27edc..2ebe9ee817 100644 --- a/spec/javascripts/compositeView.spec.js +++ b/spec/javascripts/compositeView.spec.js @@ -249,17 +249,12 @@ describe('composite view', function() { order.push(compositeView); }); - sinon.spy(compositeView, 'trigger'); - sinon.spy(compositeView, 'onRender'); + this.sinon.spy(compositeView, 'trigger'); + this.sinon.spy(compositeView, 'onRender'); compositeView.render(); }); - afterEach(function() { - compositeView.trigger.restore(); - compositeView.onRender.restore(); - }); - it('should trigger a render event for the model view', function() { expect(compositeView.trigger).to.have.been.calledWith('render:template'); }); @@ -319,21 +314,15 @@ describe('composite view', function() { collection: collection }); - sinon.spy(compositeView, 'render'); - sinon.spy(compositeView, 'destroyChildren'); - sinon.spy(Backbone.Marionette.Renderer, 'render'); + this.sinon.spy(compositeView, 'render'); + this.sinon.spy(compositeView, 'destroyChildren'); + this.sinon.spy(Backbone.Marionette.Renderer, 'render'); compositeRenderSpy = compositeView.render; compositeView.render(); compositeView.render(); }); - afterEach(function() { - compositeView.render.restore(); - compositeView.destroyChildren.restore(); - Backbone.Marionette.Renderer.render.restore(); - }); - it('should re-render the template view', function() { expect(Backbone.Marionette.Renderer.render.callCount).to.equal(2); }); @@ -459,11 +448,7 @@ describe('composite view', function() { compositeView.render(); - sinon.spy(compositeView, '_renderRoot'); - }); - - afterEach(function() { - compositeView._renderRoot.restore(); + this.sinon.spy(compositeView, '_renderRoot'); }); describe('and then resetting the collection', function() { @@ -586,17 +571,13 @@ describe('composite view', function() { collection: collection }); - sinon.spy(CompositeModelView.prototype, 'destroy'); + this.sinon.spy(CompositeModelView.prototype, 'destroy'); compositeView.render(); compositeView.destroy(); }); - afterEach(function() { - CompositeModelView.prototype.destroy.restore(); - }); - it('should delete the model view', function() { expect(compositeView.renderedModelView).to.be.undefined; }); @@ -779,16 +760,12 @@ describe('composite view', function() { gridView.onBeforeRender = function() { called = true; }; - sinon.spy(gridView, 'onBeforeRender'); + this.sinon.spy(gridView, 'onBeforeRender'); gridView.render(); }); - afterEach(function() { - gridView.onBeforeRender.restore(); - }); - // this test enforces that ui elements should be accessible as soon as their html was inserted // to the DOM it('should return its jQuery selector', function() { @@ -810,14 +787,10 @@ describe('composite view', function() { var constructor, compositeView; beforeEach(function() { - constructor = sinon.spy(Marionette, 'CollectionView'); + constructor = this.sinon.spy(Marionette, 'CollectionView'); compositeView = new Marionette.CompositeView(); }); - afterEach(function() { - Marionette.CollectionView.restore(); - }); - it('calls the parent Marionette.CollectionViews constructor function on instantiation', function() { expect(constructor).to.have.been.called; }); diff --git a/spec/javascripts/controller.spec.js b/spec/javascripts/controller.spec.js index aa041c0b64..56e7fd1f2d 100644 --- a/spec/javascripts/controller.spec.js +++ b/spec/javascripts/controller.spec.js @@ -5,17 +5,20 @@ describe('marionette controller', function() { describe('when creating an controller', function() { - var Controller = Marionette.Controller.extend({ - initialize: sinon.stub() - }); + var Controller; var controller, options, handler; beforeEach(function() { options = {}; + + Controller = Marionette.Controller.extend({ + initialize: this.sinon.stub() + }); + controller = new Controller(options); - handler = sinon.stub(); + handler = this.sinon.stub(); controller.on('foo', handler); controller.trigger('foo', options); @@ -46,11 +49,12 @@ describe('marionette controller', function() { describe('when no options argument is supplied to the constructor', function() { var controller; - var Controller = Marionette.Controller.extend({ - initialize: sinon.stub() - }); + var Controller; beforeEach(function() { + Controller = Marionette.Controller.extend({ + initialize: this.sinon.stub() + }); controller = new Controller(); }); @@ -66,30 +70,26 @@ describe('marionette controller', function() { describe('when destroying a controller', function() { var controller, destroyHandler, listenToHandler; - var Controller = Marionette.Controller.extend({ - onDestroy: sinon.stub() - }); + var Controller; beforeEach(function() { + Controller = Marionette.Controller.extend({ + onDestroy: this.sinon.stub() + }); controller = new Controller(); - destroyHandler = sinon.stub(); + destroyHandler = this.sinon.stub(); controller.on('destroy', destroyHandler); - listenToHandler = sinon.stub(); + listenToHandler = this.sinon.stub(); controller.listenTo(controller, 'destroy', listenToHandler); - sinon.spy(controller, 'stopListening'); - sinon.spy(controller, 'off'); + this.sinon.spy(controller, 'stopListening'); + this.sinon.spy(controller, 'off'); controller.destroy(123, 'second param'); }); - afterEach(function() { - controller.stopListening.restore(); - controller.off.restore(); - }); - it('should stopListening events', function() { expect(controller.stopListening).to.have.been.called; }); diff --git a/spec/javascripts/destroyingViews.spec.js b/spec/javascripts/destroyingViews.spec.js index bde02fd8c7..fccdb5595f 100644 --- a/spec/javascripts/destroyingViews.spec.js +++ b/spec/javascripts/destroyingViews.spec.js @@ -10,7 +10,7 @@ describe('destroying views', function() { beforeEach(function() { view = new View(); - view.onBeforeDestroy = sinon.stub(); + view.onBeforeDestroy = this.sinon.stub(); view.destroy(); view.destroy(); @@ -31,7 +31,7 @@ describe('destroying views', function() { beforeEach(function() { view = new View(); - view.onBeforeDestroy = sinon.stub(); + view.onBeforeDestroy = this.sinon.stub(); view.destroy(); view.destroy(); @@ -54,8 +54,8 @@ describe('destroying views', function() { beforeEach(function() { view = new View(); - view.onBeforeRender = sinon.stub(); - view.onRender = sinon.stub(); + view.onBeforeRender = this.sinon.stub(); + view.onRender = this.sinon.stub(); view.destroy(); }); @@ -71,7 +71,7 @@ describe('destroying views', function() { beforeEach(function() { view = new View(); - view.onBeforeDestroy = sinon.stub(); + view.onBeforeDestroy = this.sinon.stub(); view.destroy(); view.destroy(); @@ -98,8 +98,8 @@ describe('destroying views', function() { beforeEach(function() { view = new CollectionView(); - view.onBeforeRender = sinon.stub(); - view.onRender = sinon.stub(); + view.onBeforeRender = this.sinon.stub(); + view.onRender = this.sinon.stub(); view.destroy(); }); @@ -115,7 +115,7 @@ describe('destroying views', function() { beforeEach(function() { view = new View(); - view.onBeforeDestroy = sinon.stub(); + view.onBeforeDestroy = this.sinon.stub(); view.destroy(); view.destroy(); @@ -144,8 +144,8 @@ describe('destroying views', function() { beforeEach(function() { view = new CompositeView(); - view.onBeforeRender = sinon.stub(); - view.onRender = sinon.stub(); + view.onBeforeRender = this.sinon.stub(); + view.onRender = this.sinon.stub(); view.destroy(); }); diff --git a/spec/javascripts/itemView.spec.js b/spec/javascripts/itemView.spec.js index 010036af18..def748b61e 100644 --- a/spec/javascripts/itemView.spec.js +++ b/spec/javascripts/itemView.spec.js @@ -42,9 +42,9 @@ describe('item view', function() { beforeEach(function() { view = new OnRenderView({}); - sinon.spy(view, 'onBeforeRender'); - sinon.spy(view, 'onRender'); - sinon.spy(view, 'trigger'); + this.sinon.spy(view, 'onBeforeRender'); + this.sinon.spy(view, 'onRender'); + this.sinon.spy(view, 'trigger'); view.render(); }); @@ -85,7 +85,7 @@ describe('item view', function() { }) }); - sinon.spy(view, 'serializeData'); + this.sinon.spy(view, 'serializeData'); view.render(); }); @@ -124,15 +124,11 @@ describe('item view', function() { }) }); - sinon.spy(view, 'serializeData'); + this.sinon.spy(view, 'serializeData'); view.render(); }); - afterEach(function() { - view.serializeData.restore(); - }); - it('should serialize the model', function() { expect(view.serializeData).to.have.been.called; }); @@ -143,22 +139,24 @@ describe('item view', function() { }); describe('when an item view has an asynchronous onRender and is rendered', function() { - var AsyncOnRenderView = Backbone.Marionette.ItemView.extend({ - template: '#emptyTemplate', - asyncCallback: sinon.stub(), - onRender: function() { - var that = this; - var deferred = $.Deferred(); - setTimeout(function() { - deferred.resolve(that.asyncCallback()); - }, 0); - return deferred.promise(); - } - }); + var AsyncOnRenderView; var view, promise; beforeEach(function() { + AsyncOnRenderView = Backbone.Marionette.ItemView.extend({ + template: '#emptyTemplate', + asyncCallback: this.sinon.stub(), + onRender: function() { + var that = this; + var deferred = $.Deferred(); + setTimeout(function() { + deferred.resolve(that.asyncCallback()); + }, 0); + return deferred.promise(); + } + }); + this.loadFixtures('emptyTemplate.html'); view = new AsyncOnRenderView(); promise = view.render(); @@ -183,15 +181,11 @@ describe('item view', function() { collection: new Collection([{foo: 'bar'}, {foo: 'baz'}]) }); - sinon.spy(view, 'serializeData'); + this.sinon.spy(view, 'serializeData'); view.render(); }); - afterEach(function() { - view.serializeData.restore(); - }); - it('should serialize the collection', function() { expect(view.serializeData).to.have.been.called; }); @@ -212,7 +206,7 @@ describe('item view', function() { collection: new Collection([{foo: 'bar'}, {foo: 'baz'}]) }); - sinon.spy(view, 'serializeData'); + this.sinon.spy(view, 'serializeData'); view.render(); }); @@ -257,13 +251,13 @@ describe('item view', function() { }); view.render(); - sinon.spy(view, 'remove'); - sinon.spy(view, 'stopListening'); - sinon.spy(view, 'modelChange'); - sinon.spy(view, 'collectionChange'); - sinon.spy(view, 'onBeforeDestroy'); - sinon.spy(view, 'onDestroy'); - sinon.spy(view, 'trigger'); + this.sinon.spy(view, 'remove'); + this.sinon.spy(view, 'stopListening'); + this.sinon.spy(view, 'modelChange'); + this.sinon.spy(view, 'collectionChange'); + this.sinon.spy(view, 'onBeforeDestroy'); + this.sinon.spy(view, 'onDestroy'); + this.sinon.spy(view, 'trigger'); view.listenTo(model, 'change:foo', view.modelChange); view.listenTo(collection, 'foo', view.collectionChange); @@ -274,16 +268,6 @@ describe('item view', function() { collection.trigger('foo'); }); - afterEach(function() { - view.remove.restore(); - view.stopListening.restore(); - view.modelChange.restore(); - view.collectionChange.restore(); - view.onBeforeDestroy.restore(); - view.onDestroy.restore(); - view.trigger.restore(); - }); - it('should unbind model events for the view', function() { expect(view.modelChange).not.to.have.been.called; }); @@ -352,7 +336,7 @@ describe('item view', function() { model: model }); - spy = sinon.spy(view, 'render'); + spy = this.sinon.spy(view, 'render'); view.setupHandler(); view.render(); @@ -366,10 +350,6 @@ describe('item view', function() { chk.trigger('change'); }); - afterEach(function() { - view.render.restore(); - }); - it('should render the view 3 times total', function() { expect(spy.callCount).to.equal(3); }); @@ -385,7 +365,7 @@ describe('item view', function() { var renderUpdate, view; beforeEach(function() { - renderUpdate = sinon.stub(); + renderUpdate = this.sinon.stub(); view = new View(); $('body').append(view.el); @@ -411,14 +391,10 @@ describe('item view', function() { var constructor, itemView; beforeEach(function() { - constructor = sinon.spy(Marionette, 'View'); + constructor = this.sinon.spy(Marionette, 'View'); itemView = new Marionette.ItemView(); }); - afterEach(function () { - Marionette.View.restore(); - }); - it('calls the parent Marionette.Views constructor function on instantiation', function() { expect(constructor).to.have.been.called; }); diff --git a/spec/javascripts/layoutView.dynamicRegions.spec.js b/spec/javascripts/layoutView.dynamicRegions.spec.js index 55c85a0cf2..55b9b11ba8 100644 --- a/spec/javascripts/layoutView.dynamicRegions.spec.js +++ b/spec/javascripts/layoutView.dynamicRegions.spec.js @@ -20,10 +20,10 @@ describe('layoutView - dynamic regions', function() { template: template }); - beforeAddHandler = sinon.spy(); - addHandler = sinon.spy(); - onBeforeAddSpy = sinon.spy(layoutView, 'onBeforeAddRegion'); - onAddSpy = sinon.spy(layoutView, 'onAddRegion'); + beforeAddHandler = this.sinon.spy(); + addHandler = this.sinon.spy(); + onBeforeAddSpy = this.sinon.spy(layoutView, 'onBeforeAddRegion'); + onAddSpy = this.sinon.spy(layoutView, 'onAddRegion'); layoutView.on('before:add:region', beforeAddHandler); layoutView.on('add:region', addHandler); @@ -35,11 +35,6 @@ describe('layoutView - dynamic regions', function() { layoutView.foo.show(view); }); - afterEach(function() { - layoutView.onBeforeAddRegion.restore(); - layoutView.onAddRegion.restore(); - }); - it('should add the region to the layoutView', function() { expect(layoutView.foo).to.equal(region); }); @@ -176,14 +171,14 @@ describe('layoutView - dynamic regions', function() { onRemoveRegion: function() {} }); - destroyHandler = sinon.spy(); - beforeRemoveHandler = sinon.spy(); - removeHandler = sinon.spy(); + destroyHandler = this.sinon.spy(); + beforeRemoveHandler = this.sinon.spy(); + removeHandler = this.sinon.spy(); layoutView = new LayoutView(); - onBeforeRemoveSpy = sinon.spy(layoutView, 'onBeforeRemoveRegion'); - onRemoveSpy = sinon.spy(layoutView, 'onRemoveRegion'); + onBeforeRemoveSpy = this.sinon.spy(layoutView, 'onBeforeRemoveRegion'); + onRemoveSpy = this.sinon.spy(layoutView, 'onRemoveRegion'); layoutView.render(); layoutView.foo.show(new Backbone.View()); @@ -196,11 +191,6 @@ describe('layoutView - dynamic regions', function() { layoutView.removeRegion('foo'); }); - afterEach(function() { - layoutView.onBeforeRemoveRegion.restore(); - layoutView.onRemoveRegion.restore(); - }); - it('should destroy the region', function() { expect(destroyHandler).to.have.been.called; }); @@ -254,7 +244,7 @@ describe('layoutView - dynamic regions', function() { var layoutView, region, destroyHandler; beforeEach(function() { - destroyHandler = sinon.stub(); + destroyHandler = this.sinon.stub(); layoutView = new Marionette.LayoutView({ template: template }); diff --git a/spec/javascripts/layoutView.spec.js b/spec/javascripts/layoutView.spec.js index bbd78e52d6..898be6a75c 100644 --- a/spec/javascripts/layoutView.spec.js +++ b/spec/javascripts/layoutView.spec.js @@ -173,17 +173,12 @@ describe('layoutView', function() { regionOne = layoutViewManager.regionOne; regionTwo = layoutViewManager.regionTwo; - sinon.spy(regionOne, 'destroy'); - sinon.spy(regionTwo, 'destroy'); + this.sinon.spy(regionOne, 'destroy'); + this.sinon.spy(regionTwo, 'destroy'); layoutViewManager.destroy(); }); - afterEach(function() { - regionOne.destroy.restore(); - regionTwo.destroy.restore(); - }); - it('should destroy the region managers', function() { expect(regionOne.destroy).to.have.been.called; expect(regionTwo.destroy).to.have.been.called; @@ -243,17 +238,13 @@ describe('layoutView', function() { view.destroy = function() {}; layoutView.regionOne.show(view); - destroyRegionsSpy = sinon.spy(layoutView.regionManager, 'destroyRegions'); + destroyRegionsSpy = this.sinon.spy(layoutView.regionManager, 'destroyRegions'); layoutView.render(); layoutView.regionOne.show(view); region = layoutView.regionOne; }); - afterEach(function() { - layoutView.regionManager.destroyRegions.restore(); - }); - it('should destroy the regions', function() { expect(destroyRegionsSpy.callCount).to.equal(1); }); @@ -293,16 +284,11 @@ describe('layoutView', function() { layoutView.regionOne.show(view); layoutView.destroy(); - sinon.spy(region, 'destroy'); - sinon.spy(view, 'destroy'); + this.sinon.spy(region, 'destroy'); + this.sinon.spy(view, 'destroy'); - layoutView.onBeforeRender = sinon.stub(); - layoutView.onRender = sinon.stub(); - }); - - afterEach(function() { - region.destroy.restore(); - view.destroy.restore(); + layoutView.onBeforeRender = this.sinon.stub(); + layoutView.onRender = this.sinon.stub(); }); it('should throw an error', function() { @@ -314,14 +300,10 @@ describe('layoutView', function() { var constructor, layoutView; beforeEach(function() { - constructor = sinon.spy(Marionette, 'View'); + constructor = this.sinon.spy(Marionette, 'View'); layoutView = new Marionette.LayoutView(); }); - afterEach(function () { - Marionette.View.restore(); - }); - it('calls the parent Marionette.Views constructor function on instantiation', function() { expect(constructor).to.have.been.called; }); @@ -342,7 +324,7 @@ describe('layoutView', function() { var layoutView, CustomRegion, layoutView2; beforeEach(function() { - CustomRegion = sinon.spy(); + CustomRegion = this.sinon.spy(); var regionOptions = { war: '.craft', is: { @@ -383,7 +365,7 @@ describe('layoutView', function() { var spy, layout; beforeEach(function() { - spy = sinon.spy(); + spy = this.sinon.spy(); layout = new (Marionette.LayoutView.extend({ getRegionManager: function() { spy.apply(this, arguments); @@ -405,8 +387,8 @@ describe('layoutView', function() { describe('childView get onDomRefresh from parent', function() { beforeEach(function() { this.setFixtures('
'); - this.spy = sinon.spy(); - this.spy2 = sinon.spy(); + this.spy = this.sinon.spy(); + this.spy2 = this.sinon.spy(); var ItemView = Marionette.ItemView.extend({ template: _.template(''), diff --git a/spec/javascripts/module.spec.js b/spec/javascripts/module.spec.js index 89ff139ec8..8f745bee95 100644 --- a/spec/javascripts/module.spec.js +++ b/spec/javascripts/module.spec.js @@ -17,8 +17,8 @@ describe('application modules', function() { beforeEach(function() { app = new Backbone.Marionette.Application(); - initializeSpy = sinon.stub(); - defineSpy = sinon.stub(); + initializeSpy = this.sinon.stub(); + defineSpy = this.sinon.stub(); }); describe('and no params are passed in', function() { @@ -125,7 +125,7 @@ describe('application modules', function() { var initializeOptionSpy; beforeEach(function() { - initializeOptionSpy = sinon.stub(); + initializeOptionSpy = this.sinon.stub(); var ModuleClass = Backbone.Marionette.Module.extend({ initialize: initializeSpy, @@ -244,8 +244,8 @@ describe('application modules', function() { var module, aSpy, bSpy; beforeEach(function() { - aSpy = sinon.spy(); - bSpy = sinon.spy(); + aSpy = this.sinon.spy(); + bSpy = this.sinon.spy(); module = app.module('Mod', { propA: 'module property a', @@ -286,8 +286,8 @@ describe('application modules', function() { var parentDefineSpy, childDefineSpy; beforeEach(function() { - parentDefineSpy = sinon.stub(); - childDefineSpy = sinon.stub(); + parentDefineSpy = this.sinon.stub(); + childDefineSpy = this.sinon.stub(); parent = app.module('parent', parentDefineSpy); child = app.module('parent.child', childDefineSpy); @@ -313,7 +313,7 @@ describe('application modules', function() { describe('and the parent is not already created', function() { var defineSpy; beforeEach(function() { - defineSpy = sinon.stub(); + defineSpy = this.sinon.stub(); child = app.module('parent.child', defineSpy); }); @@ -336,10 +336,10 @@ describe('application modules', function() { describe('when starting a module', function() { var module, startSpy, beforeStartSpy, initializeSpy1, initializeSpy2; beforeEach(function() { - startSpy = sinon.stub(); - beforeStartSpy = sinon.stub(); - initializeSpy1 = sinon.stub(); - initializeSpy2 = sinon.stub(); + startSpy = this.sinon.stub(); + beforeStartSpy = this.sinon.stub(); + initializeSpy1 = this.sinon.stub(); + initializeSpy2 = this.sinon.stub(); module = app.module('Mod'); module.on('before:start', beforeStartSpy); @@ -373,7 +373,7 @@ describe('application modules', function() { beforeEach(function() { var module = app.module('Mod'); - startSpy = sinon.spy(); + startSpy = this.sinon.spy(); module.on('before:start', startSpy); module.start(); module.start(); @@ -393,16 +393,11 @@ describe('application modules', function() { parent = app.module('Parent'); child = app.module('Parent.Child'); - childStartSpy = sinon.spy(child, 'start'); - parentStartSpy = sinon.spy(parent, 'start'); + childStartSpy = this.sinon.spy(child, 'start'); + parentStartSpy = this.sinon.spy(parent, 'start'); parent.start(); }); - afterEach(function() { - child.start.restore(); - parent.start.restore(); - }); - it('parent is started', function() { expect(parentStartSpy).to.have.been.called; }); @@ -417,14 +412,10 @@ describe('application modules', function() { parent = app.module('Parent', {startWithParent: false}); child = app.module('Parent.Child', {startWithParent: false}); - childStartSpy = sinon.spy(child, 'start'); + childStartSpy = this.sinon.spy(child, 'start'); parent.start(); }); - afterEach(function() { - child.start.restore(); - }); - it('the parent is started', function() { expect(parentStartSpy).to.have.been.called; }); @@ -442,7 +433,7 @@ describe('application modules', function() { describe('', function() { beforeEach(function() { var module = app.module('Mod'); - startSpy = sinon.spy(module, 'start'); + startSpy = this.sinon.spy(module, 'start'); app.start(); }); @@ -454,7 +445,7 @@ describe('application modules', function() { describe('and its module is set to not start with parent', function() { beforeEach(function() { var module = app.module('Mod', {startWithParent: false}); - startSpy = sinon.spy(module, 'start'); + startSpy = this.sinon.spy(module, 'start'); app.start(); }); @@ -470,7 +461,7 @@ describe('application modules', function() { beforeEach(function() { app.start(); - initializeSpy = sinon.stub(); + initializeSpy = this.sinon.stub(); module = app.module('Mod'); module.addInitializer(initializeSpy); @@ -493,9 +484,9 @@ describe('application modules', function() { var module, beforeStopSpy, stopSpy, finalizerSpy; beforeEach(function() { - beforeStopSpy = sinon.spy(); - stopSpy = sinon.spy(); - finalizerSpy = sinon.spy(); + beforeStopSpy = this.sinon.spy(); + stopSpy = this.sinon.spy(); + finalizerSpy = this.sinon.spy(); module = app.module('Mod'); module.addFinalizer(finalizerSpy); @@ -523,16 +514,16 @@ describe('application modules', function() { var module, child, beforeStopSpy, stopSpy, finalizerSpy; beforeEach(function() { - beforeStopSpy = sinon.spy(); - stopSpy = sinon.spy(); - finalizerSpy = sinon.spy(); + beforeStopSpy = this.sinon.spy(); + stopSpy = this.sinon.spy(); + finalizerSpy = this.sinon.spy(); module = app.module('Mod'); child = app.module('Mod.Child'); child.addFinalizer(finalizerSpy); child.on('before:stop', beforeStopSpy); child.on('stop', stopSpy); - sinon.spy(child, 'stop'); + this.sinon.spy(child, 'stop'); module.start(); module.stop(); @@ -560,10 +551,10 @@ describe('application modules', function() { var parent, child, parentFinalizerSpy, childFinalizerSpy, parentStopSpy, childStopSpy; beforeEach(function() { - parentFinalizerSpy = sinon.spy(); - childFinalizerSpy = sinon.spy(); - parentStopSpy = sinon.spy(); - childStopSpy = sinon.spy(); + parentFinalizerSpy = this.sinon.spy(); + childFinalizerSpy = this.sinon.spy(); + parentStopSpy = this.sinon.spy(); + childStopSpy = this.sinon.spy(); parent = app.module('Parent'); child = app.module('Child'); diff --git a/spec/javascripts/module.stop.spec.js b/spec/javascripts/module.stop.spec.js index 9923e9278e..ec7f0e39ea 100644 --- a/spec/javascripts/module.stop.spec.js +++ b/spec/javascripts/module.stop.spec.js @@ -14,9 +14,9 @@ describe('module stop', function() { var mod1, mod2, mod3, beforeStop, stop, finalizerSpy; beforeEach(function() { - beforeStop = sinon.stub(); - stop = sinon.stub(); - finalizerSpy = sinon.spy(); + beforeStop = this.sinon.stub(); + stop = this.sinon.stub(); + finalizerSpy = this.sinon.spy(); mod1 = App.module('Mod1', function(Mod1) { Mod1.addFinalizer(finalizerSpy); @@ -28,18 +28,13 @@ describe('module stop', function() { mod2 = App.module('Mod1.Mod2'); mod3 = App.module('Mod1.Mod3'); - sinon.spy(mod2, 'stop'); - sinon.spy(mod3, 'stop'); + this.sinon.spy(mod2, 'stop'); + this.sinon.spy(mod3, 'stop'); mod1.start(); mod1.stop(); }); - afterEach(function() { - mod2.stop.restore(); - mod3.stop.restore(); - }); - it('should trigger a "before:stop" event', function() { expect(beforeStop).to.have.been.called; }); @@ -71,7 +66,7 @@ describe('module stop', function() { var mod1, mod2, mod3, finalizerSpy; beforeEach(function() { - finalizerSpy = sinon.spy(); + finalizerSpy = this.sinon.spy(); mod1 = App.module('Mod1', function(Mod1) { Mod1.addFinalizer(finalizerSpy); }); @@ -79,18 +74,13 @@ describe('module stop', function() { mod2 = App.module('Mod1.Mod2'); mod3 = App.module('Mod1.Mod3'); - sinon.spy(mod2, 'stop'); - sinon.spy(mod3, 'stop'); + this.sinon.spy(mod2, 'stop'); + this.sinon.spy(mod3, 'stop'); // this module has not been started mod1.stop(); }); - afterEach(function() { - mod2.stop.restore(); - mod3.stop.restore(); - }); - it('should not run any finalizers', function() { expect(finalizerSpy).not.to.have.been.called; }); @@ -108,7 +98,7 @@ describe('module stop', function() { var MyApp = new Marionette.Application(); var module = MyApp.module('MyModule'); - finalizer = sinon.stub(); + finalizer = this.sinon.stub(); module.addFinalizer(finalizer); MyApp.start(); diff --git a/spec/javascripts/onDomRefresh.spec.js b/spec/javascripts/onDomRefresh.spec.js index 95695d2c6a..e1ff029018 100644 --- a/spec/javascripts/onDomRefresh.spec.js +++ b/spec/javascripts/onDomRefresh.spec.js @@ -10,7 +10,7 @@ describe('onDomRefresh', function() { }); beforeEach(function() { - sinon.spy(View.prototype, 'onDomRefresh'); + this.sinon.spy(View.prototype, 'onDomRefresh'); view = new View(); view.trigger('show'); view.trigger('render'); @@ -18,7 +18,6 @@ describe('onDomRefresh', function() { afterEach(function() { view.remove(); - View.prototype.onDomRefresh.restore(); }); describe('when the view is not in the DOM', function() { diff --git a/spec/javascripts/region.spec.js b/spec/javascripts/region.spec.js index 1774ebb5dd..e1b02cc479 100644 --- a/spec/javascripts/region.spec.js +++ b/spec/javascripts/region.spec.js @@ -105,19 +105,19 @@ describe('region', function() { beforeEach(function() { this.setFixtures('
'); - showSpy = sinon.spy(); - regionBeforeShowSpy = sinon.spy(); - regionBeforeSwapSpy = sinon.spy(); - regionSwapSpy = sinon.spy(); - viewBeforeShowSpy = sinon.spy(); + showSpy = this.sinon.spy(); + regionBeforeShowSpy = this.sinon.spy(); + regionBeforeSwapSpy = this.sinon.spy(); + regionSwapSpy = this.sinon.spy(); + viewBeforeShowSpy = this.sinon.spy(); view = new MyView(); - sinon.spy(view, 'render'); + this.sinon.spy(view, 'render'); myRegion = new MyRegion(); - sinon.spy(myRegion, 'onShow'); - setHtmlSpy = sinon.spy(myRegion, 'setHtml'); - swapSpy = sinon.spy(myRegion, 'onSwap'); + this.sinon.spy(myRegion, 'onShow'); + setHtmlSpy = this.sinon.spy(myRegion, 'setHtml'); + swapSpy = this.sinon.spy(myRegion, 'onSwap'); myRegion.on('show', showSpy); myRegion.on('before:show', regionBeforeShowSpy); @@ -129,13 +129,6 @@ describe('region', function() { myRegion.show(view); }); - afterEach(function() { - view.render.restore(); - myRegion.onShow.restore(); - myRegion.setHtml.restore(); - myRegion.onSwap.restore(); - }); - it('should render the view', function() { expect(view.render).to.have.been.called; }); @@ -245,15 +238,11 @@ describe('region', function() { view2 = new MyView2(); myRegion = new MyRegion(); - sinon.spy(view1, 'destroy'); + this.sinon.spy(view1, 'destroy'); myRegion.show(view1); }); - afterEach(function() { - view1.destroy.restore(); - }); - describe('preventDestroy: true', function() { beforeEach(function() { myRegion.show(view2, {preventDestroy: true}); @@ -303,31 +292,29 @@ describe('region', function() { } }); - SubView = Backbone.Marionette.ItemView.extend({ - render: function() { - $(this.el).html('some content'); - }, + beforeEach(function() { + var self = this; - initialize: function() { - innerRegionBeforeShowSpy = sinon.spy(); - innerRegionShowSpy = sinon.spy(); - this.on('before:show', innerRegionBeforeShowSpy); - this.on('show', innerRegionShowSpy); - } - }); + SubView = Backbone.Marionette.ItemView.extend({ + render: function() { + $(this.el).html('some content'); + }, + + initialize: function() { + innerRegionBeforeShowSpy = self.sinon.spy(); + innerRegionShowSpy = self.sinon.spy(); + this.on('before:show', innerRegionBeforeShowSpy); + this.on('show', innerRegionShowSpy); + } + }); - beforeEach(function() { this.setFixtures('
'); region = new MyRegion(); - setHtmlSpy = sinon.spy(region, 'setHtml'); + setHtmlSpy = this.sinon.spy(region, 'setHtml'); region.show(new LayoutView()); }); - afterEach(function() { - region.setHtml.restore(); - }); - - it('should call inner region before:show before region setHtml', function() { + it('should call inner region before:show before region open', function() { expect(innerRegionBeforeShowSpy.calledBefore(setHtmlSpy)).to.be.true; }); @@ -362,16 +349,12 @@ describe('region', function() { view2 = new MyView(); myRegion = new MyRegion(); - sinon.spy(view1, 'destroy'); + this.sinon.spy(view1, 'destroy'); myRegion.show(view1); myRegion.show(view2); }); - afterEach(function() { - view1.destroy.restore(); - }); - it('should call "destroy" on the already open view', function() { expect(view1.destroy).to.have.been.called; }); @@ -404,18 +387,12 @@ describe('region', function() { myRegion = new MyRegion(); myRegion.show(view); - sinon.spy(view, 'destroy'); - sinon.spy(myRegion, 'setHtml'); - sinon.spy(view, 'render'); + this.sinon.spy(view, 'destroy'); + this.sinon.spy(myRegion, 'setHtml'); + this.sinon.spy(view, 'render'); myRegion.show(view); }); - afterEach(function() { - view.destroy.restore(); - myRegion.setHtml.restore(); - view.render.restore(); - }); - it('should not call "destroy" on the view', function() { expect(view.destroy).not.to.have.been.called; }); @@ -452,18 +429,12 @@ describe('region', function() { myRegion = new MyRegion(); myRegion.show(view); - sinon.spy(view, 'destroy'); - sinon.spy(myRegion, 'setHtml'); - sinon.spy(view, 'render'); + this.sinon.spy(view, 'destroy'); + this.sinon.spy(myRegion, 'setHtml'); + this.sinon.spy(view, 'render'); myRegion.show(view, {forceShow: true}); }); - afterEach(function() { - view.destroy.restore(); - myRegion.setHtml.restore(); - view.render.restore(); - }); - it('should not call "destroy" on the view', function() { expect(view.destroy).not.to.have.been.called; }); @@ -497,15 +468,9 @@ describe('region', function() { myRegion.show(view); view.destroy(); - sinon.spy(view, 'destroy'); - sinon.spy(myRegion, 'setHtml'); - sinon.spy(view, 'render'); - }); - - afterEach(function() { - view.destroy.restore(); - myRegion.setHtml.restore(); - view.render.restore(); + this.sinon.spy(view, 'destroy'); + this.sinon.spy(myRegion, 'setHtml'); + this.sinon.spy(view, 'render'); }); it('should not throw an error saying the views been destroyed if a destroyed view is passed in', function() { @@ -535,11 +500,7 @@ describe('region', function() { view2 = new MyView(); myRegion = new MyRegion(); - sinon.spy(view1, 'destroy'); - }); - - afterEach(function() { - view1.destroy.restore(); + this.sinon.spy(view1, 'destroy'); }); it('shouldnt call "destroy" on an already destroyed view', function() { @@ -568,13 +529,13 @@ describe('region', function() { beforeEach(function() { this.setFixtures('
'); - beforeDestroySpy = sinon.spy(); - destroyedSpy = sinon.spy(); + beforeDestroySpy = this.sinon.spy(); + destroyedSpy = this.sinon.spy(); view = new MyView(); - sinon.spy(view, 'destroy'); - sinon.spy(view, 'remove'); + this.sinon.spy(view, 'destroy'); + this.sinon.spy(view, 'remove'); myRegion = new MyRegion(); myRegion.on('before:destroy', beforeDestroySpy); @@ -584,11 +545,6 @@ describe('region', function() { myRegion.destroy(); }); - afterEach(function() { - view.destroy.restore(); - view.remove.restore(); - }); - it('should trigger a "before:destroy" event with the view thats being destroyed', function() { expect(beforeDestroySpy).to.have.been.calledWith(view); }); @@ -637,16 +593,12 @@ describe('region', function() { beforeEach(function() { view = new MyView(); - sinon.spy(view, 'remove'); + this.sinon.spy(view, 'remove'); myRegion = new MyRegion(); myRegion.show(view); myRegion.destroy(); }); - afterEach(function() { - view.remove.restore(); - }); - it('should call "remove" on the view', function() { expect(view.remove).to.have.been.called; }); @@ -678,8 +630,8 @@ describe('region', function() { view = new View(); - sinon.spy(view, 'render'); - sinon.spy(view, 'onShow'); + this.sinon.spy(view, 'render'); + this.sinon.spy(view, 'onShow'); region = new Backbone.Marionette.Region({ el: '#foo', @@ -687,11 +639,6 @@ describe('region', function() { }); }); - afterEach(function() { - view.render.restore(); - view.onShow.restore(); - }); - it('should not render the view', function() { expect(view.render).not.to.have.been.called; }); @@ -713,8 +660,8 @@ describe('region', function() { view = new View(); - sinon.spy(view, 'render'); - sinon.spy(view, 'onShow'); + this.sinon.spy(view, 'render'); + this.sinon.spy(view, 'onShow'); region = new Backbone.Marionette.Region({ el: '#foo' @@ -723,11 +670,6 @@ describe('region', function() { region.attachView(view); }); - afterEach(function() { - view.render.restore(); - view.onShow.restore(); - }); - it('should not render the view', function() { expect(view.render).not.to.have.been.called; }); @@ -751,17 +693,13 @@ describe('region', function() { initialize: function() {} }); - sinon.spy(Region.prototype, 'initialize'); + this.sinon.spy(Region.prototype, 'initialize'); region = new Region({ foo: 'bar' }); }); - afterEach(function() { - Region.prototype.initialize.restore(); - }); - it('should call the initialize method with the options from the constructor', function() { expect(Region.prototype.initialize).to.have.been.calledWith(expectedOptions); }); @@ -780,15 +718,11 @@ describe('region', function() { }); region = MyApp.MyRegion; - sinon.spy(region, 'destroy'); + this.sinon.spy(region, 'destroy'); MyApp.removeRegion('MyRegion'); }); - afterEach(function() { - region.destroy.restore(); - }); - it('should be removed from the app', function() { expect(MyApp.MyRegion).to.be.undefined; }); @@ -824,17 +758,13 @@ describe('region', function() { el: '#region' }); - sinon.spy(region, 'destroy'); + this.sinon.spy(region, 'destroy'); region._ensureElement(); region.reset(); }); - afterEach(function() { - region.destroy.restore(); - }); - it('should not hold on to the regions previous "el"', function() { expect(region.$el).not.to.exist; }); diff --git a/spec/javascripts/regionManager.spec.js b/spec/javascripts/regionManager.spec.js index 39f937c2e9..02cda8e669 100644 --- a/spec/javascripts/regionManager.spec.js +++ b/spec/javascripts/regionManager.spec.js @@ -9,8 +9,8 @@ describe('regionManager', function() { var region, regionManager, addHandler, beforeAddHandler; beforeEach(function() { - addHandler = sinon.spy(); - beforeAddHandler = sinon.spy(); + addHandler = this.sinon.spy(); + beforeAddHandler = this.sinon.spy(); regionManager = new Marionette.RegionManager(); regionManager.on('add:region', addHandler); @@ -44,8 +44,8 @@ describe('regionManager', function() { var region, builtRegion, regionManager, addHandler, beforeAddHandler; beforeEach(function() { - addHandler = sinon.spy(); - beforeAddHandler = sinon.spy(); + addHandler = this.sinon.spy(); + beforeAddHandler = this.sinon.spy(); regionManager = new Marionette.RegionManager(); regionManager.on('add:region', addHandler); @@ -100,7 +100,7 @@ describe('regionManager', function() { beforeEach(function() { context = $('
'); - parentElHandler = sinon.stub().returns(context); + parentElHandler = this.sinon.stub().returns(context); regionManager = new Marionette.RegionManager(); region = regionManager.addRegion('foo', { selector: '#foo', @@ -193,9 +193,9 @@ describe('regionManager', function() { beforeEach(function() { this.setFixtures('
'); - destroyHandler = sinon.spy(); - beforeRemoveHandler = sinon.spy(); - removeHandler = sinon.spy(); + destroyHandler = this.sinon.spy(); + beforeRemoveHandler = this.sinon.spy(); + removeHandler = this.sinon.spy(); regionManager = new Marionette.RegionManager(); region = regionManager.addRegion('foo', '#foo'); @@ -205,15 +205,11 @@ describe('regionManager', function() { regionManager.on('before:remove:region', beforeRemoveHandler); regionManager.on('remove:region', removeHandler); - sinon.spy(region, 'stopListening'); + this.sinon.spy(region, 'stopListening'); regionManager.removeRegion('foo'); }); - afterEach(function() { - region.stopListening.restore(); - }); - it('should destroy the region', function() { expect(destroyHandler).to.have.been.called; }); @@ -245,9 +241,9 @@ describe('regionManager', function() { beforeEach(function() { this.setFixtures('
'); - destroyHandler = sinon.stub(); - destroyHandler2 = sinon.stub(); - removeHandler = sinon.stub(); + destroyHandler = this.sinon.stub(); + destroyHandler2 = this.sinon.stub(); + removeHandler = this.sinon.stub(); regionManager = new Marionette.RegionManager(); region = regionManager.addRegion('foo', '#foo'); @@ -261,17 +257,12 @@ describe('regionManager', function() { regionManager.on('remove:region', removeHandler); - sinon.spy(region, 'stopListening'); - sinon.spy(r2, 'stopListening'); + this.sinon.spy(region, 'stopListening'); + this.sinon.spy(r2, 'stopListening'); regionManager.removeRegions(); }); - afterEach(function() { - region.stopListening.restore(); - r2.stopListening.restore(); - }); - it('should destroy the regions', function() { expect(destroyHandler).to.have.been.called; expect(destroyHandler2).to.have.been.called; @@ -299,8 +290,8 @@ describe('regionManager', function() { beforeEach(function() { this.setFixtures('
'); - destroyHandler = sinon.stub(); - destroyManagerHandler = sinon.stub(); + destroyHandler = this.sinon.stub(); + destroyManagerHandler = this.sinon.stub(); regionManager = new Marionette.RegionManager(); region = regionManager.addRegion('foo', '#foo'); @@ -325,8 +316,8 @@ describe('regionManager', function() { beforeEach(function() { this.setFixtures('
'); - destroyHandler = sinon.stub(); - destroyManagerHandler = sinon.stub(); + destroyHandler = this.sinon.stub(); + destroyManagerHandler = this.sinon.stub(); regionManager = new Marionette.RegionManager(); region = regionManager.addRegion('foo', '#foo'); @@ -335,15 +326,11 @@ describe('regionManager', function() { region.on('destroy', destroyHandler); regionManager.on('destroy', destroyManagerHandler); - sinon.spy(region, 'stopListening'); + this.sinon.spy(region, 'stopListening'); regionManager.destroy(); }); - afterEach(function() { - region.stopListening.restore(); - }); - it('should destroy all regions', function() { expect(destroyHandler).to.have.been.called; }); @@ -365,7 +352,7 @@ describe('regionManager', function() { var cb, r1, r2, r3; beforeEach(function() { - cb = sinon.stub(); + cb = this.sinon.stub(); var rm = new Marionette.RegionManager(); diff --git a/spec/javascripts/renderer.spec.js b/spec/javascripts/renderer.spec.js index adf4cf1bb8..4730ae8998 100644 --- a/spec/javascripts/renderer.spec.js +++ b/spec/javascripts/renderer.spec.js @@ -10,15 +10,11 @@ describe('renderer', function() { beforeEach(function() { this.loadFixtures('rendererTemplate.html'); - sinon.spy(Backbone.Marionette.TemplateCache, 'get'); + this.sinon.spy(Backbone.Marionette.TemplateCache, 'get'); var html = Backbone.Marionette.Renderer.render(templateSelector).trim(); result = $(html); }); - afterEach(function() { - Backbone.Marionette.TemplateCache.get.restore(); - }); - it('should retrieve the template from the cache', function() { expect(Backbone.Marionette.TemplateCache.get).to.have.been.calledWith(templateSelector); }); @@ -34,17 +30,13 @@ describe('renderer', function() { beforeEach(function() { this.loadFixtures('rendererWithDataTemplate.html'); - sinon.spy(Backbone.Marionette.TemplateCache, 'get'); + this.sinon.spy(Backbone.Marionette.TemplateCache, 'get'); var data = {foo: 'bar'}; var html = Backbone.Marionette.Renderer.render(templateSelector, data).trim(); result = $(html); }); - afterEach(function() { - Backbone.Marionette.TemplateCache.get.restore(); - }); - it('should retrieve the template from the cache', function() { expect(Backbone.Marionette.TemplateCache.get).to.have.been.calledWith(templateSelector); }); diff --git a/spec/javascripts/sortedViews.spec.js b/spec/javascripts/sortedViews.spec.js index fe225ca967..31c72832cb 100644 --- a/spec/javascripts/sortedViews.spec.js +++ b/spec/javascripts/sortedViews.spec.js @@ -140,14 +140,10 @@ describe('collection/composite view sorting', function(){ describe('and then adding another', function(){ beforeEach(function(){ model = new Backbone.Model({foo: 'bbar'}); - sinon.spy(collectionView, 'render'); + this.sinon.spy(collectionView, 'render'); collection.add(model); }); - afterEach(function() { - collectionView.render.restore(); - }); - it('should have the order in the dom', function(){ expect(getCollectionChildren(collectionView.$el)).to.equal('abar,bbar,wbar'); expect(getCollectionChildren(compositeView.$el)).to.equal('abar,bbar,wbar'); diff --git a/spec/javascripts/templateCache.spec.js b/spec/javascripts/templateCache.spec.js index 7c5b1dec7d..ea82118c80 100644 --- a/spec/javascripts/templateCache.spec.js +++ b/spec/javascripts/templateCache.spec.js @@ -8,15 +8,11 @@ describe('template cache', function() { beforeEach(function() { this.setFixtures(''); - sinon.spy(Backbone.Marionette.TemplateCache.prototype, 'loadTemplate'); + this.sinon.spy(Backbone.Marionette.TemplateCache.prototype, 'loadTemplate'); Backbone.Marionette.TemplateCache.get('#t1'); }); - afterEach(function() { - Backbone.Marionette.TemplateCache.prototype.loadTemplate.restore(); - }); - it('should load from the DOM', function() { expect(Backbone.Marionette.TemplateCache.prototype.loadTemplate).to.have.been.called; }); @@ -32,16 +28,12 @@ describe('template cache', function() { Backbone.Marionette.TemplateCache.get('#t2'); templateCache = Backbone.Marionette.TemplateCache.templateCaches['#t2']; - sinon.spy(templateCache, 'loadTemplate'); + this.sinon.spy(templateCache, 'loadTemplate'); Backbone.Marionette.TemplateCache.get('#t2'); Backbone.Marionette.TemplateCache.get('#t2'); }); - afterEach(function() { - templateCache.loadTemplate.restore(); - }); - it('should load from the DOM once', function() { expect(templateCache.loadTemplate).not.to.have.been.called; expect(templateCache.loadTemplate.callCount).to.equal(0); diff --git a/spec/javascripts/templateHelpers.spec.js b/spec/javascripts/templateHelpers.spec.js index a05f242374..e18ffb33b1 100644 --- a/spec/javascripts/templateHelpers.spec.js +++ b/spec/javascripts/templateHelpers.spec.js @@ -93,16 +93,11 @@ describe('template helper methods', function() { beforeEach(function() { var model = new Backbone.Model({bar: 'baz'}); view = new View({model: model}); - sinon.spy(view, 'template'); - sinon.stub(view, 'templateHelpers').returns({foo: function() {}}); + this.sinon.spy(view, 'template'); + this.sinon.stub(view, 'templateHelpers').returns({foo: function() {}}); view.render(); }); - afterEach(function() { - view.template.restore(); - view.templateHelpers.restore(); - }); - it('should include the template helpers in the data object', function() { var firstArg = view.template.args[0][0]; expect(firstArg.foo).to.exist; @@ -135,14 +130,10 @@ describe('template helper methods', function() { } }); - sinon.spy(view, 'template'); + this.sinon.spy(view, 'template'); view.render(); }); - afterEach(function() { - view.template.restore(); - }); - it('should include the template helpers in the data object', function() { var firstArg = view.template.args[0][0]; expect(firstArg.foo).to.exist; diff --git a/spec/javascripts/triggerMethod.spec.js b/spec/javascripts/triggerMethod.spec.js index c021d7e7e8..00f91c3430 100644 --- a/spec/javascripts/triggerMethod.spec.js +++ b/spec/javascripts/triggerMethod.spec.js @@ -13,8 +13,8 @@ describe('trigger event and method name', function() { this.triggerMethod = Marionette.triggerMethod; }; - eventHandler = sinon.stub(); - methodHandler = sinon.stub(); + eventHandler = this.sinon.stub(); + methodHandler = this.sinon.stub(); }); describe('when triggering an event', function() { @@ -153,7 +153,7 @@ describe('trigger event and method name', function() { collection: collection }); - collectionView.onChildviewAddSelection = sinon.stub(); + collectionView.onChildviewAddSelection = this.sinon.stub(); collectionView.render(); diff --git a/spec/javascripts/unbindEntityEvents.spec.js b/spec/javascripts/unbindEntityEvents.spec.js index ee61e045b0..a56e56c9c7 100644 --- a/spec/javascripts/unbindEntityEvents.spec.js +++ b/spec/javascripts/unbindEntityEvents.spec.js @@ -8,12 +8,12 @@ describe('Marionette.unbindEntityEvents', function() { beforeEach(function() { target = { - foo: sinon.spy(), - bar: sinon.spy(), - stopListening: sinon.spy() + foo: this.sinon.spy(), + bar: this.sinon.spy(), + stopListening: this.sinon.spy() }; - entity = sinon.spy(); + entity = this.sinon.spy(); }); describe('when entity isnt passed', function() { @@ -40,7 +40,7 @@ describe('Marionette.unbindEntityEvents', function() { var bindingsSpy; beforeEach(function() { - bindingsSpy = sinon.spy(function() { + bindingsSpy = this.sinon.spy(function() { return {'eventNameMock': 'foo'}; }); @@ -118,13 +118,13 @@ describe('Marionette.unbindEntityEvents', function() { describe('when unbindEntityEvents is proxied', function() { beforeEach(function() { target = { - foo: sinon.spy(), - bar: sinon.spy(), - stopListening: sinon.spy(), + foo: this.sinon.spy(), + bar: this.sinon.spy(), + stopListening: this.sinon.spy(), unbindEntityEvents: Marionette.proxyUnbindEntityEvents }; - entity = sinon.spy(); + entity = this.sinon.spy(); target.unbindEntityEvents(entity, {'eventNameMock': target.foo}); }); diff --git a/spec/javascripts/view.entityEvents.spec.js b/spec/javascripts/view.entityEvents.spec.js index e00bc401f5..fe1e7782d0 100644 --- a/spec/javascripts/view.entityEvents.spec.js +++ b/spec/javascripts/view.entityEvents.spec.js @@ -6,17 +6,19 @@ describe('view entity events', function() { describe('when a view has string-based model and collection event configuration', function() { var view; - var View = Backbone.Marionette.View.extend({ - modelEvents: {'model-event': 'modelEventHandler modelEventHandler2'}, - collectionEvents: {'collection-event': 'collectionEventHandler collectionEventHandler2'}, - - modelEventHandler: sinon.stub(), - collectionEventHandler: sinon.stub(), - modelEventHandler2: sinon.stub(), - collectionEventHandler2: sinon.stub() - }); + var View; beforeEach(function() { + View = Backbone.Marionette.View.extend({ + modelEvents: {'model-event': 'modelEventHandler modelEventHandler2'}, + collectionEvents: {'collection-event': 'collectionEventHandler collectionEventHandler2'}, + + modelEventHandler: this.sinon.stub(), + collectionEventHandler: this.sinon.stub(), + modelEventHandler2: this.sinon.stub(), + collectionEventHandler2: this.sinon.stub() + }); + view = new View({ model: new Backbone.Model(), collection: new Backbone.Collection() @@ -39,17 +41,17 @@ describe('view entity events', function() { describe('when a view has function-based model and collection event configuration', function() { var view; - - var View = Backbone.Marionette.View.extend({ - modelEvents: { - 'model-event': sinon.stub() - }, - collectionEvents: { - 'collection-event': sinon.stub() - } - }); + var View; beforeEach(function() { + View = Backbone.Marionette.View.extend({ + modelEvents: { + 'model-event': this.sinon.stub() + }, + collectionEvents: { + 'collection-event': this.sinon.stub() + } + }); view = new View({ model: new Backbone.Model(), collection: new Backbone.Collection() @@ -90,8 +92,8 @@ describe('view entity events', function() { var view, modelHandler, collectionHandler; beforeEach(function() { - modelHandler = sinon.stub(); - collectionHandler = sinon.stub(); + modelHandler = this.sinon.stub(); + collectionHandler = this.sinon.stub(); var View = Backbone.Marionette.View.extend({ modelEvents: function() { @@ -124,8 +126,8 @@ describe('view entity events', function() { var view, modelHandler, collectionHandler; beforeEach(function() { - modelHandler = sinon.stub(); - collectionHandler = sinon.stub(); + modelHandler = this.sinon.stub(); + collectionHandler = this.sinon.stub(); var View = Marionette.View.extend({ modelEvents: { @@ -167,8 +169,8 @@ describe('view entity events', function() { var view, modelHandler, collectionHandler; beforeEach(function() { - modelHandler = sinon.stub(); - collectionHandler = sinon.stub(); + modelHandler = this.sinon.stub(); + collectionHandler = this.sinon.stub(); var View = Marionette.View.extend({ modelEvents: { @@ -241,8 +243,8 @@ describe('view entity events', function() { }); beforeEach(function() { - destroySpy = sinon.spy(ChildView.prototype, 'destroy'); - renderSpy = sinon.stub(ChildView.prototype, 'render'); + destroySpy = this.sinon.spy(ChildView.prototype, 'destroy'); + renderSpy = this.sinon.stub(ChildView.prototype, 'render'); var model = new Backbone.Model(); var parent = new ParentView({ @@ -254,11 +256,6 @@ describe('view entity events', function() { model.trigger('sync'); }); - afterEach(function() { - ChildView.prototype.destroy.restore(); - ChildView.prototype.render.restore(); - }); - it('should destroy the previous child view', function() { expect(destroySpy).to.have.been.called; }); diff --git a/spec/javascripts/view.spec.js b/spec/javascripts/view.spec.js index cd7d578500..fc82052cc2 100644 --- a/spec/javascripts/view.spec.js +++ b/spec/javascripts/view.spec.js @@ -8,7 +8,7 @@ describe('base view', function() { var fooHandler, view; beforeEach(function() { - fooHandler = sinon.stub(); + fooHandler = this.sinon.stub(); var View = Backbone.Marionette.View.extend({ initialize: function() { @@ -33,7 +33,7 @@ describe('base view', function() { var destroy; beforeEach(function() { - destroy = sinon.stub(); + destroy = this.sinon.stub(); var view = new Marionette.View(); view.listenTo(view, 'destroy', destroy); @@ -48,25 +48,22 @@ describe('base view', function() { describe('when destroying a view', function() { var destroy, view; - - var View = Marionette.View.extend({ - onDestroy: sinon.stub() - }); + var View; beforeEach(function() { + View = Marionette.View.extend({ + onDestroy: this.sinon.stub() + }); + view = new View(); - sinon.spy(view, 'remove'); - destroy = sinon.stub(); + this.sinon.spy(view, 'remove'); + destroy = this.sinon.stub(); view.on('destroy', destroy); view.destroy(123, 'second param'); }); - afterEach(function() { - view.remove.restore(); - }); - it('should trigger the destroy event', function() { expect(destroy).to.have.been.called; }); @@ -90,8 +87,8 @@ describe('base view', function() { beforeEach(function() { view = new Marionette.View(); - sinon.spy(view, 'remove'); - destroy = sinon.stub(); + this.sinon.spy(view, 'remove'); + destroy = this.sinon.stub(); view.on('destroy', destroy); view.onBeforeDestroy = function() { @@ -101,10 +98,6 @@ describe('base view', function() { view.destroy(); }); - afterEach(function() { - view.remove.restore(); - }); - it('should not trigger the destroy event', function() { expect(destroy).to.have.been.called; }); @@ -124,8 +117,8 @@ describe('base view', function() { beforeEach(function() { view = new Marionette.View(); - sinon.spy(view, 'remove'); - destroy = sinon.stub(); + this.sinon.spy(view, 'remove'); + destroy = this.sinon.stub(); view.on('destroy', destroy); view.onBeforeDestroy = function() { @@ -135,10 +128,6 @@ describe('base view', function() { view.destroy(123, 'second param'); }); - afterEach(function() { - view.remove.restore(); - }); - it('should trigger the destroy event', function() { expect(destroy).to.have.been.calledWith(123, 'second param'); }); @@ -213,17 +202,13 @@ describe('base view', function() { view = new Marionette.View(); view.destroy(); - sinon.spy(view, 'remove'); - destroy = sinon.stub(); + this.sinon.spy(view, 'remove'); + destroy = this.sinon.stub(); view.on('destroy', destroy); view.destroy(); }); - afterEach(function() { - view.remove.restore(); - }); - it('should not trigger the destroy event', function() { expect(destroy).not.to.have.been.called; }); diff --git a/spec/javascripts/view.triggers.spec.js b/spec/javascripts/view.triggers.spec.js index e9c8de871f..99e55db183 100644 --- a/spec/javascripts/view.triggers.spec.js +++ b/spec/javascripts/view.triggers.spec.js @@ -25,8 +25,8 @@ describe('view triggers', function() { }); view.render(); - fooHandler = sinon.stub(); - whatHandler = sinon.stub(); + fooHandler = this.sinon.stub(); + whatHandler = this.sinon.stub(); view.on('do:foo', fooHandler); view.on('what:ever', whatHandler); @@ -85,7 +85,7 @@ describe('view triggers', function() { view = new View(); view.render(); - fooHandler = sinon.stub(); + fooHandler = this.sinon.stub(); view.on('do:foo', fooHandler); view.$('.foo').trigger('click'); @@ -121,8 +121,8 @@ describe('view triggers', function() { view = new View(); view.render(); - fooHandler = sinon.stub(); - whatHandler = sinon.stub(); + fooHandler = this.sinon.stub(); + whatHandler = this.sinon.stub(); view.on('do:foo', fooHandler); view.on('what:ever', whatHandler); @@ -165,7 +165,7 @@ describe('view triggers', function() { beforeEach(function() { viewInstance = new MyView(); - hashChangeSpy = sinon.stub(); + hashChangeSpy = this.sinon.stub(); $(window).on('hashchange', hashChangeSpy); viewInstance.render(); @@ -214,23 +214,16 @@ describe('view triggers', function() { fooEvent = $.Event('click'); barEvent = $.Event('click'); - sinon.spy(fooEvent, 'preventDefault'); - sinon.spy(fooEvent, 'stopPropagation'); + this.sinon.spy(fooEvent, 'preventDefault'); + this.sinon.spy(fooEvent, 'stopPropagation'); - sinon.spy(barEvent, 'preventDefault'); - sinon.spy(barEvent, 'stopPropagation'); + this.sinon.spy(barEvent, 'preventDefault'); + this.sinon.spy(barEvent, 'stopPropagation'); view.$('.foo').trigger(fooEvent); view.$('.bar').trigger(barEvent); }); - afterEach(function() { - fooEvent.preventDefault.restore(); - fooEvent.stopPropagation.restore(); - barEvent.preventDefault.restore(); - barEvent.stopPropagation.restore(); - }); - it('should prevent and dont stop the first view event', function() { expect(fooEvent.preventDefault).to.have.been.called; expect(fooEvent.stopPropagation).not.to.have.been.called; diff --git a/spec/javascripts/view.uiEventAndTriggers.spec.js b/spec/javascripts/view.uiEventAndTriggers.spec.js index d01f162002..1527b9e4b5 100644 --- a/spec/javascripts/view.uiEventAndTriggers.spec.js +++ b/spec/javascripts/view.uiEventAndTriggers.spec.js @@ -86,19 +86,15 @@ describe('view ui event trigger configuration', function() { view2.render(); view3.render(); - fooHandler = sinon.stub(); - attackHandler = sinon.stub(); - defendHandler = sinon.stub(); - tapHandler = sinon.stub(); - sinon.spy(view, 'attack'); + fooHandler = this.sinon.stub(); + attackHandler = this.sinon.stub(); + defendHandler = this.sinon.stub(); + tapHandler = this.sinon.stub(); + this.sinon.spy(view, 'attack'); view.on('do:foo', fooHandler); view2.on('do:foo', fooHandler); }); - afterEach(function () { - view.attack.restore(); - }); - it('should correctly trigger an event', function() { view.$('.foo').trigger('click'); expect(fooHandler).to.have.been.called;