konacha-chai-matchers 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSIONS +1 -1
- data/lib/konacha-chai-matchers/version.rb +1 -1
- data/vendor/assets/javascripts/chai-things.js +32 -21
- metadata +3 -9
data/VERSIONS
CHANGED
@@ -14,23 +14,31 @@
|
|
14
14
|
|
15
15
|
var Assertion = chai.Assertion,
|
16
16
|
assertionPrototype = Assertion.prototype,
|
17
|
-
expect = chai.expect
|
17
|
+
expect = chai.expect,
|
18
|
+
containPropertyDesc = Object.getOwnPropertyDescriptor(assertionPrototype, 'contain');
|
19
|
+
Object.defineProperty(assertionPrototype, 'contains', containPropertyDesc);
|
20
|
+
Object.defineProperty(assertionPrototype, 'includes', containPropertyDesc);
|
18
21
|
|
19
22
|
// Handles the `something` chain property
|
20
23
|
function chainSomething() {
|
21
24
|
// `include` or `contains` should have been called before
|
22
25
|
if (!utils.flag(this, "contains"))
|
23
26
|
throw new Error("cannot use something without include or contains");
|
24
|
-
//
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
// Flag that this is a `something` chain
|
28
|
+
var lastSomething = this, newSomething = {};
|
29
|
+
while (utils.flag(lastSomething, "something")) {
|
30
|
+
lastSomething = utils.flag(lastSomething, "something");
|
31
|
+
}
|
32
|
+
// Transfer all the flags to the new `something` and remove them from `this`
|
33
|
+
utils.transferFlags(this, newSomething, false);
|
34
|
+
for (var prop in this.__flags)
|
35
|
+
if (!/^(?:something|object|ssfi|message)$/.test(prop))
|
36
|
+
delete this.__flags[prop];
|
37
|
+
|
38
|
+
// Add the `newSomething` to the `lastSomething` in the chain.
|
39
|
+
utils.flag(lastSomething, "something", newSomething);
|
40
|
+
// Clear the `something` flag from `newSomething`.
|
41
|
+
utils.flag(newSomething, "something", false);
|
34
42
|
}
|
35
43
|
|
36
44
|
// Performs the `something()` assertion
|
@@ -38,7 +46,8 @@
|
|
38
46
|
// Undo the flags set by the `something` chain property
|
39
47
|
var somethingFlags = utils.flag(this, "something");
|
40
48
|
utils.flag(this, "something", false);
|
41
|
-
|
49
|
+
if (somethingFlags)
|
50
|
+
utils.transferFlags(somethingFlags, this, true);
|
42
51
|
|
43
52
|
// The assertion's object for `something` should be array-like
|
44
53
|
var object = utils.flag(this, "object");
|
@@ -62,13 +71,13 @@
|
|
62
71
|
// Override all methods to react on a possible `something` in the chain
|
63
72
|
methodNames.forEach(function (methodName) {
|
64
73
|
Assertion.overwriteMethod(methodName, function (_super) {
|
65
|
-
return function () {
|
74
|
+
return function somethingMethod() {
|
66
75
|
// Return if no `something` has been used in the chain
|
67
76
|
var somethingFlags = utils.flag(this, "something");
|
68
77
|
if (!somethingFlags)
|
69
78
|
return _super.apply(this, arguments);
|
70
|
-
//
|
71
|
-
utils.flag(this, "something",
|
79
|
+
// Use the nested `something` flag as the new `something` flag for this.
|
80
|
+
utils.flag(this, "something", utils.flag(somethingFlags, "something"));
|
72
81
|
|
73
82
|
// The assertion's object for `something` should be array-like
|
74
83
|
var arrayObject = utils.flag(this, "object");
|
@@ -77,7 +86,7 @@
|
|
77
86
|
expect(length).to.be.a("number", "something object length");
|
78
87
|
|
79
88
|
// In the negative case, an empty array means success
|
80
|
-
var negate = somethingFlags
|
89
|
+
var negate = utils.flag(somethingFlags, "negate");
|
81
90
|
if (negate && !length)
|
82
91
|
return;
|
83
92
|
// In the positive case, the array should not be empty
|
@@ -91,17 +100,19 @@
|
|
91
100
|
var item = arrayObject[i],
|
92
101
|
itemAssertion = copyAssertion(this, item, somethingAssert);
|
93
102
|
assertionError = null;
|
94
|
-
try {
|
103
|
+
try { somethingMethod.apply(itemAssertion, arguments); }
|
95
104
|
catch (error) { assertionError = error; }
|
96
105
|
// If the element satisfies the assertion
|
97
106
|
if (!assertionError) {
|
98
107
|
// In case the base assertion is negated, a satisfying element
|
99
108
|
// means the base assertion ("no element must satisfy x") fails
|
100
109
|
if (negate) {
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
110
|
+
if (!utils.flag(somethingFlags, "something")) {
|
111
|
+
// If we have no child `something`s then assert the negated item assertion, which should fail and throw an error
|
112
|
+
var negItemAssertion = copyAssertion(this, item, somethingAssert, true);
|
113
|
+
somethingMethod.apply(negItemAssertion, arguments);
|
114
|
+
}
|
115
|
+
// Throw here if we have a child `something`, or, for some reason, the negated item assertion didn't throw
|
105
116
|
new Assertion(arrayObject).assert(false,
|
106
117
|
"expected no element of #{this} to satisfy the assertion");
|
107
118
|
}
|
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.1.
|
4
|
+
version: 0.1.2
|
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-
|
12
|
+
date: 2013-03-27 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:
|
@@ -59,21 +59,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
hash: 567893281
|
65
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
63
|
none: false
|
67
64
|
requirements:
|
68
65
|
- - ! '>='
|
69
66
|
- !ruby/object:Gem::Version
|
70
67
|
version: '0'
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
hash: 567893281
|
74
68
|
requirements: []
|
75
69
|
rubyforge_project: konacha-chai-matchers
|
76
|
-
rubygems_version: 1.8.
|
70
|
+
rubygems_version: 1.8.15
|
77
71
|
signing_key:
|
78
72
|
specification_version: 3
|
79
73
|
summary: Chai.js plugins collection for Konacha
|