konacha-chai-matchers 0.0.12 → 0.0.13
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,71 +1,86 @@
|
|
1
|
+
// Generated by CoffeeScript 1.3.3
|
1
2
|
(function() {
|
2
|
-
var
|
3
|
-
__slice = Array.prototype.slice;
|
3
|
+
var __slice = [].slice;
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if (typeof
|
9
|
-
return
|
5
|
+
(function(name, context, factory) {
|
6
|
+
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
|
7
|
+
return module.exports = factory();
|
8
|
+
} else if (typeof define === "function" && define.amd) {
|
9
|
+
return define(function() {
|
10
|
+
return factory();
|
11
|
+
});
|
10
12
|
} else {
|
11
|
-
return
|
13
|
+
return context[name] = factory();
|
12
14
|
}
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if (
|
19
|
-
|
20
|
-
}
|
21
|
-
|
22
|
-
throw "Factory " + factoryName + " is already defined";
|
23
|
-
}
|
24
|
-
return this.factories[factoryName] = {
|
25
|
-
sequences: {},
|
26
|
-
factory: builder
|
27
|
-
};
|
28
|
-
},
|
29
|
-
create: function() {
|
30
|
-
var args, f, factoryName, nameWithTraits, obj, r, traits;
|
31
|
-
nameWithTraits = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
32
|
-
traits = nameWithTraits.split('-');
|
33
|
-
factoryName = traits.pop();
|
34
|
-
if (this.factories[factoryName] == null) {
|
35
|
-
throw "Factory " + factoryName + " does not exist";
|
15
|
+
})('Factory', this, function() {
|
16
|
+
var Factory, sequencer;
|
17
|
+
sequencer = function(property) {
|
18
|
+
var value;
|
19
|
+
value = this.sequences[property] != null ? this.sequences[property] += 1 : this.sequences[property] = 0;
|
20
|
+
if (typeof property === 'function') {
|
21
|
+
return property(value);
|
22
|
+
} else {
|
23
|
+
return value;
|
36
24
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
is: function(name) {
|
44
|
-
return ~this.traits.indexOf(name);
|
45
|
-
},
|
46
|
-
trait: function() {
|
47
|
-
var name, names, _i, _len, _ref;
|
48
|
-
names = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
49
|
-
_ref = this.traits;
|
50
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
51
|
-
name = _ref[_i];
|
52
|
-
if (~names.indexOf(name)) return name;
|
53
|
-
}
|
54
|
-
},
|
55
|
-
sample: function() {
|
56
|
-
var values;
|
57
|
-
values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
58
|
-
return values[Math.floor(Math.random() * values.length)];
|
25
|
+
};
|
26
|
+
Factory = {
|
27
|
+
factories: {},
|
28
|
+
define: function(factoryName, builder) {
|
29
|
+
if (factoryName.indexOf('-') > 0) {
|
30
|
+
throw "Factory name '" + factoryName + "' can't use - in name. It clashes with the traits construct";
|
59
31
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
32
|
+
if (this.factories[factoryName] != null) {
|
33
|
+
throw "Factory " + factoryName + " is already defined";
|
34
|
+
}
|
35
|
+
return this.factories[factoryName] = {
|
36
|
+
sequences: {},
|
37
|
+
factory: builder
|
38
|
+
};
|
39
|
+
},
|
40
|
+
create: function() {
|
41
|
+
var args, f, factoryName, nameWithTraits, obj, r, traits;
|
42
|
+
nameWithTraits = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
43
|
+
traits = nameWithTraits.split('-');
|
44
|
+
factoryName = traits.pop();
|
45
|
+
if (this.factories[factoryName] == null) {
|
46
|
+
throw "Factory " + factoryName + " does not exist";
|
47
|
+
}
|
48
|
+
f = this.factories[factoryName];
|
49
|
+
obj = {
|
50
|
+
sequences: f.sequences,
|
51
|
+
factory: f.factory,
|
52
|
+
sequence: sequencer,
|
53
|
+
traits: traits,
|
54
|
+
is: function(name) {
|
55
|
+
return ~this.traits.indexOf(name);
|
56
|
+
},
|
57
|
+
trait: function() {
|
58
|
+
var name, names, _i, _len, _ref;
|
59
|
+
names = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
60
|
+
_ref = this.traits;
|
61
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
62
|
+
name = _ref[_i];
|
63
|
+
if (~names.indexOf(name)) {
|
64
|
+
return name;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
},
|
68
|
+
sample: function() {
|
69
|
+
var values;
|
70
|
+
values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
71
|
+
return values[Math.floor(Math.random() * values.length)];
|
72
|
+
}
|
73
|
+
};
|
74
|
+
r = obj.factory.apply(obj, args);
|
75
|
+
f.sequences = obj.sequences;
|
76
|
+
obj = null;
|
77
|
+
return r;
|
78
|
+
},
|
79
|
+
resetFactories: function() {
|
80
|
+
return this.factories = [];
|
81
|
+
}
|
82
|
+
};
|
83
|
+
return Factory;
|
84
|
+
});
|
70
85
|
|
71
86
|
}).call(this);
|