Repository navigation
Expand file tree
/
Copy pathSpicyEnough.js
More file actions
75 lines (66 loc) · 2.09 KB
/
Copy pathSpicyEnough.js
File metadata and controls
75 lines (66 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* When using SpicyEnough, always start with SpicyEnough().
* This ensures that you're not using stale tests. Blech!
* @class
* @namespace SpicyEnough
* @param {String} description A description of the test.
* @param {Function} testing The function to test.
*/
function SpicyEnough(description, testing) {
return new SpiceTest(description, testing);
}
/**
* This is where testing is really done.
* @class
* @namespace SpiceTest
* @param {String} description A description of the test.
* @param {Function} testing The function to test.
*/
function SpiceTest(description, testing) {
this.version = '0.1';
this.description = description;
this.testing = testing;
this.result = this.testing();
}
SpiceTest.prototype.log = function log(pass, error) {
if (pass === false) {
Log("Failed: " + this.description +
((typeof error !== 'undefined') ? "\nError: " + error : ""));
return Stop();
}
Log("Passed.");
};
SpiceTest.prototype.equals = function equals(assertion) {
this.log(this.result === assertion);
};
SpiceTest.prototype.notEquals = function notEquals(assertion) {
this.log(this.result !== assertion);
};
SpiceTest.prototype.greaterThan = function greaterThan(assertion) {
this.log(this.result > assertion);
};
SpiceTest.prototype.greaterThanOrEqualTo =
function greaterThanOrEqualTo(assertion) {
this.log(this.result >= assertion);
};
SpiceTest.prototype.lessThan = function lessThan(assertion) {
this.log(this.result < assertion);
};
SpiceTest.prototype.lessThanOrEqualTo =
function lessThanOrEqualTo(assertion) {
this.log(this.result <= assertion);
};
SpiceTest.prototype.hasProperties = function hasProperties(assertion) {
if (assertion instanceof Array) {
for (var i = 0; i < assertion.length; i++) {
if (typeof this.result[assertion[i]] === 'undefined')
return this.log(false, "Missing property \"" + assertion[i] + "\"");
}
} else {
for (var property in assertion) {
if (typeof this.result[property] === 'undefined')
return this.log(false, "Missing property \"" + property + "\"");
}
}
this.log(true);
};