konacha-chai-matchers 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d75de08177b5bc14d3165f7d1aaf558dacfc584d
4
- data.tar.gz: a8c99d1eba99773d9195fd25ba01c26c75eaca3e
3
+ metadata.gz: f6b60b89f98ae533e719ffcab08c0b3e87b8799e
4
+ data.tar.gz: 191e69e079fa781a2e451fae095d89336f88d26b
5
5
  SHA512:
6
- metadata.gz: a0d413734a1fffa4a0939fd277d2c3ae1bdc0eefb4e965cd9c781a6b5821cb4a3093654c74a8419b5fbf21197844b8b66d90e0380fec7d35abb1267c9b28be1c
7
- data.tar.gz: 55b70498cbab2e31d33abe0f3599a9b299e43fb4e25de126fe7dfa2daf051bb4173f2738ea06f51c8f0531f05e89252bff18a1f43a8814e15ec38d65719c5c53
6
+ metadata.gz: 5ecfef8e457cdbe3ee1fca5c66d222284f91c25ef913261f3c3f9931d1db9121b766f4009b77e042676b779824fee78163d2aae93596498e0668079ac2629a99
7
+ data.tar.gz: 8de203d47ce991198b08732835a37176d46ee9ff713b98956186dfb4ee731d252fbb441ffe83710a442387c2d205e00d8b974fd5533f27ad5a6f826254fa78ad
@@ -46,3 +46,18 @@
46
46
  [submodule "memo-is"]
47
47
  path = memo-is
48
48
  url = https://github.com/d11wtq/node-memo-is.git
49
+ [submodule "chai-jq"]
50
+ path = chai-jq
51
+ url = https://github.com/FormidableLabs/chai-jq.git
52
+ [submodule "chai-js-factories"]
53
+ path = chai-js-factories
54
+ url = https://github.com/solatis/chai-js-factories.git
55
+ [submodule "chai-json-schema"]
56
+ path = chai-json-schema
57
+ url = https://github.com/Bartvds/chai-json-schema.git
58
+ [submodule "chai-datetime"]
59
+ path = chai-datetime
60
+ url = https://github.com/gaslight/chai-datetime.git
61
+ [submodule "chai-change"]
62
+ path = chai-change
63
+ url = https://github.com/timruffles/chai-change.git
@@ -0,0 +1 @@
1
+ 2.1.1
data/VERSIONS CHANGED
@@ -1,16 +1,21 @@
1
1
  chai-spies: 0.5.1
2
2
  sinon-chai: 2.5.0
3
- chai-as-promised: 4.1.0
4
- chai-jquery: 1.2.1
3
+ chai-as-promised: 4.1.1
4
+ chai-jquery: 1.2.3
5
5
  chai-timers: 0.2.0
6
6
  chai-stats: 0.3.0
7
7
  chai-null: 0.1.0
8
8
  chai-factories: 0.1.0
9
9
  chai-changes: 1.3.4
10
10
  chai-backbone: 0.9.2
11
- js-factories: 1.0.1
11
+ js-factories: 1.1.1
12
12
  mocha-as-promised: 2.0.0
13
13
  chai-things: 0.2.0
14
14
  chai-fuzzy: 1.4.0
15
- sinon: 1.7.3
15
+ sinon: 1.10.3
16
16
  memo-is: 0.0.2
17
+ chai-jq: 0.0.7
18
+ chai-js-factories: 0.1.3
19
+ chai-json-schema: 1.1.0
20
+ chai-datetime: 1.3.0
21
+ chai-change: 1.0.0
@@ -1 +1,2 @@
1
- sinon: v1.7.3
1
+ memo-is: origin/master
2
+ chai-jquery: origin/master
@@ -30,11 +30,25 @@ module Konacha
30
30
  @libs ||= urls.each_with_index.map do |url, i|
31
31
  name = paths[i]
32
32
  `cd ./#{name} && git fetch && cd ..`
