Comparing version 1.3.2 to 1.3.3
@@ -0,1 +1,4 @@ | ||
== 1.3.3 / 2012-04-14 | ||
* Fix bug with buster-format | ||
== 1.3.2 / 2012-03-11 | ||
@@ -2,0 +5,0 @@ * Stronger Node inference in sandbox |
@@ -122,2 +122,5 @@ /*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/ | ||
deepEqual: function deepEqual(a, b) { | ||
if (sinon.match.isMatcher(a)) { | ||
return a.test(b); | ||
} | ||
if (typeof a != "object" || typeof b != "object") { | ||
@@ -274,2 +277,10 @@ return a === b; | ||
}, 0); | ||
}, | ||
typeOf: function (value) { | ||
if (value === null) { | ||
return "null"; | ||
} | ||
var string = Object.prototype.toString.call(value); | ||
return string.substring(8, string.length - 1).toLowerCase(); | ||
} | ||
@@ -294,2 +305,3 @@ }; | ||
module.exports.assert = require("./sinon/assert"); | ||
module.exports.match = require("./sinon/match"); | ||
} | ||
@@ -296,0 +308,0 @@ |
@@ -109,3 +109,14 @@ /** | ||
} | ||
if (!property && !!object && typeof object == "object") { | ||
var stubbedObj = sinon.stub.apply(sinon, arguments); | ||
for (var prop in stubbedObj) { | ||
if (typeof stubbedObj[prop] === "function") { | ||
this.add(stubbedObj[prop]); | ||
} | ||
} | ||
return stubbedObj; | ||
} | ||
return this.add(sinon.stub.apply(sinon, arguments)); | ||
@@ -112,0 +123,0 @@ }, |
@@ -1,2 +0,5 @@ | ||
/* @depend ../sinon.js */ | ||
/** | ||
* @depend ../sinon.js | ||
* @depend match.js | ||
*/ | ||
/*jslint eqeqeq: false, onevar: false, plusplus: false*/ | ||
@@ -34,3 +37,3 @@ /*global module, require, sinon*/ | ||
if (!object || !property) { | ||
if (!object && !property) { | ||
return spy.create(function () {}); | ||
@@ -393,3 +396,3 @@ } | ||
returned: function returned(value) { | ||
return this.returnValue === value; | ||
return sinon.deepEqual(value, this.returnValue); | ||
}, | ||
@@ -396,0 +399,0 @@ |
@@ -44,3 +44,4 @@ /*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/ | ||
func: args[0], | ||
callAt: this.now + delay | ||
callAt: this.now + delay, | ||
invokeArgs: Array.prototype.slice.call(args, 2) | ||
}; | ||
@@ -179,3 +180,4 @@ | ||
interval: this.timeouts[id].interval, | ||
id: this.timeouts[id].id | ||
id: this.timeouts[id].id, | ||
invokeArgs: this.timeouts[id].invokeArgs | ||
}; | ||
@@ -190,5 +192,11 @@ } | ||
callTimer: function (timer) { | ||
if (typeof timer.interval == "number") { | ||
this.timeouts[timer.id].callAt += timer.interval; | ||
} else { | ||
delete this.timeouts[timer.id]; | ||
} | ||
try { | ||
if (typeof timer.func == "function") { | ||
timer.func.call(null); | ||
timer.func.apply(null, timer.invokeArgs); | ||
} else { | ||
@@ -208,8 +216,2 @@ eval(timer.func); | ||
if (typeof timer.interval == "number") { | ||
this.timeouts[timer.id].callAt += timer.interval; | ||
} else { | ||
delete this.timeouts[timer.id]; | ||
} | ||
if (exception) { | ||
@@ -216,0 +218,0 @@ throw exception; |
{ | ||
"name": "sinon", | ||
"description": "JavaScript test spies, stubs and mocks.", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"homepage": "http://cjohansen.no/sinon/", | ||
@@ -6,0 +6,0 @@ "author": "Christian Johansen", |
/** | ||
* Sinon.JS 1.3.2, 2012/03/11 | ||
* Sinon.JS 1.3.3, 2012/04/14 | ||
* | ||
* @author Christian Johansen (christian@cjohansen.no) | ||
* @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS | ||
* | ||
* (The BSD License) | ||
* | ||
* Copyright (c) 2010-2011, Christian Johansen, christian@cjohansen.no | ||
* Copyright (c) 2010-2012, Christian Johansen, christian@cjohansen.no | ||
* All rights reserved. | ||
@@ -10,0 +11,0 @@ * |
@@ -5,3 +5,3 @@ # Sinon.JS | ||
## Installation | ||
## Installation | ||
@@ -12,3 +12,3 @@ via [npm (node package manager)](http://github.com/isaacs/npm) | ||
or install via git by cloning the repository and including sinon.js | ||
or install via git by cloning the repository and including sinon.js | ||
in your project, as you would any other third party library. | ||
@@ -32,8 +32,28 @@ | ||
## Develop? | ||
## Develop? | ||
Check out [todo.org](http://github.com/cjohansen/Sinon.JS/raw/1.0.0/todo.org) in the project repository | ||
## Running tests on Rhino | ||
## Run the tests | ||
### On Node | ||
$ node test/node/run.js | ||
### In the browser, via JsTestDriver | ||
* Install [Node.js](http://nodejs.org/) & [NPM](http://npmjs.org/) | ||
* `$ npm install buster-format` | ||
* Install Java | ||
* Download [jsTestDriver](http://code.google.com/p/js-test-driver/) | ||
* Start the JsTestDriver server | ||
`$ java -jar JsTestDriver.jar --port 4224` | ||
* Open a browser, go to [http://localhost:4224/](http://localhost:4224) and click 'Capture this Browser' | ||
* run the tests | ||
`$ java -jar JsTestDriver.jar --tests all --reset` | ||
### On Rhino | ||
I've added a rudimentary setup for running the tests on Rhino with env.js (as | ||
@@ -40,0 +60,0 @@ this is a fairly common test setup, Sinon should support it). The files are |
@@ -14,1 +14,2 @@ global.jstestdriver = { console: console }; | ||
require("../sinon/test_case_test.js"); | ||
require("../sinon/match_test.js"); |
@@ -16,2 +16,3 @@ var jstestdriver = {}; | ||
load("lib/sinon/test.js"); | ||
load("lib/sinon/match.js"); | ||
load("lib/sinon/util/fake_server.js"); | ||
@@ -32,2 +33,3 @@ load("lib/sinon/util/fake_server_with_clock.js"); | ||
load("test/sinon/test_test.js"); | ||
load("test/sinon/match_test.js"); | ||
load("test/sinon/util/fake_server_test.js"); | ||
@@ -34,0 +36,0 @@ load("test/sinon/util/fake_server_with_clock_test.js"); |
@@ -408,2 +408,44 @@ /*jslint onevar: false, eqeqeq: false*/ | ||
}); | ||
testCase("TypeOfTest", { | ||
"should return boolean": function () { | ||
assertEquals("boolean", sinon.typeOf(false)); | ||
}, | ||
"should return string": function () { | ||
assertEquals("string", sinon.typeOf("Sinon.JS")); | ||
}, | ||
"should return number": function () { | ||
assertEquals("number", sinon.typeOf(123)); | ||
}, | ||
"should return object": function () { | ||
assertEquals("object", sinon.typeOf({})); | ||
}, | ||
"should return function": function () { | ||
assertEquals("function", sinon.typeOf(function () {})); | ||
}, | ||
"should return undefined": function () { | ||
assertEquals("undefined", sinon.typeOf(undefined)); | ||
}, | ||
"should return null": function () { | ||
assertEquals("null", sinon.typeOf(null)); | ||
}, | ||
"should return array": function () { | ||
assertEquals("array", sinon.typeOf([])); | ||
}, | ||
"should return regexp": function () { | ||
assertEquals("regexp", sinon.typeOf(/.*/)); | ||
}, | ||
"should return date": function () { | ||
assertEquals("date", sinon.typeOf(new Date())); | ||
} | ||
}); | ||
}()); |
@@ -1031,2 +1031,65 @@ /*jslint onevar: false*/ | ||
"assert.calledWith match.any exception message": function () { | ||
this.obj.doSomething(true, true); | ||
assertEquals("expected doSomething to be called with arguments " + | ||
"any, false\n doSomething(true, true)", | ||
this.message("calledWith", this.obj.doSomething, | ||
sinon.match.any, false)); | ||
}, | ||
"assert.calledWith match.same exception message": function () { | ||
this.obj.doSomething(); | ||
assertEquals("expected doSomething to be called with arguments " + | ||
"same(1)\n doSomething()", | ||
this.message("calledWith", this.obj.doSomething, | ||
sinon.match.same(1))); | ||
}, | ||
"assert.calledWith match.typeOf exception message": function () { | ||
this.obj.doSomething(); | ||
assertEquals("expected doSomething to be called with arguments " + | ||
"typeOf(\"string\")\n doSomething()", | ||
this.message("calledWith", this.obj.doSomething, | ||
sinon.match.typeOf("string"))); | ||
}, | ||
"assert.calledWith match.instanceOf exception message": function () { | ||
this.obj.doSomething(); | ||
assertEquals("expected doSomething to be called with arguments " + | ||
"instanceOf(CustomType)\n doSomething()", | ||
this.message("calledWith", this.obj.doSomething, | ||
sinon.match.instanceOf(function CustomType() {}))); | ||
}, | ||
"assert.calledWith match.like object exception message": function () { | ||
this.obj.doSomething(); | ||
assertEquals("expected doSomething to be called with arguments " + | ||
"like(some: value, and: 123)\n doSomething()", | ||
this.message("calledWith", this.obj.doSomething, | ||
sinon.match.like({ some: "value", and: 123 }))); | ||
}, | ||
"assert.calledWith match.like string exception message": function () { | ||
this.obj.doSomething(); | ||
assertEquals("expected doSomething to be called with arguments " + | ||
"like(\"Sinon\")\n doSomething()", | ||
this.message("calledWith", this.obj.doSomething, | ||
sinon.match.like("Sinon"))); | ||
}, | ||
"assert.calledWith match.like regexp exception message": function () { | ||
this.obj.doSomething(); | ||
assertEquals("expected doSomething to be called with arguments " + | ||
"like(/[a-z]+/)\n doSomething()", | ||
this.message("calledWith", this.obj.doSomething, | ||
sinon.match.like(/[a-z]+/))); | ||
}, | ||
"assert.alwaysCalledWith exception message": function () { | ||
@@ -1033,0 +1096,0 @@ this.obj.doSomething(1, 3, "hey"); |
@@ -87,3 +87,38 @@ /*jslint onevar: false, eqeqeq: false, plusplus: false*/ | ||
assertEquals(objects, this.collection.fakes); | ||
}, | ||
"should add all object methods to fake array": function() { | ||
var object = { method: function () {}, method2: function() {} }; | ||
sinon.stub = function() { | ||
return object; | ||
}; | ||
this.collection.stub(object); | ||
assertEquals([object.method, object.method2], this.collection.fakes); | ||
assertEquals(2, this.collection.fakes.length); | ||
}, | ||
"should return a stubbed object": function() { | ||
var object = { method: function () {} }; | ||
sinon.stub = function () { | ||
return object; | ||
}; | ||
assertEquals(object, this.collection.stub(object)); | ||
}, | ||
"should return a stubbed method": function() { | ||
var object = { method: function () {} }; | ||
sinon.stub = function () { | ||
return object.method; | ||
}; | ||
assertEquals(object.method, this.collection.stub(object, "method")); | ||
} | ||
}); | ||
@@ -90,0 +125,0 @@ |
@@ -164,2 +164,24 @@ /*jslint onevar: false*/ | ||
"should unstub all methods of an objects after test is run": function () { | ||
var myMeth = function () {}; | ||
var myMeth2 = function () {}; | ||
var myObj = { meth: myMeth, meth2: myMeth2 }; | ||
var testCase = sinon.testCase({ | ||
testA: function () { | ||
this.stub(myObj); | ||
assertFunction(this.stub); | ||
assertNotSame(myMeth, myObj.meth); | ||
assertNotSame(myMeth2, myObj.meth2); | ||
} | ||
}); | ||
testCase.testA(); | ||
assertSame(myMeth, myObj.meth); | ||
assertSame(myMeth2, myObj.meth2); | ||
}, | ||
"should unstub objects stubbed in setUp": function () { | ||
@@ -185,2 +207,25 @@ var myMeth = function () {}; | ||
"should unstub all methods of an objects stubbed in setUp": function () { | ||
var myMeth = function () {}; | ||
var myMeth2 = function () {}; | ||
var myObj = { meth: myMeth, meth2: myMeth2 }; | ||
var testCase = sinon.testCase({ | ||
setUp: function () { | ||
this.stub(myObj); | ||
}, | ||
testA: function () { | ||
assertFunction(this.stub); | ||
assertNotSame(myMeth, myObj.meth); | ||
assertNotSame(myMeth2, myObj.meth2); | ||
} | ||
}); | ||
testCase.testA(); | ||
assertSame(myMeth, myObj.meth); | ||
assertSame(myMeth2, myObj.meth2); | ||
}, | ||
"should allow the use of helper methods": function () { | ||
@@ -187,0 +232,0 @@ var helper = sinon.spy(); |
@@ -75,2 +75,15 @@ /*jslint onevar: false, eqeqeq: false, browser: true*/ | ||
"should restore stubs on all object methods": function() { | ||
var method = function () {}; | ||
var method2 = function () {}; | ||
var object = { method: method, method2: method2 }; | ||
sinon.test(function () { | ||
this.stub(object); | ||
}).call({}); | ||
assertSame(method, object.method); | ||
assertSame(method2, object.method2); | ||
}, | ||
"should throw when method throws": function () { | ||
@@ -77,0 +90,0 @@ var method = function () {}; |
@@ -89,3 +89,28 @@ /*jslint onevar: false, eqeqeq: false, plusplus: false*/ | ||
assert(sinon.clock.evalCalled); | ||
} | ||
}, | ||
"should pass setTimeout parameters": function() { | ||
var clock = sinon.clock.create(); | ||
var stub = sinon.stub.create(); | ||
clock.setTimeout(stub, 2, 'the first', 'the second'); | ||
clock.tick(3); | ||
assertEquals(true, stub.calledWithExactly('the first', 'the second')); | ||
}, | ||
"should call correct timeout on recursive tick": function() { | ||
var clock = sinon.clock.create(), | ||
stub = sinon.stub.create(), | ||
recurseCallback = function(){ | ||
clock.tick(100); | ||
}; | ||
clock.setTimeout(recurseCallback, 50); | ||
clock.setTimeout(stub, 100); | ||
clock.tick(50); | ||
assert(stub.called); | ||
} | ||
}); | ||
@@ -483,2 +508,13 @@ | ||
assertEquals(3, stub.callCount); | ||
}, | ||
"should pass setTimeout parameters": function() { | ||
var clock = sinon.clock.create(); | ||
var stub = sinon.stub.create(); | ||
clock.setInterval(stub, 2, 'the first', 'the second'); | ||
clock.tick(3); | ||
assertEquals(true, stub.calledWithExactly('the first', 'the second')); | ||
} | ||
@@ -485,0 +521,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1586290
63
33532
63