Skip to content

Commit

Permalink
thisify sinon
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebuilds authored and samccone committed Jun 17, 2014
1 parent 1cc02ab commit 1260e41
Show file tree
Hide file tree
Showing 32 changed files with 440 additions and 799 deletions.
86 changes: 47 additions & 39 deletions spec/javascripts/appRouter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -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();

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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();
Expand All @@ -200,7 +207,6 @@ describe('app router', function() {
});

afterEach(function() {
Router.prototype.standardRoute.restore();
Backbone.history.stop();
});

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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: {
Expand Down
17 changes: 6 additions & 11 deletions spec/javascripts/application.appRegions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('application regions', function() {
this.setFixtures('<div id="region"></div>');
this.setFixtures('<div id="region2"></div>');

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);
Expand Down Expand Up @@ -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;
Expand All @@ -167,8 +162,8 @@ describe('application regions', function() {
this.setFixtures('<div id="region"></div>');
this.setFixtures('<div id="region2"></div>');

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);
Expand Down
10 changes: 3 additions & 7 deletions spec/javascripts/application.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
58 changes: 27 additions & 31 deletions spec/javascripts/behaviors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Behaviors', function() {
var Obj, View, Tooltip;

beforeEach(function() {
Tooltip = sinon.spy();
Tooltip = this.sinon.spy();
Obj = {
Tooltip: Tooltip
};
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('Behaviors', function() {
var Obj, View, Tooltip;

beforeEach(function() {
Tooltip = sinon.spy();
Tooltip = this.sinon.spy();
Obj = {
Tooltip: Tooltip
};
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('Behaviors', function() {

beforeEach(function() {
Behavior = Marionette.Behavior.extend({
initialize: sinon.spy()
initialize: this.sinon.spy()
});

Obj = {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit 1260e41

Please sign in to comment.