33
- latest_tag = `cd ./#{name} && git describe --tags --abbrev=0 && cd ..`.split.first
34
- library_tag = locked_versions[name] || latest_tag
33
+ `cd ./#{name} && git fetch --tags && cd ..`
34
+ tags = `cd ./#{name} && git tag && cd ..`.split
35
+
36
+ ordered_tags = tags.sort do |astr, bstr|
37
+ a = astr.scan(/\d+/).map(&:to_i)
38
+ b = bstr.scan(/\d+/).map(&:to_i)
39
+ a.each_with_index do |e, c|
40
+ next if e == b[c]
41
+ break e <=> b[c]
42
+ end
43
+ end
44
+ latest_tag = ordered_tags.last
35
45
 
46
+ library_tag = latest_tag
47
+ library_tag = locked_versions[name] if locked_versions.key? name
36
48
  latest_commit = `cd ./#{name} && git rev-parse #{library_tag || 'HEAD'} && cd ..`.split.first
37
49
 
50
+ $stdout.puts "*** #{name} tag: #{latest_tag.inspect}, using: #{library_tag.inspect} commit: #{latest_commit}"
51
+
38
52
  Library.new url: url, name: name, tag: library_tag, commit: latest_commit
39
53
  end
40
54
  end
@@ -1,7 +1,7 @@
1
1
  module Konacha
2
2
  module Chai
3
3
  module Matchers
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -330,12 +330,12 @@
330
330
  return toTestAgainst !== undefined ? assertion.to.be.rejectedWith(toTestAgainst) : assertion.to.be.rejected;
331
331
  };
332
332
 
