honkster-screw-unit-server 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/CHANGES +48 -0
  2. data/README.markdown +359 -0
  3. data/Rakefile +43 -0
  4. data/VERSION.yml +5 -0
  5. data/bin/screw_unit +6 -0
  6. data/bin/screw_unit_server +14 -0
  7. data/core/CHANGES +10 -0
  8. data/core/EXAMPLE.html +68 -0
  9. data/core/LICENSE +22 -0
  10. data/core/README.markdown +307 -0
  11. data/core/example/models/cat.js +5 -0
  12. data/core/example/models/man.js +17 -0
  13. data/core/example/spec/matchers/have.js +8 -0
  14. data/core/example/spec/models/cat_spec.js +31 -0
  15. data/core/example/spec/models/man_spec.js +34 -0
  16. data/core/example/spec/spec_helper.js +5 -0
  17. data/core/example/spec/suite.html +25 -0
  18. data/core/lib/jquery-1.3.2.js +4376 -0
  19. data/core/lib/jquery.fn.js +30 -0
  20. data/core/lib/jquery.print.js +109 -0
  21. data/core/lib/screw.behaviors.js +93 -0
  22. data/core/lib/screw.builder.js +95 -0
  23. data/core/lib/screw.css +90 -0
  24. data/core/lib/screw.events.js +45 -0
  25. data/core/lib/screw.matchers.js +244 -0
  26. data/core/spec/behaviors_spec.js +166 -0
  27. data/core/spec/matchers_spec.js +372 -0
  28. data/core/spec/print_spec.js +158 -0
  29. data/core/spec/spec_helper.js +0 -0
  30. data/core/spec/suite.html +19 -0
  31. data/core/spec/with_screw_context_spec.js +9 -0
  32. data/init.rb +0 -0
  33. data/lib/screw_unit.rb +21 -0
  34. data/spec/functional/functional_spec.rb +25 -0
  35. data/spec/functional/functional_spec_helper.rb +42 -0
  36. data/spec/functional/functional_spec_server_starter.rb +68 -0
  37. data/spec/functional_suite.rb +10 -0
  38. data/spec/spec_suite.rb +2 -0
  39. data/standalone.ru +3 -0
  40. data/vendor/js-test-core/CHANGES +31 -0
  41. data/vendor/js-test-core/README +6 -0
  42. data/vendor/js-test-core/Rakefile +73 -0
  43. data/vendor/js-test-core/bin/js-test-client +0 -0
  44. data/vendor/js-test-core/bin/js-test-server +6 -0
  45. data/vendor/js-test-core/lib/js_test_core.rb +38 -0
  46. data/vendor/js-test-core/lib/js_test_core/app.rb +11 -0
  47. data/vendor/js-test-core/lib/js_test_core/client.rb +139 -0
  48. data/vendor/js-test-core/lib/js_test_core/configuration.rb +65 -0
  49. data/vendor/js-test-core/lib/js_test_core/representations.rb +13 -0
  50. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +25 -0
  51. data/vendor/js-test-core/lib/js_test_core/representations/frameworks.rb +3 -0
  52. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +16 -0
  53. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  54. data/vendor/js-test-core/lib/js_test_core/representations/suite.html.rb +57 -0
  55. data/vendor/js-test-core/lib/js_test_core/representations/suites.rb +3 -0
  56. data/vendor/js-test-core/lib/js_test_core/representations/suites/screw_unit.html.rb +81 -0
  57. data/vendor/js-test-core/lib/js_test_core/resources.rb +15 -0
  58. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  59. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +62 -0
  60. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +28 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  63. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +51 -0
  64. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +15 -0
  65. data/vendor/js-test-core/lib/js_test_core/server.rb +84 -0
  66. data/vendor/js-test-core/public/js_test_server.js +541 -0
  67. data/vendor/js-test-core/spec/example_framework/JsTestCore.css +0 -0
  68. data/vendor/js-test-core/spec/example_framework/JsTestCore.js +0 -0
  69. data/vendor/js-test-core/spec/example_framework/subdir/SubDirFile.js +0 -0
  70. data/vendor/js-test-core/spec/example_root/favicon.ico +0 -0
  71. data/vendor/js-test-core/spec/example_root/javascripts/foo.js +3 -0
  72. data/vendor/js-test-core/spec/example_root/javascripts/large_file.js +59 -0
  73. data/vendor/js-test-core/spec/example_root/javascripts/subdir/bar.js +1 -0
  74. data/vendor/js-test-core/spec/example_root/robots.txt +0 -0
  75. data/vendor/js-test-core/spec/example_root/stylesheets/example.css +3 -0
  76. data/vendor/js-test-core/spec/example_spec/custom_dir_and_suite/passing_spec.js +8 -0
  77. data/vendor/js-test-core/spec/example_spec/custom_suite.html +8 -0
  78. data/vendor/js-test-core/spec/example_spec/failing_spec.js +7 -0
  79. data/vendor/js-test-core/spec/example_spec/foo/failing_spec.js +8 -0
  80. data/vendor/js-test-core/spec/example_spec/foo/passing_spec.js +8 -0
  81. data/vendor/js-test-core/spec/example_spec/passing_spec.js +8 -0
  82. data/vendor/js-test-core/spec/functional/functional_spec.rb +25 -0
  83. data/vendor/js-test-core/spec/functional/functional_spec_helper.rb +42 -0
  84. data/vendor/js-test-core/spec/functional/functional_spec_server_starter.rb +77 -0
  85. data/vendor/js-test-core/spec/functional_suite.rb +10 -0
  86. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  87. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  88. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +16 -0
  89. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  90. data/vendor/js-test-core/spec/spec_suite.rb +3 -0
  91. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +196 -0
  93. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +50 -0
  94. data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
  95. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +81 -0
  96. data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
  97. data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
  98. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +149 -0
  99. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +28 -0
  100. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +66 -0
  101. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +30 -0
  102. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  103. data/vendor/js-test-core/standalone.ru +1 -0
  104. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +77 -0
  105. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +5 -0
  106. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +142 -0
  107. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource/path.rb +24 -0
  108. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  109. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  110. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +276 -0
  111. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  112. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
  113. data/vendor/js-test-core/vendor/lucky-luciano/syntax_ideas.txt +34 -0
  114. metadata +201 -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,166 @@
1
+ Screw.Unit(function() {
2
+ var global_before_invoked = false, global_after_invoked = false, screwUnitBeforeAndAfterOrdering = [];
3
+ before(function() { global_before_invoked = true });
4
+ after(function() { global_after_invoked = true });
5
+
6
+ describe('Behaviors', function() {
7
+ describe("level 1", function() {
8
+ before(function() {
9
+ screwUnitBeforeAndAfterOrdering.push("before 1");
10
+ });
11
+
12
+ after(function() {
13
+ screwUnitBeforeAndAfterOrdering.push("after 1");
14
+ });
15
+
16
+ describe("level 2", function() {
17
+ before(function() {
18
+ screwUnitBeforeAndAfterOrdering.push("before 2");
19
+ });
20
+
21
+ after(function() {
22
+ screwUnitBeforeAndAfterOrdering.push("after 2");
23
+ });
24
+ describe("level 3", function() {
25
+ before(function() {
26
+ screwUnitBeforeAndAfterOrdering.push("before 3");
27
+ });
28
+
29
+ after(function() {
30
+ screwUnitBeforeAndAfterOrdering.push("after 3");
31
+ });
32
+
33
+ it("runs", function() {
34
+ screwUnitBeforeAndAfterOrdering.push("spec");
35
+ });
36
+ });
37
+ });
38
+ });
39
+
40
+ describe('#run', function() {
41
+ describe("A describe with a nested describe", function() {
42
+ it("it runs befores outside in, then the spec, then afters inside out", function() {
43
+ expect(screwUnitBeforeAndAfterOrdering).to(equal, [
44
+ "before 1",
45
+ "before 2",
46
+ "before 3",
47
+ "spec",
48
+ "after 3",
49
+ "after 2",
50
+ "after 1"
51
+ ]);
52
+ });
53
+ });
54
+
55
+ describe("elapsed time", function() {
56
+ it("displays the elapsed time after the Suite finishes", function() {
57
+ var status = $(".status");
58
+ status.fn("display");
59
+ var time_elapsed_matches = /([0-9]+\.[0-9]+) seconds/.exec(status.html());
60
+ var time_elapsed = parseFloat(time_elapsed_matches[1]);
61
+ expect(time_elapsed > 0.0).to(be_true);
62
+ });
63
+ });
64
+
65
+ describe("a simple [describe]", function() {
66
+ it("invokes the global [before] before an [it]", function() {
67
+ expect(global_before_invoked).to(equal, true);
68
+ global_before_invoked = false;
69
+ });
70
+
71
+ it("invokes the global [before] before each [it]", function() {
72
+ expect(global_before_invoked).to(equal, true);
73
+ global_after_invoked = false;
74
+ });
75
+
76
+ it("invokes the global [after] after an [it]", function() {
77
+ expect(global_after_invoked).to(equal, true);
78
+ });
79
+ });
80
+
81
+ describe("a [describe] with a [before] and [after] block", function() {
82
+ var before_invoked = false, after_invoked = false;
83
+ before(function() { before_invoked = true });
84
+ after(function() { after_invoked = true });
85
+
86
+ describe('[after] blocks', function() {
87
+ it("does not invoke the [after] until after the first [it]", function() {
88
+ expect(after_invoked).to(equal, false);
89
+ });
90
+
91
+ it("invokes the [after] after the first [it]", function() {
92
+ expect(after_invoked).to(equal, true);
93
+ after_invoked = false;
94
+ });
95
+
96
+ it("invokes the [after] after each [it]", function() {
97
+ expect(after_invoked).to(equal, true);
98
+ });
99
+ });
100
+
101
+ describe('[before] blocks', function() {
102
+ it("invokes the [before] before an it", function() {
103
+ expect(before_invoked).to(equal, true);
104
+ before_invoked = false;
105
+ });
106
+
107
+ it("invokes the [before] before each it", function() {
108
+ expect(before_invoked).to(equal, true);
109
+ });
110
+ });
111
+ });
112
+
113
+ describe("A [describe] with two [before] and two [after] blocks", function() {
114
+ var before_invocations = [], after_invocations = [];
115
+ before(function() { before_invocations.push('before 1') });
116
+ before(function() { before_invocations.push('before 2') });
117
+
118
+ after(function() { after_invocations.push('after 1') });
119
+ after(function() { after_invocations.push('after 2') });
120
+
121
+ it("invokes the [before]s in lexical order before each [it]", function() {
122
+ expect(before_invocations).to(equal, ['before 1', 'before 2']);
123
+ });
124
+
125
+ it("invokes the [afters]s in lexical order after each [it]", function() {
126
+ expect(after_invocations).to(equal, ['after 1', 'after 2']);
127
+ });
128
+ });
129
+
130
+ describe("A describe block with exceptions", function() {
131
+ var after_invoked = false;
132
+ after(function() {
133
+ after_invoked = true;
134
+ });
135
+
136
+ describe("an exception in a test", function() {
137
+ it("fails because it throws an exception", function() {
138
+ throw('an exception');
139
+ });
140
+
141
+ it("invokes [after]s even if the previous [it] raised an exception", function() {
142
+ expect(after_invoked).to(equal, true);
143
+ });
144
+ });
145
+ });
146
+ });
147
+
148
+ describe("#selector", function() {
149
+ describe('a [describe]', function() {
150
+ it('manufactures a CSS selector that uniquely locates the [describe]', function() {
151
+ $('.describe').each(function() {
152
+ expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
153
+ });
154
+ });
155
+ });
156
+
157
+ describe('an [it]', function() {
158
+ it('manufactures a CSS selector that uniquely locates the [it]', function() {
159
+ $('.it').each(function() {
160
+ expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
161
+ });
162
+ });
163
+ });
164
+ });
165
+ });
166
+ });
@@ -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
+ });