konacha-chai-matchers 0.0.3 → 0.0.4

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.
@@ -1,7 +1,7 @@
1
1
  module Konacha
2
2
  module Chai
3
3
  module Matchers
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
6
6
  end
7
7
  end
@@ -22,12 +22,14 @@
22
22
  */
23
23
 
24
24
  chai.Assertion.addMethod('when', function(val, options) {
25
- var action, definedActions, done, result, _i, _j, _len, _len1, _results,
25
+ var action, definedActions, done, object, promiseCallback, result, _i, _j, _len, _len1,
26
26
  _this = this;
27
27
  if (options == null) {
28
28
  options = {};
29
29
  }
30
30
  definedActions = flag(this, 'whenActions') || [];
31
+ object = flag(this, 'object');
32
+ flag(this, 'whenObject', object);
31
33
  for (_i = 0, _len = definedActions.length; _i < _len; _i++) {
32
34
  action = definedActions[_i];
33
35
  if (typeof action.before === "function") {
@@ -35,12 +37,13 @@
35
37
  }
36
38
  }
37
39
  result = val();
38
- if (result.then != null) {
40
+ flag(this, 'object', result);
41
+ if ((result != null ? result.then : void 0) != null) {
39
42
  done = options != null ? options.notify : void 0;
40
43
  if (done == null) {
41
44
  done = function() {};
42
45
  }
43
- return result.then(function() {
46
+ promiseCallback = function() {
44
47
  var _j, _len1;
45
48
  try {
46
49
  for (_j = 0, _len1 = definedActions.length; _j < _len1; _j++) {
@@ -51,17 +54,20 @@
51
54
  }
52
55
  return done();
53
56
  } catch (error) {
54
- return done(new Error(error));
57
+ done(new Error(error));
58
+ throw new Error(error);
55
59
  }
56
- });
60
+ };
61
+ result.then(promiseCallback, promiseCallback);
57
62
  } else {
58
- _results = [];
59
63
  for (_j = 0, _len1 = definedActions.length; _j < _len1; _j++) {
60
64
  action = definedActions[_j];
61
- _results.push(typeof action.after === "function" ? action.after(this) : void 0);
65
+ if (typeof action.after === "function") {
66
+ action.after(this);
67
+ }
62
68
  }
63
- return _results;
64
69
  }
70
+ return this;
65
71
  });
66
72
  noChangeAssert = function(context) {
67
73
  var endValue, negate, object, relevant, result, startValue;
@@ -71,7 +77,7 @@
71
77
  }
72
78
  negate = flag(context, 'negate');
73
79
  flag(context, 'negate', this.negate);
74
- object = flag(context, 'object');
80
+ object = flag(context, 'whenObject');
75
81
  startValue = flag(context, 'changeStart');
76
82
  endValue = object();
77
83
  result = !utils.eql(endValue, startValue);
@@ -82,7 +88,7 @@
82
88
  var actualDelta, endValue, negate, object, startValue;
83
89
  negate = flag(context, 'negate');
84
90
  flag(context, 'negate', this.negate);
85
- object = flag(context, 'object');
91
+ object = flag(context, 'whenObject');
86
92
  startValue = flag(context, 'changeStart');
87
93
  endValue = object();
88
94
  actualDelta = endValue - startValue;
@@ -93,7 +99,7 @@
93
99
  var negate, object, result, startValue;
94
100
  negate = flag(context, 'negate');
95
101
  flag(context, 'negate', this.negate);
96
- object = flag(context, 'object');
102
+ object = flag(context, 'whenObject');
97
103
  startValue = object();
98
104
  result = !utils.eql(startValue, this.expectedEndValue);
99
105
  if (negate) {
@@ -106,7 +112,7 @@
106
112
  var endValue, negate, object, result;
107
113
  negate = flag(context, 'negate');
108
114
  flag(context, 'negate', this.negate);
109
- object = flag(context, 'object');
115
+ object = flag(context, 'whenObject');
110
116
  endValue = object();
111
117
  result = utils.eql(endValue, this.expectedEndValue);
112
118
  context.assert(result, "expected `" + (formatFunction(object)) + "` to change to " + (utils.inspect(this.expectedEndValue)) + ", but it changed to " + (utils.inspect(endValue)), "expected `" + (formatFunction(object)) + "` not to change to " + (utils.inspect(this.expectedEndValue)) + ", but it did");
@@ -116,7 +122,7 @@
116
122
  var negate, object, result, startValue;
117
123
  negate = flag(context, 'negate');
118
124
  flag(context, 'negate', this.negate);
119
- object = flag(context, 'object');
125
+ object = flag(context, 'whenObject');
120
126
  startValue = object();
121
127
  result = utils.eql(startValue, this.expectedStartValue);
122
128
  context.assert(result, "expected the change of `" + (formatFunction(object)) + "` to start from " + (utils.inspect(this.expectedStartValue)) + ", but it started from " + (utils.inspect(startValue)), "expected the change of `" + (formatFunction(object)) + "` not to start from " + (utils.inspect(this.expectedStartValue)) + ", but it did");
@@ -126,7 +132,7 @@
126
132
  var endValue, negate, object, result, startValue;
127
133
  negate = flag(context, 'negate');
128
134
  flag(context, 'negate', this.negate);
129
- object = flag(context, 'object');
135
+ object = flag(context, 'whenObject');
130
136
  startValue = flag(context, 'changeStart');
131
137
  endValue = object();
132
138
  result = !utils.eql(startValue, endValue);
@@ -144,7 +150,7 @@
144
150
  negate: flag(this, 'negate'),
145
151
  before: function(context) {
146
152
  var startValue;
147
- startValue = flag(context, 'object')();
153
+ startValue = flag(context, 'whenObject')();
148
154
  return flag(context, 'changeStart', startValue);
149
155
  },
150
156
  after: noChangeAssert
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Sinon.JS 1.5.2, 2013/01/06
2
+ * Sinon.JS 1.5.2, 2013/01/07
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.3
4
+ version: 0.0.4
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-06 00:00:00.000000000 Z
12
+ date: 2013-01-07 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: