pivotal-screw-unit-server 0.5.3
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.
- data/CHANGES +27 -0
- data/README.markdown +354 -0
- data/Rakefile +42 -0
- data/VERSION.yml +4 -0
- data/bin/screw_unit +6 -0
- data/bin/screw_unit_server +20 -0
- data/core/CHANGES +10 -0
- data/core/EXAMPLE.html +68 -0
- data/core/LICENSE +22 -0
- data/core/README.markdown +307 -0
- data/core/example/models/cat.js +5 -0
- data/core/example/models/man.js +17 -0
- data/core/example/spec/matchers/have.js +8 -0
- data/core/example/spec/models/cat_spec.js +31 -0
- data/core/example/spec/models/man_spec.js +34 -0
- data/core/example/spec/spec_helper.js +5 -0
- data/core/example/spec/suite.html +25 -0
- data/core/lib/jquery-1.3.2.js +4376 -0
- data/core/lib/jquery.fn.js +30 -0
- data/core/lib/jquery.print.js +109 -0
- data/core/lib/screw.behaviors.js +93 -0
- data/core/lib/screw.builder.js +95 -0
- data/core/lib/screw.css +90 -0
- data/core/lib/screw.events.js +45 -0
- data/core/lib/screw.matchers.js +244 -0
- data/core/spec/behaviors_spec.js +188 -0
- data/core/spec/matchers_spec.js +372 -0
- data/core/spec/print_spec.js +158 -0
- data/core/spec/spec_helper.js +0 -0
- data/core/spec/suite.html +19 -0
- data/core/spec/with_screw_context_spec.js +9 -0
- data/init.rb +0 -0
- data/lib/screw_unit.rb +23 -0
- data/lib/screw_unit/representations.rb +2 -0
- data/lib/screw_unit/representations/spec.html.rb +117 -0
- data/spec/functional/functional_spec.rb +25 -0
- data/spec/functional/functional_spec_helper.rb +43 -0
- data/spec/functional/functional_spec_server_starter.rb +68 -0
- data/spec/functional_suite.rb +10 -0
- data/spec/spec_suite.rb +3 -0
- data/spec/unit/js_test_core/specs/spec_file_spec.rb +68 -0
- data/spec/unit/unit_spec_helper.rb +51 -0
- data/spec/unit_suite.rb +10 -0
- data/vendor/js-test-core/CHANGES +28 -0
- data/vendor/js-test-core/README +12 -0
- data/vendor/js-test-core/Rakefile +73 -0
- data/vendor/js-test-core/lib/js_test_core.rb +46 -0
- data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/client.rb +129 -0
- data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
- data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
- data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
- data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
- data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
- data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
- data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
- data/vendor/js-test-core/lib/js_test_core/resources.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
- data/vendor/js-test-core/lib/js_test_core/resources/file.rb +62 -0
- data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
- data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
- data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
- data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
- data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
- data/vendor/js-test-core/spec/example_core/subdir/SubDirFile.js +0 -0
- data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
- data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
- data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
- data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
- data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
- data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
- data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
- data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
- data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
- data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
- data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
- data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
- data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
- data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
- data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
- data/vendor/js-test-core/spec/spec_suite.rb +2 -0
- data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
- data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +192 -0
- data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
- data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +81 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/selenium_session_spec.rb +362 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +28 -0
- data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
- data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +28 -0
- data/vendor/js-test-core/spec/unit_suite.rb +10 -0
- data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
- metadata +198 -0
@@ -0,0 +1,244 @@
|
|
1
|
+
Screw.Matchers = (function($) {
|
2
|
+
return matchers = {
|
3
|
+
expect: function(actual) {
|
4
|
+
var funcname = function(f) {
|
5
|
+
var s = f.toString().match(/function (\w*)/)[1];
|
6
|
+
if ((s == null) || (s.length == 0)) return "anonymous";
|
7
|
+
return s;
|
8
|
+
};
|
9
|
+
|
10
|
+
var stacktrace = function() {
|
11
|
+
var s = "";
|
12
|
+
for(var a = arguments.caller; a != null; a = a.caller) {
|
13
|
+
s += funcname(a.callee) + "\n";
|
14
|
+
if (a.caller == a) break;
|
15
|
+
}
|
16
|
+
return s;
|
17
|
+
};
|
18
|
+
|
19
|
+
return {
|
20
|
+
to: function(matcher, expected, not) {
|
21
|
+
var matched = matcher.match(expected, actual);
|
22
|
+
if (not ? matched : !matched) {
|
23
|
+
throw(matcher.failure_message(expected, actual, not));
|
24
|
+
}
|
25
|
+
},
|
26
|
+
|
27
|
+
to_not: function(matcher, expected) {
|
28
|
+
this.to(matcher, expected, true);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
},
|
32
|
+
|
33
|
+
equal: {
|
34
|
+
match: function(expected, actual) {
|
35
|
+
if(expected == actual) return true;
|
36
|
+
if(actual == undefined) return false;
|
37
|
+
|
38
|
+
if (expected instanceof Array) {
|
39
|
+
for (var i = 0; i < actual.length; i++)
|
40
|
+
if (!Screw.Matchers.equal.match(expected[i], actual[i])) return false;
|
41
|
+
return actual.length == expected.length;
|
42
|
+
} else if (expected instanceof Object) {
|
43
|
+
for (var key in expected)
|
44
|
+
if (!this.match(expected[key], actual[key])) return false;
|
45
|
+
for (var key in actual)
|
46
|
+
if (!this.match(actual[key], expected[key])) return false;
|
47
|
+
return true;
|
48
|
+
}
|
49
|
+
return false;
|
50
|
+
},
|
51
|
+
|
52
|
+
failure_message: function(expected, actual, not) {
|
53
|
+
return 'expected ' + $.print(actual) + (not ? ' to not equal ' : ' to equal ') + $.print(expected);
|
54
|
+
}
|
55
|
+
},
|
56
|
+
|
57
|
+
be_gt: {
|
58
|
+
match: function(expected, actual) {
|
59
|
+
return actual > expected;
|
60
|
+
},
|
61
|
+
|
62
|
+
failure_message: function(expected, actual, not) {
|
63
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than ' + $.print(expected);
|
64
|
+
}
|
65
|
+
},
|
66
|
+
|
67
|
+
be_gte: {
|
68
|
+
match: function(expected, actual) {
|
69
|
+
return actual >= expected;
|
70
|
+
},
|
71
|
+
|
72
|
+
failure_message: function(expected, actual, not) {
|
73
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than or equal to ' + $.print(expected);
|
74
|
+
}
|
75
|
+
},
|
76
|
+
|
77
|
+
be_lt: {
|
78
|
+
match: function(expected, actual) {
|
79
|
+
return actual < expected;
|
80
|
+
},
|
81
|
+
|
82
|
+
failure_message: function(expected, actual, not) {
|
83
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than ' + $.print(expected);
|
84
|
+
}
|
85
|
+
},
|
86
|
+
|
87
|
+
be_lte: {
|
88
|
+
match: function(expected, actual) {
|
89
|
+
return actual <= expected;
|
90
|
+
},
|
91
|
+
|
92
|
+
failure_message: function(expected, actual, not) {
|
93
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than or equal to ' + $.print(expected);
|
94
|
+
}
|
95
|
+
},
|
96
|
+
|
97
|
+
match: {
|
98
|
+
match: function(expected, actual) {
|
99
|
+
if (expected.constructor == RegExp)
|
100
|
+
return expected.exec(actual.toString());
|
101
|
+
else
|
102
|
+
return actual.indexOf(expected) > -1;
|
103
|
+
},
|
104
|
+
|
105
|
+
failure_message: function(expected, actual, not) {
|
106
|
+
return 'expected ' + $.print(actual) + (not ? ' to not match ' : ' to match ') + $.print(expected);
|
107
|
+
}
|
108
|
+
},
|
109
|
+
|
110
|
+
be_empty: {
|
111
|
+
match: function(expected, actual) {
|
112
|
+
if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
|
113
|
+
|
114
|
+
return actual.length == 0;
|
115
|
+
},
|
116
|
+
|
117
|
+
failure_message: function(expected, actual, not) {
|
118
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be empty' : ' to be empty');
|
119
|
+
}
|
120
|
+
},
|
121
|
+
|
122
|
+
be_blank: {
|
123
|
+
match: function(expected, actual) {
|
124
|
+
if (actual == undefined) return true;
|
125
|
+
if (typeof(actual) == "string") actual = actual.replace(/^\s*(.*?)\s*$/, "$1");
|
126
|
+
return Screw.Matchers.be_empty.match(expected, actual);
|
127
|
+
},
|
128
|
+
|
129
|
+
failure_message: function(expected, actual, not) {
|
130
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be blank' : ' to be blank');
|
131
|
+
}
|
132
|
+
},
|
133
|
+
|
134
|
+
have_length: {
|
135
|
+
match: function(expected, actual) {
|
136
|
+
if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
|
137
|
+
|
138
|
+
return actual.length == expected;
|
139
|
+
},
|
140
|
+
|
141
|
+
failure_message: function(expected, actual, not) {
|
142
|
+
return 'expected ' + $.print(actual) + (not ? ' to not' : ' to') + ' have length ' + expected;
|
143
|
+
}
|
144
|
+
},
|
145
|
+
|
146
|
+
be_null: {
|
147
|
+
match: function(expected, actual) {
|
148
|
+
return actual == null;
|
149
|
+
},
|
150
|
+
|
151
|
+
failure_message: function(expected, actual, not) {
|
152
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be null' : ' to be null');
|
153
|
+
}
|
154
|
+
},
|
155
|
+
|
156
|
+
be_undefined: {
|
157
|
+
match: function(expected, actual) {
|
158
|
+
return actual == undefined;
|
159
|
+
},
|
160
|
+
|
161
|
+
failure_message: function(expected, actual, not) {
|
162
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be undefined' : ' to be undefined');
|
163
|
+
}
|
164
|
+
},
|
165
|
+
|
166
|
+
be_true: {
|
167
|
+
match: function(expected, actual) {
|
168
|
+
return actual;
|
169
|
+
},
|
170
|
+
|
171
|
+
failure_message: function(expected, actual, not) {
|
172
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be true' : ' to be true');
|
173
|
+
}
|
174
|
+
},
|
175
|
+
|
176
|
+
be_false: {
|
177
|
+
match: function(expected, actual) {
|
178
|
+
return !actual;
|
179
|
+
},
|
180
|
+
|
181
|
+
failure_message: function(expected, actual, not) {
|
182
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be false' : ' to be false');
|
183
|
+
}
|
184
|
+
},
|
185
|
+
|
186
|
+
match_html: {
|
187
|
+
munge: function(mungee) {
|
188
|
+
if (mungee instanceof jQuery) {
|
189
|
+
mungee = mungee.html();
|
190
|
+
} else if (typeof(mungee) == "string") {
|
191
|
+
var span = document.createElement("span");
|
192
|
+
span.innerHTML = mungee;
|
193
|
+
mungee = span.innerHTML;
|
194
|
+
}
|
195
|
+
|
196
|
+
var regEx = /\sjQuery\d+=['"]\d+['"]/g;
|
197
|
+
mungee = mungee.replace(regEx, "");
|
198
|
+
|
199
|
+
return mungee;
|
200
|
+
},
|
201
|
+
|
202
|
+
match: function(expected, actual) {
|
203
|
+
var trimmedExpected = this.munge(expected);
|
204
|
+
var trimmedActual = this.munge(actual);
|
205
|
+
return trimmedActual.indexOf(trimmedExpected) > -1;
|
206
|
+
},
|
207
|
+
|
208
|
+
failure_message: function(expected, actual, not) {
|
209
|
+
var trimmedExpected = this.munge(expected);
|
210
|
+
var trimmedActual = this.munge(actual);
|
211
|
+
return 'expected ' + $.print(trimmedActual, { max_string: 300 }) +
|
212
|
+
(not ? ' to not contain ' : ' to contain ') + $.print(trimmedExpected, { max_string: 300 });
|
213
|
+
}
|
214
|
+
},
|
215
|
+
|
216
|
+
match_selector: {
|
217
|
+
match: function(expected, actual) {
|
218
|
+
if (!(actual instanceof jQuery)) {
|
219
|
+
throw expected.toString() + " must be an instance of jQuery to match against a selector"
|
220
|
+
}
|
221
|
+
|
222
|
+
return actual.is(expected);
|
223
|
+
},
|
224
|
+
|
225
|
+
failure_message: function(expected, actual, not) {
|
226
|
+
return 'expected ' + $.print(actual) + (not ? ' to not match selector ' : ' to match selector ') + expected;
|
227
|
+
}
|
228
|
+
},
|
229
|
+
|
230
|
+
contain_selector: {
|
231
|
+
match: function(expected, actual) {
|
232
|
+
if (!(actual instanceof jQuery)) {
|
233
|
+
throw expected.toString() + " must be an instance of jQuery to match against a selector"
|
234
|
+
}
|
235
|
+
|
236
|
+
return actual.find(expected).length > 0;
|
237
|
+
},
|
238
|
+
|
239
|
+
failure_message: function(expected, actual, not) {
|
240
|
+
return 'expected ' + $.print(actual) + (not ? ' to not contain selector ' : ' to contain selector ') + expected;
|
241
|
+
}
|
242
|
+
}
|
243
|
+
}
|
244
|
+
})(jQuery);
|
@@ -0,0 +1,188 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
var global_before_invoked = false, global_after_invoked = false;
|
3
|
+
before(function() { global_before_invoked = true });
|
4
|
+
after(function() { global_after_invoked = true });
|
5
|
+
|
6
|
+
describe('Behaviors', function() {
|
7
|
+
describe('#run', function() {
|
8
|
+
describe("elapsed time", function() {
|
9
|
+
it("displays the elapsed time after the Suite finishes", function() {
|
10
|
+
var status = $(".status");
|
11
|
+
status.fn("display");
|
12
|
+
var time_elapsed_matches = /([0-9]+\.[0-9]+) seconds/.exec(status.html());
|
13
|
+
var time_elapsed = parseFloat(time_elapsed_matches[1]);
|
14
|
+
expect(time_elapsed > 0.0).to(be_true);
|
15
|
+
});
|
16
|
+
});
|
17
|
+
|
18
|
+
describe("a simple [describe]", function() {
|
19
|
+
it("invokes the global [before] before an [it]", function() {
|
20
|
+
expect(global_before_invoked).to(equal, true);
|
21
|
+
global_before_invoked = false;
|
22
|
+
});
|
23
|
+
|
24
|
+
it("invokes the global [before] before each [it]", function() {
|
25
|
+
expect(global_before_invoked).to(equal, true);
|
26
|
+
global_after_invoked = false;
|
27
|
+
});
|
28
|
+
|
29
|
+
it("invokes the global [after] after an [it]", function() {
|
30
|
+
expect(global_after_invoked).to(equal, true);
|
31
|
+
});
|
32
|
+
});
|
33
|
+
|
34
|
+
describe("a [describe] with a [before] and [after] block", function() {
|
35
|
+
var before_invoked = false, after_invoked = false;
|
36
|
+
before(function() { before_invoked = true });
|
37
|
+
after(function() { after_invoked = true });
|
38
|
+
|
39
|
+
describe('[after] blocks', function() {
|
40
|
+
it("does not invoke the [after] until after the first [it]", function() {
|
41
|
+
expect(after_invoked).to(equal, false);
|
42
|
+
});
|
43
|
+
|
44
|
+
it("invokes the [after] after the first [it]", function() {
|
45
|
+
expect(after_invoked).to(equal, true);
|
46
|
+
after_invoked = false;
|
47
|
+
});
|
48
|
+
|
49
|
+
it("invokes the [after] after each [it]", function() {
|
50
|
+
expect(after_invoked).to(equal, true);
|
51
|
+
});
|
52
|
+
});
|
53
|
+
|
54
|
+
describe('[before] blocks', function() {
|
55
|
+
it("invokes the [before] before an it", function() {
|
56
|
+
expect(before_invoked).to(equal, true);
|
57
|
+
before_invoked = false;
|
58
|
+
});
|
59
|
+
|
60
|
+
it("invokes the [before] before each it", function() {
|
61
|
+
expect(before_invoked).to(equal, true);
|
62
|
+
});
|
63
|
+
});
|
64
|
+
});
|
65
|
+
|
66
|
+
describe("A [describe] with two [before] and two [after] blocks", function() {
|
67
|
+
var before_invocations = [], after_invocations = [];
|
68
|
+
before(function() { before_invocations.push('before 1') });
|
69
|
+
before(function() { before_invocations.push('before 2') });
|
70
|
+
|
71
|
+
after(function() { after_invocations.push('after 1') });
|
72
|
+
after(function() { after_invocations.push('after 2') });
|
73
|
+
|
74
|
+
it("invokes the [before]s in lexical order before each [it]", function() {
|
75
|
+
expect(before_invocations).to(equal, ['before 1', 'before 2']);
|
76
|
+
});
|
77
|
+
|
78
|
+
it("invokes the [afters]s in lexical order after each [it]", function() {
|
79
|
+
expect(after_invocations).to(equal, ['after 1', 'after 2']);
|
80
|
+
});
|
81
|
+
});
|
82
|
+
|
83
|
+
describe("A describe with a nested describe", function() {
|
84
|
+
var before_invocations = [], after_invocations = [];
|
85
|
+
before(function() {
|
86
|
+
before_invocations = [];
|
87
|
+
before_invocations.push("outermost before");
|
88
|
+
});
|
89
|
+
|
90
|
+
after(function() {
|
91
|
+
after_invocations = [];
|
92
|
+
after_invocations.push("outermost after");
|
93
|
+
});
|
94
|
+
|
95
|
+
it("outside a nested [describe], does not invoke any of the nested's [before]s", function() {
|
96
|
+
expect(before_invocations).to(equal, ["outermost before"]);
|
97
|
+
});
|
98
|
+
|
99
|
+
it("outside a nested [describe], does not invoke any of the nested's [after]s", function() {
|
100
|
+
expect(after_invocations).to(equal, ["outermost after"]);
|
101
|
+
});
|
102
|
+
|
103
|
+
describe("a nested [describe]", function() {
|
104
|
+
before(function() {
|
105
|
+
before_invocations.push("inner before");
|
106
|
+
});
|
107
|
+
|
108
|
+
after(function() {
|
109
|
+
after_invocations.push("inner after");
|
110
|
+
});
|
111
|
+
|
112
|
+
it("runs [before]s in the parent [describe] before each [it]", function() {
|
113
|
+
expect(before_invocations).to(equal, ["outermost before", "inner before"]);
|
114
|
+
});
|
115
|
+
|
116
|
+
it("runs [after]s in the parent [describe] after each [it]", function() {
|
117
|
+
expect(after_invocations).to(equal, ["outermost after", "inner after"]);
|
118
|
+
});
|
119
|
+
|
120
|
+
describe("a doubly nested [describe]", function() {
|
121
|
+
before(function() {
|
122
|
+
before_invocations.push('innermost before');
|
123
|
+
});
|
124
|
+
|
125
|
+
after(function() {
|
126
|
+
after_invocations.push('innermost after');
|
127
|
+
});
|
128
|
+
|
129
|
+
describe('[before] blocks', function() {
|
130
|
+
it("runs [before]s in all ancestors before an [it]", function() {
|
131
|
+
expect(before_invocations).to(equal, ["outermost before", "inner before", "innermost before"]);
|
132
|
+
});
|
133
|
+
|
134
|
+
it("runs [before]s in all ancestors before each [it]", function() {
|
135
|
+
expect(before_invocations).to(equal, ["outermost before", "inner before", "innermost before"]);
|
136
|
+
});
|
137
|
+
});
|
138
|
+
|
139
|
+
describe('[after] blocks', function() {
|
140
|
+
it("runs [after]s in all ancestors after an [it]", function() {
|
141
|
+
expect(after_invocations).to(equal, ["outermost after", "inner after", "innermost after"]);
|
142
|
+
});
|
143
|
+
|
144
|
+
it("runs [after]s in all ancestors after each [it]", function() {
|
145
|
+
expect(after_invocations).to(equal, ["outermost after", "inner after", "innermost after"]);
|
146
|
+
});
|
147
|
+
});
|
148
|
+
});
|
149
|
+
});
|
150
|
+
});
|
151
|
+
|
152
|
+
describe("A describe block with exceptions", function() {
|
153
|
+
var after_invoked = false;
|
154
|
+
after(function() {
|
155
|
+
after_invoked = true;
|
156
|
+
});
|
157
|
+
|
158
|
+
describe("an exception in a test", function() {
|
159
|
+
it("fails because it throws an exception", function() {
|
160
|
+
throw('an exception');
|
161
|
+
});
|
162
|
+
|
163
|
+
it("invokes [after]s even if the previous [it] raised an exception", function() {
|
164
|
+
expect(after_invoked).to(equal, true);
|
165
|
+
});
|
166
|
+
});
|
167
|
+
});
|
168
|
+
});
|
169
|
+
|
170
|
+
describe("#selector", function() {
|
171
|
+
describe('a [describe]', function() {
|
172
|
+
it('manufactures a CSS selector that uniquely locates the [describe]', function() {
|
173
|
+
$('.describe').each(function() {
|
174
|
+
expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
|
175
|
+
});
|
176
|
+
});
|
177
|
+
});
|
178
|
+
|
179
|
+
describe('an [it]', function() {
|
180
|
+
it('manufactures a CSS selector that uniquely locates the [it]', function() {
|
181
|
+
$('.it').each(function() {
|
182
|
+
expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
|
183
|
+
});
|
184
|
+
});
|
185
|
+
});
|
186
|
+
});
|
187
|
+
});
|
188
|
+
});
|
@@ -0,0 +1,372 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("Matchers", function() {
|
3
|
+
describe('#equal', function() {
|
4
|
+
it("invokes the provided matcher on a call to expect", function() {
|
5
|
+
expect(true).to(equal, true);
|
6
|
+
expect(true).to_not(equal, false);
|
7
|
+
});
|
8
|
+
|
9
|
+
describe('when actual is an object', function() {
|
10
|
+
describe("when expected has the same keys and values", function() {
|
11
|
+
it("matches successfully", function() {
|
12
|
+
expect({a: 'b', c: 'd'}).to(equal, {a: 'b', c: 'd'});
|
13
|
+
});
|
14
|
+
});
|
15
|
+
|
16
|
+
describe("when expected has different keys and values", function() {
|
17
|
+
it("does not match", function() {
|
18
|
+
expect({a: 'b', c: 'd', e: 'f'}).to_not(equal, {a: 'b', c: 'd', e: 'G'});
|
19
|
+
});
|
20
|
+
});
|
21
|
+
|
22
|
+
describe("when expected is undefined", function() {
|
23
|
+
it("does not match", function() {
|
24
|
+
expect({}).to_not(equal, undefined);
|
25
|
+
});
|
26
|
+
});
|
27
|
+
});
|
28
|
+
|
29
|
+
describe("when actual is undefined", function() {
|
30
|
+
describe("when expected is undefined", function() {
|
31
|
+
it("matches successfully", function() {
|
32
|
+
expect(undefined).to(equal, undefined);
|
33
|
+
});
|
34
|
+
});
|
35
|
+
|
36
|
+
describe("when expected is an empty object", function() {
|
37
|
+
it("does not match", function() {
|
38
|
+
expect(undefined).to_not(equal, {});
|
39
|
+
});
|
40
|
+
});
|
41
|
+
});
|
42
|
+
|
43
|
+
describe('when actual is an array', function() {
|
44
|
+
it("matches Arrays with the same elements", function() {
|
45
|
+
expect([1, 2, 4]).to(equal, [1, 2, 4]);
|
46
|
+
expect([1, 2, 3]).to_not(equal, [3, 2, 1]);
|
47
|
+
});
|
48
|
+
|
49
|
+
it("recursively applies equality to complex elements", function() {
|
50
|
+
expect([{a: 'b'}, {c: 'd'}]).to(equal, [{a: 'b'}, {c: 'd'}]);
|
51
|
+
expect([{a: 'b'}, {c: 'd'}]).to_not(equal, [{a: 'b'}, {c: 'E'}]);
|
52
|
+
});
|
53
|
+
});
|
54
|
+
|
55
|
+
describe("when actual is a hash", function() {
|
56
|
+
it("matches hashes with the same key-value pairs", function() {
|
57
|
+
expect({"a":"b", "c":"d"}).to(equal, {"a":"b", "c":"d"});
|
58
|
+
expect({"a":"b", "c":"e"}).to_not(equal, {"a":"b", "c":"d"});
|
59
|
+
expect({"a":"b", "d":"d"}).to_not(equal, {"a":"b", "c":"d"});
|
60
|
+
});
|
61
|
+
|
62
|
+
it("recursively applies equality to complex hashes", function() {
|
63
|
+
expect({"a":"b", "c": {"e":"f", "g":"h"}}).to(equal, {"a":"b", "c": {"e":"f", "g":"h"}});
|
64
|
+
expect({"a":"b", "c": {"e":"f", "g":"i"}}).to_not(equal, {"a":"b", "c": {"e":"f", "g":"h"}});
|
65
|
+
expect({"a":"b", "c": {"e":"f", "h":"h"}}).to_not(equal, {"a":"b", "c": {"e":"f", "g":"h"}});
|
66
|
+
});
|
67
|
+
});
|
68
|
+
|
69
|
+
describe(".failure_message", function() {
|
70
|
+
it('prints "expected [expected] to (not) be equal [actual]"', function() {
|
71
|
+
var message = null;
|
72
|
+
try { expect(1).to(equal, 2) } catch(e) { message = e }
|
73
|
+
expect(message).to(equal, 'expected 1 to equal 2');
|
74
|
+
|
75
|
+
try { expect(1).to_not(equal, 1) } catch(e) { message = e }
|
76
|
+
expect(message).to(equal, 'expected 1 to not equal 1');
|
77
|
+
});
|
78
|
+
});
|
79
|
+
});
|
80
|
+
|
81
|
+
describe('#match', function() {
|
82
|
+
describe('when actual is a regular expression', function() {
|
83
|
+
it("matches Strings produced by the grammar", function() {
|
84
|
+
expect("The wheels of the bus").to(match, /bus/);
|
85
|
+
expect("The wheels of the bus").to_not(match, /boat/);
|
86
|
+
});
|
87
|
+
});
|
88
|
+
|
89
|
+
describe('when actual is a string', function() {
|
90
|
+
it("matches [expected]s containing [actual]s", function() {
|
91
|
+
expect("The wheels of the bus").to(match, "wheels");
|
92
|
+
expect("The wheels of the bus").to_not(match, "oars");
|
93
|
+
});
|
94
|
+
});
|
95
|
+
|
96
|
+
describe('when actual is an integer', function() {
|
97
|
+
it("matches [expected]s containing [actual]s", function() {
|
98
|
+
expect("1 time").to(match, 1);
|
99
|
+
expect("2 times").to_not(match, 3);
|
100
|
+
});
|
101
|
+
});
|
102
|
+
|
103
|
+
describe(".failure_message", function() {
|
104
|
+
it('prints "expected [actual] to (not) match [expected]', function() {
|
105
|
+
var message = null;
|
106
|
+
try { expect("hello").to(match, "schmello") } catch(e) { message = e }
|
107
|
+
expect(message).to(equal, 'expected "hello" to match "schmello"');
|
108
|
+
|
109
|
+
try { expect("hello").to_not(match, "ello") } catch(e) { message = e }
|
110
|
+
expect(message).to(equal, 'expected "hello" to not match "ello"');
|
111
|
+
});
|
112
|
+
});
|
113
|
+
});
|
114
|
+
|
115
|
+
describe('#be_empty', function() {
|
116
|
+
it("matches Arrays with no elements", function() {
|
117
|
+
expect([]).to(be_empty);
|
118
|
+
expect([1]).to_not(be_empty);
|
119
|
+
});
|
120
|
+
|
121
|
+
describe(".failure_message", function() {
|
122
|
+
it("prints 'expected [actual] to (not) be empty", function() {
|
123
|
+
var message = null;
|
124
|
+
try { expect([1]).to(be_empty) } catch(e) { message = e }
|
125
|
+
expect(message).to(equal, 'expected [ 1 ] to be empty');
|
126
|
+
|
127
|
+
try { expect([]).to_not(be_empty) } catch(e) { message = e }
|
128
|
+
expect(message).to(equal, 'expected [] to not be empty');
|
129
|
+
});
|
130
|
+
});
|
131
|
+
});
|
132
|
+
|
133
|
+
describe('#have_length', function() {
|
134
|
+
it("matches Arrays of the expected length", function() {
|
135
|
+
expect([]).to(have_length, 0);
|
136
|
+
expect([1]).to(have_length, 1);
|
137
|
+
expect([1, 2, 3]).to_not(have_length, 4);
|
138
|
+
});
|
139
|
+
|
140
|
+
describe(".failure_message", function() {
|
141
|
+
it("prints 'expected [actual] to (not) have length [expected]", function() {
|
142
|
+
var message = null;
|
143
|
+
try { expect([1, 2]).to(have_length, 4) } catch(e) { message = e }
|
144
|
+
expect(message).to(equal, 'expected [ 1, 2 ] to have length 4');
|
145
|
+
|
146
|
+
try { expect([1]).to_not(have_length, 1) } catch(e) { message = e }
|
147
|
+
expect(message).to(equal, 'expected [ 1 ] to not have length 1');
|
148
|
+
});
|
149
|
+
});
|
150
|
+
});
|
151
|
+
|
152
|
+
describe('#be_null', function() {
|
153
|
+
it("matches null", function() {
|
154
|
+
expect(null).to(be_null);
|
155
|
+
expect(1).to_not(be_null);
|
156
|
+
});
|
157
|
+
|
158
|
+
describe(".failure_message", function() {
|
159
|
+
it("prints 'expected [actual] to (not) be null", function() {
|
160
|
+
var message = null;
|
161
|
+
try { expect(1).to(be_null) } catch(e) { message = e }
|
162
|
+
expect(message).to(equal, 'expected 1 to be null');
|
163
|
+
|
164
|
+
try { expect(null).to_not(be_null) } catch(e) { message = e }
|
165
|
+
expect(message).to(equal, 'expected null to not be null');
|
166
|
+
});
|
167
|
+
});
|
168
|
+
});
|
169
|
+
|
170
|
+
describe('#be_undefined', function() {
|
171
|
+
it("matches undefined", function() {
|
172
|
+
expect(undefined).to(be_undefined);
|
173
|
+
expect(1).to_not(be_undefined);
|
174
|
+
});
|
175
|
+
|
176
|
+
describe(".failure_message", function() {
|
177
|
+
it("prints 'expected [actual] to (not) be undefined", function() {
|
178
|
+
var message = undefined;
|
179
|
+
try { expect(1).to(be_undefined) } catch(e) { message = e }
|
180
|
+
expect(message).to(equal, 'expected 1 to be undefined');
|
181
|
+
|
182
|
+
try { expect(undefined).to_not(be_undefined) } catch(e) { message = e }
|
183
|
+
expect(message).to(equal, 'expected undefined to not be undefined');
|
184
|
+
});
|
185
|
+
});
|
186
|
+
});
|
187
|
+
|
188
|
+
describe('#be_true', function() {
|
189
|
+
it("matches values that are considered true conditions", function() {
|
190
|
+
expect(true).to(be_true);
|
191
|
+
expect(1).to(be_true);
|
192
|
+
expect(false).to_not(be_true);
|
193
|
+
expect(undefined).to_not(be_true);
|
194
|
+
expect(null).to_not(be_true);
|
195
|
+
});
|
196
|
+
|
197
|
+
describe(".failure_message", function() {
|
198
|
+
it("prints 'expected [actual] to (not) be true", function() {
|
199
|
+
var message = true;
|
200
|
+
try { expect(false).to(be_true) } catch(e) { message = e }
|
201
|
+
expect(message).to(equal, 'expected false to be true');
|
202
|
+
|
203
|
+
try { expect(true).to_not(be_true) } catch(e) { message = e }
|
204
|
+
expect(message).to(equal, 'expected true to not be true');
|
205
|
+
});
|
206
|
+
});
|
207
|
+
});
|
208
|
+
|
209
|
+
describe('#be_false', function() {
|
210
|
+
it("matches values that are considered false conditions", function() {
|
211
|
+
expect(false).to(be_false);
|
212
|
+
expect(undefined).to(be_false);
|
213
|
+
expect(null).to(be_false);
|
214
|
+
expect(true).to_not(be_false);
|
215
|
+
expect(1).to_not(be_false);
|
216
|
+
});
|
217
|
+
|
218
|
+
describe(".failure_message", function() {
|
219
|
+
it("prints 'expected [actual] to (not) be false", function() {
|
220
|
+
var message = false;
|
221
|
+
try { expect(true).to(be_false) } catch(e) { message = e }
|
222
|
+
expect(message).to(equal, 'expected true to be false');
|
223
|
+
|
224
|
+
try { expect(false).to_not(be_false) } catch(e) { message = e }
|
225
|
+
expect(message).to(equal, 'expected false to not be false');
|
226
|
+
});
|
227
|
+
});
|
228
|
+
});
|
229
|
+
|
230
|
+
describe('#match_selector', function() {
|
231
|
+
var elt;
|
232
|
+
before(function() {
|
233
|
+
elt = $("<div class='foo'></div>");
|
234
|
+
});
|
235
|
+
|
236
|
+
it("matches a jQuery element against the expected selector", function() {
|
237
|
+
expect(elt).to(match_selector, 'div.foo');
|
238
|
+
expect(elt).to_not(match_selector, 'div.bar');
|
239
|
+
});
|
240
|
+
|
241
|
+
describe(".failure_message", function() {
|
242
|
+
it("prints 'expected [actual] to (not) match selector [expected]", function() {
|
243
|
+
var message = false;
|
244
|
+
try { expect(elt).to(match_selector, 'div.bar') } catch(e) { message = e }
|
245
|
+
expect(message).to(equal, 'expected $([ <div class="foo"> ]) to match selector div.bar');
|
246
|
+
|
247
|
+
try { expect(elt).to_not(match_selector, 'div.foo') } catch(e) { message = e }
|
248
|
+
expect(message).to(equal, 'expected $([ <div class="foo"> ]) to not match selector div.foo');
|
249
|
+
});
|
250
|
+
});
|
251
|
+
});
|
252
|
+
|
253
|
+
describe('#contain_selector', function() {
|
254
|
+
var elt;
|
255
|
+
before(function() {
|
256
|
+
elt = $("<div><div class='foo'></div></div>");
|
257
|
+
});
|
258
|
+
|
259
|
+
it("matches a jQuery element against the expected selector", function() {
|
260
|
+
expect(elt).to(contain_selector, 'div.foo');
|
261
|
+
expect(elt).to_not(contain_selector, 'div.bar');
|
262
|
+
});
|
263
|
+
|
264
|
+
describe(".failure_message", function() {
|
265
|
+
it("prints 'expected [actual] to (not) match selector [expected]", function() {
|
266
|
+
var message = false;
|
267
|
+
try { expect(elt).to(contain_selector, 'div.bar') } catch(e) { message = e }
|
268
|
+
expect(message).to(equal, 'expected $([ <div> ]) to contain selector div.bar');
|
269
|
+
|
270
|
+
try { expect(elt).to_not(contain_selector, 'div.foo') } catch(e) { message = e }
|
271
|
+
expect(message).to(equal, 'expected $([ <div> ]) to not contain selector div.foo');
|
272
|
+
});
|
273
|
+
});
|
274
|
+
});
|
275
|
+
|
276
|
+
describe('#be_gt', function() {
|
277
|
+
it('matches integers greater than the expected value', function() {
|
278
|
+
expect(2).to(be_gt, 1);
|
279
|
+
expect(1).to(be_gt, 0);
|
280
|
+
expect(0).to(be_gt, -1);
|
281
|
+
expect(0).to_not(be_gt, 0);
|
282
|
+
expect(-1).to_not(be_gt, 0);
|
283
|
+
expect(0).to_not(be_gt, 1);
|
284
|
+
expect(1).to_not(be_gt, 5);
|
285
|
+
});
|
286
|
+
|
287
|
+
describe(".failure_message", function() {
|
288
|
+
it('prints "expected [expected] to (not) be greater than [actual]"', function() {
|
289
|
+
var message = null;
|
290
|
+
try { expect(1).to(be_gt, 2) } catch(e) { message = e }
|
291
|
+
expect(message).to(equal, 'expected 1 to be greater than 2');
|
292
|
+
|
293
|
+
try { expect(2).to_not(be_gt, 1) } catch(e) { message = e }
|
294
|
+
expect(message).to(equal, 'expected 2 to not be greater than 1');
|
295
|
+
});
|
296
|
+
});
|
297
|
+
});
|
298
|
+
|
299
|
+
describe('#be_gte', function() {
|
300
|
+
it('matches integers greater than or equal to the expected value', function() {
|
301
|
+
expect(2).to(be_gte, 1);
|
302
|
+
expect(1).to(be_gte, 0);
|
303
|
+
expect(0).to(be_gte, -1);
|
304
|
+
expect(-1).to(be_gte, -1);
|
305
|
+
expect(0).to(be_gte, 0);
|
306
|
+
expect(1).to(be_gte, 1);
|
307
|
+
expect(-1).to_not(be_gte, 0);
|
308
|
+
expect(0).to_not(be_gte, 1);
|
309
|
+
expect(1).to_not(be_gte, 5);
|
310
|
+
});
|
311
|
+
|
312
|
+
describe(".failure_message", function() {
|
313
|
+
it('prints "expected [expected] to (not) be greater than or equal to [actual]"', function() {
|
314
|
+
var message = null;
|
315
|
+
try { expect(1).to(be_gte, 2) } catch(e) { message = e }
|
316
|
+
expect(message).to(equal, 'expected 1 to be greater than or equal to 2');
|
317
|
+
|
318
|
+
try { expect(2).to_not(be_gte, 1) } catch(e) { message = e }
|
319
|
+
expect(message).to(equal, 'expected 2 to not be greater than or equal to 1');
|
320
|
+
});
|
321
|
+
});
|
322
|
+
});
|
323
|
+
|
324
|
+
describe('#be_lt', function() {
|
325
|
+
it('matches integers less than the expected value', function() {
|
326
|
+
expect(1).to(be_lt, 2);
|
327
|
+
expect(0).to(be_lt, 1);
|
328
|
+
expect(-1).to(be_lt, 0);
|
329
|
+
expect(0).to_not(be_lt, 0);
|
330
|
+
expect(0).to_not(be_lt, -1);
|
331
|
+
expect(1).to_not(be_lt, 0);
|
332
|
+
expect(5).to_not(be_lt, 1);
|
333
|
+
});
|
334
|
+
|
335
|
+
describe(".failure_message", function() {
|
336
|
+
it('prints "expected [expected] to (not) be less than [actual]"', function() {
|
337
|
+
var message = null;
|
338
|
+
try { expect(2).to(be_lt, 1) } catch(e) { message = e }
|
339
|
+
expect(message).to(equal, 'expected 2 to be less than 1');
|
340
|
+
|
341
|
+
try { expect(1).to_not(be_lt, 2) } catch(e) { message = e }
|
342
|
+
expect(message).to(equal, 'expected 1 to not be less than 2');
|
343
|
+
});
|
344
|
+
});
|
345
|
+
});
|
346
|
+
|
347
|
+
describe('#be_lte', function() {
|
348
|
+
it('matches integers less than or equal to the expected value', function() {
|
349
|
+
expect(1).to(be_lte, 2);
|
350
|
+
expect(0).to(be_lte, 1);
|
351
|
+
expect(-1).to(be_lte, 0);
|
352
|
+
expect(-1).to(be_lte, -1);
|
353
|
+
expect(0).to(be_lte, 0);
|
354
|
+
expect(1).to(be_lte, 1);
|
355
|
+
expect(0).to_not(be_lte, -1);
|
356
|
+
expect(1).to_not(be_lte, 0);
|
357
|
+
expect(5).to_not(be_lte, 1);
|
358
|
+
});
|
359
|
+
|
360
|
+
describe(".failure_message", function() {
|
361
|
+
it('prints "expected [expected] to (not) be less than or equal to [actual]"', function() {
|
362
|
+
var message = null;
|
363
|
+
try { expect(2).to(be_lte, 1) } catch(e) { message = e }
|
364
|
+
expect(message).to(equal, 'expected 2 to be less than or equal to 1');
|
365
|
+
|
366
|
+
try { expect(1).to_not(be_lte, 2) } catch(e) { message = e }
|
367
|
+
expect(message).to(equal, 'expected 1 to not be less than or equal to 2');
|
368
|
+
});
|
369
|
+
});
|
370
|
+
});
|
371
|
+
});
|
372
|
+
});
|