Remove dep on sinon

This commit is contained in:
Raymond Feng 2015-05-20 09:13:56 -07:00
parent 9705819972
commit cbb8d7c789
3 changed files with 18 additions and 19 deletions

View File

@ -28,8 +28,7 @@
"devDependencies": { "devDependencies": {
"bluebird": "^2.9.9", "bluebird": "^2.9.9",
"mocha": "^2.1.0", "mocha": "^2.1.0",
"should": "^5.0.0", "should": "^5.0.0"
"sinon": "^1.14.1"
}, },
"dependencies": { "dependencies": {
"async": "^0.9.0", "async": "^0.9.0",

View File

@ -1,6 +1,5 @@
// This test written in mocha+should.js // This test written in mocha+should.js
var should = require('./init.js'); var should = require('./init.js');
var sinon = require('sinon');
var async = require('async'); var async = require('async');
var db, User, Profile, AccessToken, Post, Passport, City, Street, Building, Assembly, Part; var db, User, Profile, AccessToken, Post, Passport, City, Street, Building, Assembly, Part;
@ -382,12 +381,19 @@ describe('include', function () {
}); });
}); });
describe(' performance - ', function () { describe('performance', function () {
beforeEach(function () { var all;
this.callSpy = sinon.spy(db.connector, 'all'); beforeEach(function() {
this.called = 0;
var self = this;
all = db.connector.all;
db.connector.all = function(model, filter, options, cb) {
self.called++;
return all.apply(db.connector, arguments);
};
}); });
afterEach(function () { afterEach(function() {
db.connector.all.restore(); db.connector.all = all;
}); });
it('including belongsTo should make only 2 db calls', function (done) { it('including belongsTo should make only 2 db calls', function (done) {
var self = this; var self = this;
@ -407,7 +413,7 @@ describe('include', function () {
owner.id.should.eql(p.ownerId); owner.id.should.eql(p.ownerId);
} }
}); });
self.callSpy.calledTwice.should.be.true; self.called.should.eql(2);
done(); done();
}); });
}); });
@ -434,7 +440,7 @@ describe('include', function () {
}); });
}, next); }, next);
}, function (err) { }, function (err) {
self.callSpy.reset(); self.called = 0;
Assembly.find({ Assembly.find({
where: { where: {
name: { name: {
@ -452,7 +458,7 @@ describe('include', function () {
result[1].parts().should.have.length(2); result[1].parts().should.have.length(2);
//SUV //SUV
result[2].parts().should.have.length(0); result[2].parts().should.have.length(0);
self.callSpy.calledThrice.should.be.true; self.called.should.eql(3);
done(); done();
}); });
}); });
@ -489,7 +495,7 @@ describe('include', function () {
pp.ownerId.should.eql(user.id); pp.ownerId.should.eql(user.id);
}); });
}); });
self.callSpy.calledThrice.should.be.true; self.called.should.eql(3);
done(); done();
}); });
}); });
@ -528,7 +534,7 @@ describe('include', function () {
pp.ownerId.should.eql(user.id); pp.ownerId.should.eql(user.id);
}); });
}); });
self.callSpy.calledThrice.should.be.true; self.called.should.eql(3);
done(); done();
}); });
}); });

View File

@ -6,12 +6,6 @@
} }
*/ */
try {
global.sinon = require('sinon');
} catch (e) {
// ignore
}
var group_name = false, EXT_EXP; var group_name = false, EXT_EXP;
function it(should, test_case) { function it(should, test_case) {
check_external_exports(); check_external_exports();