summaryrefslogtreecommitdiff
path: root/spec/lib/jasmine-sinon.js
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-07-20 10:56:36 +0200
committerAzul <azul@leap.se>2012-07-20 10:56:36 +0200
commit50de80c5e817476ac95a096c718a66f5555fcd05 (patch)
treee05a25868a999557e2788a91f41da3a5a8a1a0b0 /spec/lib/jasmine-sinon.js
parent07fe2d8976db0ec267bd57ded90778f0d7695478 (diff)
INCOMPATIBLE: major restructuring of the repository
* removed Django code - we're keeping the tests - so I hope the two can still be used together * removed js packer - everyone has their own packaging strategy these days * cleaned up the repository - we only have js so javascript directory does not make much sense
Diffstat (limited to 'spec/lib/jasmine-sinon.js')
-rw-r--r--spec/lib/jasmine-sinon.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/lib/jasmine-sinon.js b/spec/lib/jasmine-sinon.js
new file mode 100644
index 0000000..2b7a9e0
--- /dev/null
+++ b/spec/lib/jasmine-sinon.js
@@ -0,0 +1,43 @@
+(function(global) {
+
+ var spyMatchers = "called calledOnce calledTwice calledThrice calledBefore calledAfter calledOn alwaysCalledOn calledWith alwaysCalledWith calledWithExactly alwaysCalledWithExactly".split(" "),
+ i = spyMatchers.length,
+ spyMatcherHash = {},
+ unusualMatchers = {
+ "returned": "toHaveReturned",
+ "alwaysReturned": "toHaveAlwaysReturned",
+ "threw": "toHaveThrown",
+ "alwaysThrew": "toHaveAlwaysThrown"
+ },
+
+ getMatcherFunction = function(sinonName) {
+ return function() {
+ var sinonProperty = this.actual[sinonName];
+ return (typeof sinonProperty === 'function') ? sinonProperty.apply(this.actual, arguments) : sinonProperty;
+ };
+ };
+
+ while(i--) {
+ var sinonName = spyMatchers[i],
+ matcherName = "toHaveBeen" + sinonName.charAt(0).toUpperCase() + sinonName.slice(1);
+
+ spyMatcherHash[matcherName] = getMatcherFunction(sinonName);
+ };
+
+ for (var j in unusualMatchers) {
+ spyMatcherHash[unusualMatchers[j]] = getMatcherFunction(j);
+ }
+
+ global.sinonJasmine = {
+ getMatchers: function() {
+ return spyMatcherHash;
+ }
+ };
+
+})(window);
+
+beforeEach(function() {
+
+ this.addMatchers(sinonJasmine.getMatchers());
+
+});