konacha-chai-matchers 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +33 -27
- data/lib/konacha-chai-matchers/version.rb +1 -1
- data/tasks/update.rb +39 -12
- data/vendor/assets/javascripts/chai-fuzzy.js +90 -0
- data/vendor/assets/javascripts/chai-things.js +143 -0
- data/vendor/assets/javascripts/sinon.js +1 -3429
- metadata +11 -3
data/.gitmodules
CHANGED
@@ -1,39 +1,45 @@
|
|
1
1
|
[submodule "chai-spies"]
|
2
|
-
|
3
|
-
|
2
|
+
path = chai-spies
|
3
|
+
url = git://github.com/chaijs/chai-spies.git
|
4
4
|
[submodule "sinon-chai"]
|
5
|
-
|
6
|
-
|
5
|
+
path = sinon-chai
|
6
|
+
url = git://github.com/domenic/sinon-chai.git
|
7
7
|
[submodule "chai-as-promised"]
|
8
|
-
|
9
|
-
|
8
|
+
path = chai-as-promised
|
9
|
+
url = git://github.com/domenic/chai-as-promised.git
|
10
10
|
[submodule "chai-jquery"]
|
11
|
-
|
12
|
-
|
11
|
+
path = chai-jquery
|
12
|
+
url = git://github.com/chaijs/chai-jquery.git
|
13
13
|
[submodule "chai-timers"]
|
14
|
-
|
15
|
-
|
14
|
+
path = chai-timers
|
15
|
+
url = git://github.com/chaijs/chai-timers.git
|
16
16
|
[submodule "chai-stats"]
|
17
|
-
|
18
|
-
|
17
|
+
path = chai-stats
|
18
|
+
url = git://github.com/chaijs/chai-stats.git
|
19
19
|
[submodule "chai-null"]
|
20
|
-
|
21
|
-
|
20
|
+
path = chai-null
|
21
|
+
url = git://github.com/chaijs/chai-null.git
|
22
22
|
[submodule "chai-factories"]
|
23
|
-
|
24
|
-
|
23
|
+
path = chai-factories
|
24
|
+
url = git://github.com/chaijs/chai-factories.git
|
25
25
|
[submodule "chai-changes"]
|
26
|
-
|
27
|
-
|
26
|
+
path = chai-changes
|
27
|
+
url = https://github.com/matthijsgroen/chai-changes.git
|
28
28
|
[submodule "chai-backbone"]
|
29
|
-
|
30
|
-
|
31
|
-
[submodule "Sinon.JS"]
|
32
|
-
path = Sinon.JS
|
33
|
-
url = git://github.com/cjohansen/Sinon.JS.git
|
29
|
+
path = chai-backbone
|
30
|
+
url = https://github.com/matthijsgroen/chai-backbone.git
|
34
31
|
[submodule "js-factories"]
|
35
|
-
|
36
|
-
|
32
|
+
path = js-factories
|
33
|
+
url = git://github.com/matthijsgroen/js-factories.git
|
37
34
|
[submodule "mocha-as-promised"]
|
38
|
-
|
39
|
-
|
35
|
+
path = mocha-as-promised
|
36
|
+
url = git://github.com/domenic/mocha-as-promised.git
|
37
|
+
[submodule "chai-things"]
|
38
|
+
path = chai-things
|
39
|
+
url = git://github.com/RubenVerborgh/Chai-Things.git
|
40
|
+
[submodule "chai-fuzzy"]
|
41
|
+
path = chai-fuzzy
|
42
|
+
url = git://github.com/elliotf/chai-fuzzy.git
|
43
|
+
[submodule "sinon"]
|
44
|
+
path = sinon
|
45
|
+
url = git://github.com/cjohansen/Sinon.JS.git
|
data/tasks/update.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'pathname'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
desc 'updates all submodules'
|
4
5
|
task :update do
|
5
6
|
modules = collect_modules
|
6
|
-
update_modules modules
|
7
|
+
#update_modules modules
|
7
8
|
vendor_files modules
|
8
9
|
end
|
9
10
|
|
@@ -12,7 +13,9 @@ def collect_modules
|
|
12
13
|
File.open('.gitmodules') do |f|
|
13
14
|
contents = f.read
|
14
15
|
contents.each_line do |line|
|
15
|
-
|
16
|
+
if matches = /\[submodule "(.*)"\]/.match(line)
|
17
|
+
modules << matches[1]
|
18
|
+
end
|
16
19
|
end
|
17
20
|
end
|
18
21
|
modules
|
@@ -20,28 +23,52 @@ end
|
|
20
23
|
|
21
24
|
def main_files folders
|
22
25
|
folders.map do |f|
|
23
|
-
|
24
|
-
|
26
|
+
r = determine_file_from_suggestion f
|
27
|
+
r ||= get_main_file_from_package "./#{f}/package.json", f
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
r = path_order.map do |p|
|
29
|
-
p if File.exist? p
|
30
|
-
end.flatten.compact.first
|
29
|
+
{ lib: r, module: f }
|
31
30
|
end.flatten.compact
|
32
31
|
end
|
33
32
|
|
33
|
+
def determine_file_from_suggestion filename, folder = filename
|
34
|
+
file_search = filename.downcase
|
35
|
+
file_search << '.js' unless file_search =~ /\.js$/
|
36
|
+
|
37
|
+
path_order = [
|
38
|
+
"./#{folder}/pkg/#{file_search}",
|
39
|
+
"./#{folder}/#{file_search}",
|
40
|
+
"./#{folder}/lib/#{file_search}"
|
41
|
+
]
|
42
|
+
path_order.map do |p|
|
43
|
+
p if File.exist? p
|
44
|
+
end.flatten.compact.first
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_main_file_from_package filename, folder
|
48
|
+
return unless File.exist? filename
|
49
|
+
json_string = File.open(filename).read
|
50
|
+
json = JSON.parse json_string
|
51
|
+
return unless json.has_key? "main"
|
52
|
+
main_file = json["main"]
|
53
|
+
determine_file_from_suggestion main_file, folder
|
54
|
+
end
|
55
|
+
|
34
56
|
def vendor_files modules
|
35
57
|
files = main_files modules
|
36
|
-
|
58
|
+
missing = files.map { |f| f[:lib].nil? ? f[:module] : nil }.compact
|
59
|
+
|
60
|
+
puts "missing #{missing.length} lib files: #{missing.inspect}" unless missing.empty?
|
61
|
+
|
37
62
|
path = "./vendor/assets/javascripts/"
|
38
63
|
Pathname.new(path).mkpath()
|
39
|
-
|
64
|
+
files.each do |info|
|
65
|
+
FileUtils.cp(info[:lib], "#{path}#{info[:module]}.js") if info[:lib]
|
66
|
+
end
|
40
67
|
end
|
41
68
|
|
42
69
|
def update_modules modules
|
43
70
|
modules.each do |mod|
|
44
|
-
`cd ./#{mod} && git pull`
|
71
|
+
`cd ./#{mod} && git pull origin master`
|
45
72
|
`cd ./#{mod} && ./build` if File.exist? "./#{mod}/build"
|
46
73
|
end
|
47
74
|
end
|
@@ -0,0 +1,90 @@
|
|
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
|
+
var _;
|
23
|
+
|
24
|
+
if (
|
25
|
+
typeof require === "function"
|
26
|
+
&& typeof exports === "object"
|
27
|
+
&& typeof module === "object"
|
28
|
+
) {
|
29
|
+
// server-side
|
30
|
+
_ = require('underscore');
|
31
|
+
} else {
|
32
|
+
// browser-side
|
33
|
+
_ = window._;
|
34
|
+
}
|
35
|
+
|
36
|
+
// contain => _.where, check _.isEqual
|
37
|
+
// containOnce => contain, check size of returned array
|
38
|
+
// like => _.isEqual
|
39
|
+
|
40
|
+
chai.Assertion.addMethod('like', function(expected){
|
41
|
+
var obj = this._obj
|
42
|
+
this.assert(
|
43
|
+
_.isEqual(obj, expected)
|
44
|
+
, "expected #{this} to be like #{exp}"
|
45
|
+
, "expected #{this} not to be like #{exp}"
|
46
|
+
, expected
|
47
|
+
, obj
|
48
|
+
, true
|
49
|
+
)
|
50
|
+
});
|
51
|
+
|
52
|
+
chai.Assertion.addMethod('jsonOf', function(expected){
|
53
|
+
var obj = this._obj;
|
54
|
+
var expectedAsJSON = JSON.parse(JSON.stringify(expected));
|
55
|
+
|
56
|
+
this.assert(
|
57
|
+
_.isEqual(obj, expectedAsJSON)
|
58
|
+
, "expected #{this} to be like JSON #{exp}"
|
59
|
+
, "expected #{this} not to be like JSON #{exp}"
|
60
|
+
, expectedAsJSON
|
61
|
+
, obj
|
62
|
+
, true
|
63
|
+
)
|
64
|
+
});
|
65
|
+
|
66
|
+
chai.Assertion.addMethod('containOneLike', function(expected){
|
67
|
+
var obj = this._obj
|
68
|
+
|
69
|
+
var _obj = _(obj);
|
70
|
+
|
71
|
+
if (!_obj.isObject() && !_obj.isArray()) {
|
72
|
+
this.assert(
|
73
|
+
false
|
74
|
+
, "expected #{this} to be an array, object, or string"
|
75
|
+
, "expected #{this} to be an array, object, or string"
|
76
|
+
)
|
77
|
+
}
|
78
|
+
|
79
|
+
var found = _obj.some(function(needle){
|
80
|
+
return _.isEqual(needle,expected);
|
81
|
+
});
|
82
|
+
|
83
|
+
this.assert(
|
84
|
+
found
|
85
|
+
, "expected #{this} to contain one thing like #{exp}"
|
86
|
+
, "expected #{this} not to contain one thing like #{exp}"
|
87
|
+
, expected
|
88
|
+
)
|
89
|
+
});
|
90
|
+
}));
|
@@ -0,0 +1,143 @@
|
|
1
|
+
(function (chaiModule) {
|
2
|
+
"use strict";
|
3
|
+
// NodeJS
|
4
|
+
if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
|
5
|
+
module.exports = chaiModule;
|
6
|
+
// AMD
|
7
|
+
else if (typeof define === "function" && define.amd)
|
8
|
+
define(function () { return chaiModule; });
|
9
|
+
// Other
|
10
|
+
else
|
11
|
+
chai.use(chaiModule);
|
12
|
+
}(function chaiAsPromised(chai, utils) {
|
13
|
+
"use strict";
|
14
|
+
|
15
|
+
var Assertion = chai.Assertion,
|
16
|
+
assertionPrototype = Assertion.prototype,
|
17
|
+
expect = chai.expect;
|
18
|
+
|
19
|
+
// Handles the `something` chain property
|
20
|
+
function chainSomething() {
|
21
|
+
// `include` or `contains` should have been called before
|
22
|
+
if (!utils.flag(this, "contains"))
|
23
|
+
throw new Error("cannot use something without include or contains");
|
24
|
+
// `something` should not have been used already
|
25
|
+
if (utils.flag(this, "something"))
|
26
|
+
throw new Error("cannot use something twice in an assertion");
|
27
|
+
// flag that this is a `something` chain
|
28
|
+
utils.flag(this, "something", {
|
29
|
+
// remember if `something` was negated
|
30
|
+
negate: utils.flag(this, "negate")
|
31
|
+
});
|
32
|
+
// reset the negation flag for the coming assertion
|
33
|
+
utils.flag(this, "negate", false);
|
34
|
+
}
|
35
|
+
|
36
|
+
// Performs the `something()` assertion
|
37
|
+
function assertSomething() {
|
38
|
+
// Undo the flags set by the `something` chain property
|
39
|
+
var somethingFlags = utils.flag(this, "something");
|
40
|
+
utils.flag(this, "something", false);
|
41
|
+
utils.flag(this, "negate", somethingFlags.negate);
|
42
|
+
|
43
|
+
// The assertion's object for `something` should be array-like
|
44
|
+
var object = utils.flag(this, "object");
|
45
|
+
expect(object).to.have.property("length");
|
46
|
+
expect(object.length).to.be.a("number", "something object length");
|
47
|
+
|
48
|
+
// The object should contain something
|
49
|
+
this.assert(object.length > 0,
|
50
|
+
"expected #{this} to contain something",
|
51
|
+
"expected #{this} not to contain something"
|
52
|
+
);
|
53
|
+
}
|
54
|
+
|
55
|
+
// Find all assertion methods
|
56
|
+
var methodNames = Object.getOwnPropertyNames(assertionPrototype)
|
57
|
+
.filter(function (propertyName) {
|
58
|
+
var property = Object.getOwnPropertyDescriptor(assertionPrototype, propertyName);
|
59
|
+
return typeof property.value === "function";
|
60
|
+
});
|
61
|
+
|
62
|
+
// Override all methods to react on a possible `something` in the chain
|
63
|
+
methodNames.forEach(function (methodName) {
|
64
|
+
Assertion.overwriteMethod(methodName, function (_super) {
|
65
|
+
return function () {
|
66
|
+
// Return if no `something` has been used in the chain
|
67
|
+
var somethingFlags = utils.flag(this, "something");
|
68
|
+
if (!somethingFlags)
|
69
|
+
return _super.apply(this, arguments);
|
70
|
+
// Clear the `something` flag; it should not be handled again
|
71
|
+
utils.flag(this, "something", false);
|
72
|
+
|
73
|
+
// The assertion's object for `something` should be array-like
|
74
|
+
var arrayObject = utils.flag(this, "object");
|
75
|
+
expect(arrayObject).to.have.property("length");
|
76
|
+
var length = arrayObject.length;
|
77
|
+
expect(length).to.be.a("number", "something object length");
|
78
|
+
|
79
|
+
// In the negative case, an empty array means success
|
80
|
+
var negate = somethingFlags.negate;
|
81
|
+
if (negate && !length)
|
82
|
+
return;
|
83
|
+
// In the positive case, the array should not be empty
|
84
|
+
new Assertion(arrayObject).assert(length,
|
85
|
+
"expected #{this} to contain something");
|
86
|
+
|
87
|
+
// Try the assertion on every array element
|
88
|
+
var assertionError;
|
89
|
+
for (var i = 0; i < length; i++) {
|
90
|
+
// Test whether the element satisfies the assertion
|
91
|
+
var item = arrayObject[i],
|
92
|
+
itemAssertion = copyAssertion(this, item, somethingAssert);
|
93
|
+
assertionError = null;
|
94
|
+
try { _super.apply(itemAssertion, arguments); }
|
95
|
+
catch (error) { assertionError = error; }
|
96
|
+
// If the element satisfies the assertion
|
97
|
+
if (!assertionError) {
|
98
|
+
// In case the base assertion is negated, a satisfying element
|
99
|
+
// means the base assertion ("no element must satisfy x") fails
|
100
|
+
if (negate) {
|
101
|
+
// Assert the negated item assertion, which should fail and throw an error
|
102
|
+
var negItemAssertion = copyAssertion(this, item, somethingAssert, true);
|
103
|
+
_super.apply(negItemAssertion, arguments);
|
104
|
+
// Throw here if, for some reason, the negated item assertion didn't throw
|
105
|
+
new Assertion(arrayObject).assert(false,
|
106
|
+
"expected no element of #{this} to satisfy the assertion");
|
107
|
+
}
|
108
|
+
// In the positive case, a satisfying element means the assertion holds
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
// Changes the assertion message to an array viewpoint
|
113
|
+
function somethingAssert(test, positive, negative, expected, actual) {
|
114
|
+
var replacement = (negate ? "no" : "an") + " element of #{this}";
|
115
|
+
utils.flag(this, "object", arrayObject);
|
116
|
+
assertionPrototype.assert.call(this, test,
|
117
|
+
(negate ? negative : positive).replace("#{this}", replacement),
|
118
|
+
(negate ? positive : negative).replace("#{this}", replacement),
|
119
|
+
expected, actual);
|
120
|
+
}
|
121
|
+
// If we reach this point, no element that satisfies the assertion has been found
|
122
|
+
if (!negate)
|
123
|
+
throw assertionError;
|
124
|
+
};
|
125
|
+
});
|
126
|
+
});
|
127
|
+
|
128
|
+
// Copies an assertion to another item, using the specified assert function
|
129
|
+
function copyAssertion(baseAssertion, item, assert, negate) {
|
130
|
+
var assertion = new Assertion(item);
|
131
|
+
utils.transferFlags(baseAssertion, assertion, false);
|
132
|
+
assertion.assert = assert;
|
133
|
+
if (negate)
|
134
|
+
utils.flag(assertion, "negate", !utils.flag(assertion, "negate"));
|
135
|
+
return assertion;
|
136
|
+
}
|
137
|
+
|
138
|
+
// Define the `something` chainable assertion method and its variants
|
139
|
+
["something", "thing", "item", "one", "some", "any"].forEach(function (methodName) {
|
140
|
+
if (!(methodName in assertionPrototype))
|
141
|
+
Assertion.addChainableMethod(methodName, assertSomething, chainSomething);
|
142
|
+
});
|
143
|
+
}));
|