333
- assert.becomes = function (promise, value) {
334
- return assert.eventually.deepEqual(promise, value);
333
+ assert.becomes = function (promise, value, message) {
334
+ return assert.eventually.deepEqual(promise, value, message);
335
335
  };
336
336
 
337
- assert.doesNotBecome = function (promise, value) {
338
- return assert.eventually.notDeepEqual(promise, value);
337
+ assert.doesNotBecome = function (promise, value, message) {
338
+ return assert.eventually.notDeepEqual(promise, value, message);
339
339
  };
340
340
 
341
341
  assert.eventually = {};
@@ -0,0 +1,200 @@
1
+ (function() {
2
+
3
+ function plugin(chai,util) {
4
+
5
+ var Assertion = chai.Assertion;
6
+ var flag = util.flag;
7
+
8
+ chai.Assertion.addMethod('change',assertChange);
9
+ chai.Assertion.addMethod('changes',assertChange);
10
+ chai.assert.change = assertInterfaceChange;
11
+ chai.assert.noChange = assertInterfaceNoChange;
12
+
13
+ /**
14
+ * ### .change(getValue)
15
+ *
16
+ * Asserts that the value returned by `getValue`
17
+ * changes after the function has run:
18
+ *
19
+ * var x = 0;
20
+ * expect(function() { x += 1; }).to.change(function() { return x });
21
+ *
22
+ * expect(function() {}).not.to.change(function() { return x });
23
+ *
24
+ * You can pass options to be specific about the changes expected. Use the `from`
25
+ * key to enforce a starting value, a `to` key for and ending value, and a
26
+ * `by` key to enforce a numeric change.
27
+ *
28
+ * expect(function() { x += 1 }).to.change(function() { return x },{by: 1});
29
+ * expect(function() { x += 1 }).to.change(function() { return x },{from: x});
30
+ * expect(function() { x += 1 }).to.change(function() { return x },{from: x, to: x + 1});
31
+ * expect(function() { x += 1 }).to.change(function() { return x },{to: x + 1});
32
+ *
33
+ * @name change
34
+ * @param {Function} changer
35
+ * @param {Function} getValue
36
+ * @param {Object} options _optional_
37
+ * @api public
38
+ */
39
+ function assertChange(changeWatcher, changeSpec, msg) {
40
+ if(msg) flag(this, 'message', msg);
41
+ var body = flag(this, 'object');
42
+ var negated = flag(this,'negate');
43
+
44
+ var chai = this;
45
+ var FAIL = {};
46
+
47
+ changeSpec = changeSpec || {}
48
+
49
+ withFail(function() {
50
+ if(changeSpec) new Assertion(changeSpec).is.a('object');
51
+
52
+ new Assertion(body, msg).is.a('function');
53
+ new Assertion(changeWatcher, msg).is.a('function');
54
+
55
+ if(changeWatcher.length > 0 || body.length > 0) {
56
+ chai.assert(changeSpec.callback != null,"For asynchronous tests, need to pass a `done(err)` function as `callback:` option");
57
+ }
58
+
59
+ runStep(changeWatcher,function(before) {
60
+ withFail(preconditions,before);
61
+ runStep(body,function() {
62
+ runStep(changeWatcher,function(after) {
63
+ var result = withFail(postconditions,before,after);
64
+ if(result !== FAIL && changeSpec.callback) changeSpec.callback();
65
+ });
66
+ });
67
+ });
68
+ });
69
+
70
+ function preconditions(before) {
71
+ if('by' in changeSpec) {
72
+ if(typeof changeSpec.by !== 'number' ||
73
+ (changeSpec.from != null && typeof changeSpec.from !== 'number')) {
74
+ throw new Error('change "by" assertions only work with numbers specified in "by" and or "from" options');
75
+ }
76
+ changeSpec.to = before + changeSpec.by;
77
+ }
78
+ if('from' in changeSpec && changeSpec.from !== before) {
79
+ throw new Error("change 'from' value wasn't equal to " + util.inspect(before));
80
+ }
81
+ }
82
+
83
+ function postconditions(before,after) {
84
+ if('to' in changeSpec) {
85
+ chai.assert(
86
+ after === changeSpec.to
87
+ , 'expected ' + util.inspect(before) + ' to change to ' + util.inspect(changeSpec.to) + ', instead changed to ' + util.inspect(after)
88
+ , 'didn\'t expect ' + util.inspect(before) + ' to have changed to ' + util.inspect(changeSpec.to)
89
+ );
90
+ } else {
91
+ chai.assert(
92
+ after !== before
93
+ , 'expected value to have changed from ' + util.inspect(before)
94
+ , 'expected value to have remained unchanged from ' + util.inspect(before) + ', but changed to ' + util.inspect(after)
95
+ );
96
+ }
97
+ }
98
+
99
+ function runStep(fn,done) {
100
+ if(fn.length === 0) return done(withFail(fn));
101
+ fn(function(err,val) {
102
+ if(err) return fail(err);
103
+ done(val);
104
+ });
105
+ }
106
+
107
+ function fail(err) {
108
+ if(changeSpec.callback) return changeSpec.callback(err);
109
+ if(!(err instanceof Error)) err = new Error(err);
110
+ throw err;
111
+ }
112
+
113
+ function withFail(fn) {
114
+ var args = [].slice.call(arguments,1);
115
+ try {
116
+ return fn.apply(null,args);
117
+ } catch(e) {
118
+ fail(e);
119
+ return FAIL;
120
+ }
121
+ }
122
+
123
+ return this;
124
+
125
+ };
126
+ /**
127
+ * ### .change(getValue)
128
+ *
129
+ * Asserts that the value returned by `getValue`
130
+ * changes after the `affect` function has run:
131
+ *
132
+ * var x = 0;
133
+ * assert.change(function() { x += 1; },function() { return x });
134
+ *
135
+ * You can pass options to be specific about the changes expected. Use the `from`
136
+ * key to enforce a starting value, a `to` key for and ending value, and a
137
+ * `by` key to enforce a numeric change.
138
+ *
139
+ * assert.change(function() { x += 1 },function() { return x },{by: 1});
140
+ * assert.change(function() { x += 1 },function() { return x },{from: x});
141
+ * assert.change(function() { x += 1 },function() { return x },{from: x, to: x + 1});
142
+ * assert.change(function() { x += 1 },function() { return x },{to: x + 1});
143
+ *
144
+ * @name change
145
+ * @param {Function} affect
146
+ * @param {Function} getValue
147
+ * @param {Object} options _optional_
148
+ * @param {String} message
149
+ * @api public
150
+ */
151
+ function assertInterfaceChange(fn, changeWatcher, opts, msg) {
152
+ if(typeof opts === 'string') {
153
+ msg = opts;
154
+ opts = null;
155
+ }
156
+ new Assertion(fn, msg).to.change(changeWatcher,opts);
157
+ };
158
+
159
+ /**
160
+ * ### .change(getValue)
161
+ *
162
+ * Asserts that the value returned by `getValue`
163
+ * doesn't change after the `affect` has run:
164
+ *
165
+ * var x = 0;
166
+ * assert.noChange(doesNothing,function() { return x });
167
+ * function doesNothing() {}
168
+ *
169
+ * @name change
170
+ * @param {Function} affect
171
+ * @param {Function} getValue
172
+ * @param {Object} options _optional_
173
+ * @param {String} message
174
+ * @api public
175
+ */
176
+
177
+ function assertInterfaceNoChange(fn, changeWatcher, opts, msg) {
178
+ if(typeof opts === 'string') {
179
+ msg = opts;
180
+ opts = null;
181
+ }
182
+ new Assertion(fn, msg).not.to.change(changeWatcher,opts);
183
+ };
184
+
185
+ }
186
+
187
+ if(typeof module === "undefined") {
188
+ if(typeof define === "function" && define.amd) {
189
+ define([],function() {
190
+ return plugin;
191
+ });
192
+ } else {
193
+ chai.use(plugin);
194
+ }
195
+ } else {
196
+ module.exports = plugin;
197
+ }
198
+
199
+
200
+ })();
@@ -0,0 +1,170 @@
1
+ (function(plugin){
2
+ if (
3
+ typeof require === "function" &&
4
+ typeof exports === "object" &&
5
+ typeof module === "object"
6
+ ) {
7
+ // NodeJS
8
+ module.exports = plugin;
9
+ } else if (
10
+ typeof define === "function" &&
11
+ define.amd
12
+ ) {
13
+ // AMD
14
+ define(function () {
15
+ return plugin;
16
+ });
17
+ } else {
18
+ // Other environment (usually <script> tag): plug in to global chai instance directly.
19
+ chai.use(plugin);
20
+ }
21
+ }(function(chai, utils){
22
+ chai.datetime = chai.datetime || {};
23
+
24
+ chai.datetime.formatDate = function(date) {
25
+ return date.toDateString();
26
+ };
27
+
28
+ chai.datetime.formatTime = function(time) {
29
+ return time;
30
+ };
31
+
32
+ chai.datetime.equalTime = function(actual, expected) {
33
+ return actual.getTime() == expected.getTime();
34
+ };
35
+
36
+ chai.datetime.equalDate = function(actual, expected) {
37
+ return actual.toDateString() === expected.toDateString();
38
+ };
39
+
40
+ chai.datetime.beforeDate = function(actual, expected) {
41
+ return actual.getUTCFullYear() < expected.getUTCFullYear() || actual.getUTCMonth() < expected.getUTCMonth() || actual.getUTCDate() < expected.getUTCDate();
42
+ };
43
+
44
+ chai.datetime.afterDate = function(actual, expected) {
45
+ return actual.getUTCFullYear() > expected.getUTCFullYear() || actual.getUTCMonth() > expected.getUTCMonth() || actual.getUTCDate() > expected.getUTCDate();
46
+ };
47
+
48
+ chai.datetime.beforeTime = function(actual, expected) {
49
+ return actual.getTime() < expected.getTime();
50
+ };
51
+
52
+ chai.datetime.afterTime = function(actual, expected) {
53
+ return actual.getTime() > expected.getTime();
54
+ };
55
+
56
+ chai.Assertion.addChainableMethod('equalTime', function(expected) {
57
+ var actual = this._obj;
58
+
59
+ return this.assert(
60
+ chai.datetime.equalTime(expected, actual),
61
+ 'expected ' + this._obj + ' to equal ' + expected,
62
+ 'expected ' + this._obj + ' to not equal ' + expected,
63
+ expected.toString(),
64
+ actual.toString()
65
+ );
66
+ });
67
+
68
+ chai.Assertion.addChainableMethod('equalDate', function(expected) {
69
+ var expectedDate = chai.datetime.formatDate(expected),
70
+ actualDate = chai.datetime.formatDate(this._obj);
71
+
72
+ return this.assert(
73
+ chai.datetime.equalDate(this._obj, expected),
74
+ 'expected ' + actualDate + ' to equal ' + expectedDate,
75
+ 'expected ' + actualDate + ' to not equal ' + expectedDate
76
+ );
77
+ });
78
+
79
+ chai.Assertion.addChainableMethod('beforeDate', function(expected) {
80
+ var actual = this._obj;
81
+
82
+ this.assert(
83
+ chai.datetime.beforeDate(actual, expected),
84
+ 'expected ' + chai.datetime.formatDate(actual) + ' to be before ' + chai.datetime.formatDate(expected),
85
+ 'expected ' + chai.datetime.formatDate(actual) + ' not to be before ' + chai.datetime.formatDate(expected)
86
+ );
87
+ });
88
+
89
+ chai.Assertion.addChainableMethod('afterDate', function(expected) {
90
+ var actual = this._obj;
91
+
92
+ this.assert(
93
+ chai.datetime.afterDate(actual, expected),
94
+ 'expected ' + chai.datetime.formatDate(actual) + ' to be after ' + chai.datetime.formatDate(expected),
95
+ 'expected ' + chai.datetime.formatDate(actual) + ' not to be after ' + chai.datetime.formatDate(expected)
96
+ );
97
+ });
98
+
99
+ chai.Assertion.addChainableMethod('beforeTime', function(expected) {
100
+ var actual = this._obj;
101
+
102
+ this.assert(
103
+ chai.datetime.beforeTime(actual, expected),
104
+ 'expected ' + chai.datetime.formatTime(actual) + ' to be before ' + chai.datetime.formatTime(expected),
105
+ 'expected ' + chai.datetime.formatTime(actual) + ' not to be before ' + chai.datetime.formatTime(expected)
106
+ );
107
+ });
108
+
109
+ chai.Assertion.addChainableMethod('afterTime', function(expected) {
110
+ var actual = this._obj;
111
+
112
+ this.assert(
113
+ chai.datetime.afterTime(actual, expected),
114
+ 'expected ' + chai.datetime.formatTime(actual) + ' to be after ' + chai.datetime.formatTime(expected),
115
+ 'expected ' + chai.datetime.formatTime(actual) + ' not to be after ' + chai.datetime.formatTime(expected)
116
+ );
117
+ });
118
+
119
+ // Asserts
120
+ var assert = chai.assert;
121
+
122
+ assert.equalDate = function(val, exp, msg) {
123
+ new chai.Assertion(val, msg).to.be.equalDate(exp);
124
+ };
125
+
126
+ assert.notEqualDate = function(val, exp, msg) {
127
+ new chai.Assertion(val, msg).to.not.be.equalDate(exp);
128
+ };
129
+
130
+ assert.beforeDate = function(val, exp, msg) {
131
+ new chai.Assertion(val, msg).to.be.beforeDate(exp);
132
+ };
133
+
134
+ assert.notBeforeDate = function(val, exp, msg) {
135
+ new chai.Assertion(val, msg).to.not.be.beforeDate(exp);
136
+ };
137
+
138
+ assert.afterDate = function(val, exp, msg) {
139
+ new chai.Assertion(val, msg).to.be.afterDate(exp);
140
+ };
141
+
142
+ assert.notAfterDate = function(val, exp, msg) {
143
+ new chai.Assertion(val, msg).not.to.be.afterDate(exp);
144
+ };
145
+
146
+ assert.equalTime = function(val, exp, msg) {
147
+ new chai.Assertion(val, msg).to.be.equalTime(exp);
148
+ };
149
+
150
+ assert.notEqualTime = function(val, exp, msg) {
151
+ new chai.Assertion(val, msg).to.not.be.equalTime(exp);
152
+ };
153
+
154
+ assert.beforeTime = function(val, exp, msg) {
155
+ new chai.Assertion(val, msg).to.be.beforeTime(exp);
156
+ };
157
+
158
+ assert.notBeforeTime = function(val, exp, msg) {
159
+ new chai.Assertion(val, msg).not.to.be.beforeTime(exp);
160
+ };
161
+
162
+ assert.afterTime = function(val, exp, msg) {
163
+ new chai.Assertion(val, msg).to.be.afterTime(exp);
164
+ };
165
+
166
+ assert.notAfterTime = function(val, exp, msg) {
167
+ new chai.Assertion(val, msg).to.not.be.afterTime(exp);
168
+ };
169
+
170
+ }));