konacha-chai-matchers 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitmodules CHANGED
@@ -34,3 +34,6 @@
34
34
  [submodule "js-factories"]
35
35
  path = js-factories
36
36
  url = git://github.com/matthijsgroen/js-factories.git
37
+ [submodule "mocha-as-promised"]
38
+ path = mocha-as-promised
39
+ url = git://github.com/domenic/mocha-as-promised.git
@@ -1,7 +1,7 @@
1
1
  module Konacha
2
2
  module Chai
3
3
  module Matchers
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
6
6
  end
7
7
  end
@@ -44,13 +44,13 @@
44
44
  return flag(this, 'routing', true);
45
45
  });
46
46
  routeTo = function(router, methodName, options) {
47
- var consideredRouter, current_history, route, spy, _i, _len, _ref;
47
+ var consideredRouter, current_history, route, stub, _i, _len, _ref;
48
48
  if (options == null) {
49
49
  options = {};
50
50
  }
51
51
  current_history = Backbone.history;
52
52
  Backbone.history = new Backbone.History;
53
- spy = sinon.spy(router, methodName);
53
+ stub = sinon.stub(router, methodName);
54
54
  this.assert(router._bindRoutes != null, 'provided router is not a Backbone.Router');
55
55
  router._bindRoutes();
56
56
  if (options.considering != null) {
@@ -67,9 +67,9 @@
67
67
  Backbone.history.loadUrl(route);
68
68
  Backbone.history = current_history;
69
69
  router[methodName].restore();
70
- this.assert(spy.calledOnce, "expected `" + route + "` to route to " + methodName, "expected `" + route + "` not to route to " + methodName);
70
+ this.assert(stub.calledOnce, "expected `" + route + "` to route to " + methodName, "expected `" + route + "` not to route to " + methodName);
71
71
  if (options["arguments"] != null) {
72
- return this.assert(spy.calledWith.apply(spy, options["arguments"]), "expected `" + methodName + "` to be called with " + (inspect(options["arguments"])) + ", but was called with " + (inspect(spy.args[0])) + " instead", "expected `" + methodName + "` not to be called with " + (inspect(options["arguments"])) + ", but was");
72
+ return this.assert(stub.calledWith.apply(stub, options["arguments"]), "expected `" + methodName + "` to be called with " + (inspect(options["arguments"])) + ", but was called with " + (inspect(stub.args[0])) + " instead", "expected `" + methodName + "` not to be called with " + (inspect(options["arguments"])) + ", but was");
73
73
  }
74
74
  };
75
75
  chai.Assertion.overwriteProperty('to', function(_super) {
@@ -0,0 +1,139 @@
1
+ (function (mochaAsPromised) {
2
+ "use strict";
3
+
4
+ // Module systems magic dance.
5
+
6
+ if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
7
+ // Node.js: plug in automatically, if no argument is provided. This is a good idea since one can run Mocha tests
8
+ // using the Mocha test runner from either a locally-installed package, or from a globally-installed one.
9
+ // In the latter case, naively plugging in `require("mocha")` would end up duck-punching the wrong instance,
10
+ // so we provide this shortcut to auto-detect which Mocha package needs to be duck-punched.
11
+ module.exports = function (mocha) {
12
+ if (!mocha) {
13
+ if (typeof process === "object" && Object.prototype.toString.call(process) === "[object process]") {
14
+ // We're in *real* Node.js, not in a browserify-like environment. Do automatic detection logic.
15
+ var path = require("path");
16
+
17
+ // `process.argv[1]` is either something like `"/host/package/node_modules/mocha/bin/_mocha`", or
18
+ // `"/path/to/global/node_modules/mocha/bin/_mocha"`. Verify that, though:
19
+ var lastThreeSegments = process.argv[1].split(path.sep).slice(-3);
20
+ if (lastThreeSegments[0] !== "mocha" || lastThreeSegments[1] !== "bin") {
21
+ throw new Error("Attempted to automatically plug in to Mocha, but was not running through " +
22
+ "the Mocha test runner. Either run using the Mocha command-line test runner, " +
23
+ "or plug in manually by passing the running Mocha module.");
24
+ }
25
+
26
+ var mochaPath = path.resolve(process.argv[1], "../..");
27
+ mocha = (require)(mochaPath); // Trick browserify into not complaining.
28
+ } else if (typeof Mocha !== "undefined") {
29
+ // We're in a browserify-like emulation environment. Try the `Mocha` global.
30
+ mocha = Mocha;
31
+ } else {
32
+ throw new Error("Attempted to automatically plug in to Mocha, but could not detect the " +
33
+ "environment. Plug in manually by passing the running Mocha module.");
34
+ }
35
+ }
36
+
37
+ mochaAsPromised(mocha);
38
+ };
39
+ } else if (typeof define === "function" && define.amd) {
40
+ // AMD
41
+ define(function () {
42
+ return mochaAsPromised;
43
+ });
44
+ } else {
45
+ // Other environment (usually <script> tag): plug in global `Mocha` directly and automatically.
46
+ mochaAsPromised(Mocha);
47
+ }
48
+ }((function () {
49
+ "use strict";
50
+
51
+ function isPromise(x) {
52
+ return typeof x === "object" && x !== null && typeof x.then === "function";
53
+ }
54
+
55
+ var duckPunchedAlready = false;
56
+
57
+ return function mochaAsPromised(mocha) {
58
+ if (duckPunchedAlready) {
59
+ return;
60
+ }
61
+ duckPunchedAlready = true;
62
+
63
+ // Soooo this is an awesome hack.
64
+
65
+ // Here's the idea: Mocha `Runnable` instances have a `fn` property, representing the test to run. Async tests
66
+ // in Mocha are done with `fn`s that take a `done` callback, and call it with either nothing (success) or an
67
+ // error (failure). We want to add another paradigm for async tests: `fn`s that take no arguments, but return a
68
+ // promise. Promise fulfillment corresponds to success, and rejection to failure.
69
+
70
+ // To do this, we translate promise-returning `fn`s into callback-calling ones. So Mocha never sees the promisey
71
+ // functions, but instead sees a wrapper around them that we provide. The only trick is, how and when to insert
72
+ // this wrapper into a Mocha `Runnable`?
73
+
74
+ // We accomplish this by intercepting all [[Put]]s to the `fn` property of *any* `Runnable`. That is, we define
75
+ // a setter for `fn` on `Runnable.prototype` (!). So when Mocha sets the `fn` property of a runnable inside the
76
+ // `Runnable` constructor (i.e. `this.fn = fn`), it is immediately translated into a wrapped version, which is
77
+ // then stored as a `_wrappedFn` instance property. Finally we define a getter for `fn` on `Runnable.prototype`
78
+ // as well, so that any retrievals of the `fn` property (e.g. in `Runnable.prototype.run`) return the wrapped
79
+ // version we've stored.
80
+
81
+ // We also need to override the `async` property, since the Mocha constructor sets it by looking at the `fn`
82
+ // passed in, and not at the `this.fn` property we have control over. We just give it a getter that performs the
83
+ // same logic as the Mocha constructor, and a no-op setter (so that it silently ignores Mocha's attempts to set
84
+ // it).
85
+
86
+ // ISN'T THIS COOL!?
87
+
88
+ Object.defineProperties(mocha.Runnable.prototype, {
89
+ fn: {
90
+ configurable: true,
91
+ enumerable: true,
92
+ get: function () {
93
+ return this._wrappedFn;
94
+ },
95
+ set: function (fn) {
96
+ this._wrappedFn = function (done) {
97
+ // Run the original `fn`, passing along `done` for the case in which it's callback-asynchronous.
98
+ // Make sure to forward the `this` context, since you can set variables and stuff on it to share
99
+ // within a suite.
100
+ var retVal = fn.call(this, done);
101
+
102
+ if (isPromise(retVal)) {
103
+ // If we get a promise back...
104
+ retVal.then(
105
+ function () {
106
+ // On fulfillment, ignore the fulfillment value and call `done()` with no arguments.
107
+ done();
108
+ },
109
+ function (reason) {
110
+ // On rejection, make sure there's a rejection reason, then call `done` with it.
111
+ if (reason === null || reason === undefined) {
112
+ reason = new Error("Promise rejected with no rejection reason.");
113
+ }
114
+ done(reason);
115
+ }
116
+ );
117
+ } else if (fn.length === 0) {
118
+ // If `fn` is synchronous (i.e. didn't have a `done` parameter and didn't return a promise),
119
+ // call `done` now. (If it's callback-asynchronous, `fn` will call `done` eventually since
120
+ // we passed it in above.)
121
+ done();
122
+ }
123
+ };
124
+ }
125
+ },
126
+ async: {
127
+ configurable: true,
128
+ enumerable: true,
129
+ get: function () {
130
+ // We've made every test async, so always return `true`.
131
+ return true;
132
+ },
133
+ set: function () {
134
+ // Ignore Mocha trying to set this; it doesn't know the whole picture.
135
+ }
136
+ }
137
+ });
138
+ };
139
+ }())));
@@ -39,7 +39,9 @@
39
39
  function getMessages(spy, action, nonNegatedSuffix, always, args) {
40
40
  var verbPhrase = always ? "always have " : "have ";
41
41
  nonNegatedSuffix = nonNegatedSuffix || "";
42
- spy = spy.proxy || spy;
42
+ if (isSpy(spy.proxy)) {
43
+ spy = spy.proxy;
44
+ }
43
45
 
44
46
  function printfArray(array) {
45
47
  return spy.printf.apply(spy, array);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Sinon.JS 1.5.2, 2013/01/07
2
+ * Sinon.JS 1.5.2, 2013/01/09
3
3
  *
4
4
  * @author Christian Johansen (christian@cjohansen.no)
5
5
  * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konacha-chai-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-07 00:00:00.000000000 Z
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A set of Chai.js libraries ready to use for Konacha
15
15
  email:
@@ -38,6 +38,7 @@ files:
38
38
  - vendor/assets/javascripts/chai-stats.js
39
39
  - vendor/assets/javascripts/chai-timers.js
40
40
  - vendor/assets/javascripts/js-factories.js
41
+ - vendor/assets/javascripts/mocha-as-promised.js
41
42
  - vendor/assets/javascripts/sinon-chai.js
42
43
  - vendor/assets/javascripts/sinon.js
43
44
  homepage: ''