screw-unit 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/CHANGES +11 -0
  2. data/README.markdown +354 -0
  3. data/Rakefile +40 -0
  4. data/bin/screw_unit +6 -0
  5. data/bin/screw_unit_server +10 -0
  6. data/core/EXAMPLE.html +68 -0
  7. data/core/LICENSE +22 -0
  8. data/core/README.markdown +307 -0
  9. data/core/example/models/cat.js +5 -0
  10. data/core/example/models/man.js +17 -0
  11. data/core/example/spec/matchers/have.js +8 -0
  12. data/core/example/spec/models/cat_spec.js +31 -0
  13. data/core/example/spec/models/man_spec.js +34 -0
  14. data/core/example/spec/spec_helper.js +5 -0
  15. data/core/example/spec/suite.html +25 -0
  16. data/core/lib/jquery-1.2.6.js +3549 -0
  17. data/core/lib/jquery.fn.js +29 -0
  18. data/core/lib/jquery.print.js +109 -0
  19. data/core/lib/screw.assets.js +36 -0
  20. data/core/lib/screw.behaviors.js +91 -0
  21. data/core/lib/screw.builder.js +80 -0
  22. data/core/lib/screw.css +90 -0
  23. data/core/lib/screw.events.js +44 -0
  24. data/core/lib/screw.matchers.js +145 -0
  25. data/core/lib/screw.server.js +21 -0
  26. data/core/spec/behaviors_spec.js +178 -0
  27. data/core/spec/matchers_spec.js +237 -0
  28. data/core/spec/print_spec.js +152 -0
  29. data/core/spec/spec_helper.js +0 -0
  30. data/core/spec/suite.html +18 -0
  31. data/init.rb +0 -0
  32. data/lib/screw_unit.rb +26 -0
  33. data/lib/screw_unit/resources.rb +2 -0
  34. data/lib/screw_unit/resources/spec.rb +38 -0
  35. data/spec/functional/functional_spec.rb +25 -0
  36. data/spec/functional/functional_spec_helper.rb +55 -0
  37. data/spec/functional_suite.rb +10 -0
  38. data/spec/spec_suite.rb +3 -0
  39. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +39 -0
  40. data/spec/unit/js_test_core/specs/spec_file_spec.rb +35 -0
  41. data/spec/unit/unit_spec_helper.rb +120 -0
  42. data/spec/unit_suite.rb +10 -0
  43. data/vendor/js-test-core/CHANGES +15 -0
  44. data/vendor/js-test-core/README +12 -0
  45. data/vendor/js-test-core/Rakefile +72 -0
  46. data/vendor/js-test-core/lib/js_test_core.rb +38 -0
  47. data/vendor/js-test-core/lib/js_test_core/client.rb +114 -0
  48. data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
  49. data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
  50. data/vendor/js-test-core/lib/js_test_core/rack.rb +2 -0
  51. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +5 -0
  52. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +22 -0
  53. data/vendor/js-test-core/lib/js_test_core/resources.rb +10 -0
  54. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +67 -0
  55. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +49 -0
  56. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +11 -0
  57. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +105 -0
  58. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +46 -0
  59. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +17 -0
  60. data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +40 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +17 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +63 -0
  63. data/vendor/js-test-core/lib/js_test_core/selenium.rb +2 -0
  64. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +5 -0
  65. data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
  66. data/vendor/js-test-core/lib/js_test_core/server.rb +50 -0
  67. data/vendor/js-test-core/lib/js_test_core/thin.rb +3 -0
  68. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +9 -0
  69. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +8 -0
  70. data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
  71. data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
  72. data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
  73. data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
  74. data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
  75. data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
  76. data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
  77. data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
  78. data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
  79. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
  80. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
  81. data/vendor/js-test-core/spec/spec_suite.rb +2 -0
  82. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  83. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +166 -0
  84. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +45 -0
  85. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +52 -0
  86. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +16 -0
  87. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +128 -0
  88. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +283 -0
  89. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +105 -0
  90. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +42 -0
  91. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +82 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +86 -0
  93. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +32 -0
  94. data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  95. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +117 -0
  96. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +6 -0
  97. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +134 -0
  98. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  99. data/vendor/js-test-core/vendor/thin-rest/CHANGES +2 -0
  100. data/vendor/js-test-core/vendor/thin-rest/README +0 -0
  101. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +9 -0
  102. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +116 -0
  103. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +3 -0
  104. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +21 -0
  105. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +104 -0
  106. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource_invalid.rb +4 -0
  107. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +5 -0
  108. data/vendor/js-test-core/vendor/thin-rest/spec/spec_suite.rb +5 -0
  109. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +207 -0
  110. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resource_spec.rb +127 -0
  111. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +124 -0
  112. metadata +210 -0
@@ -0,0 +1,145 @@
1
+ Screw.Matchers = (function($) {
2
+ return matchers = {
3
+ expect: function(actual) {
4
+ return {
5
+ to: function(matcher, expected, not) {
6
+ var matched = matcher.match(expected, actual);
7
+ if (not ? matched : !matched) {
8
+ throw(matcher.failure_message(expected, actual, not));
9
+ }
10
+ },
11
+
12
+ to_not: function(matcher, expected) {
13
+ this.to(matcher, expected, true);
14
+ }
15
+ }
16
+ },
17
+
18
+ equal: {
19
+ match: function(expected, actual) {
20
+ if (expected instanceof Array) {
21
+ for (var i = 0; i < actual.length; i++)
22
+ if (!Screw.Matchers.equal.match(expected[i], actual[i])) return false;
23
+ return actual.length == expected.length;
24
+ } else if (expected instanceof Object) {
25
+ for (var key in expected)
26
+ if (expected[key] != actual[key]) return false;
27
+ for (var key in actual)
28
+ if (actual[key] != expected[key]) return false;
29
+ return true;
30
+ } else {
31
+ return expected == actual;
32
+ }
33
+ },
34
+
35
+ failure_message: function(expected, actual, not) {
36
+ return 'expected ' + $.print(actual) + (not ? ' to not equal ' : ' to equal ') + $.print(expected);
37
+ }
38
+ },
39
+
40
+ match: {
41
+ match: function(expected, actual) {
42
+ if (expected.constructor == RegExp)
43
+ return expected.exec(actual.toString());
44
+ else
45
+ return actual.indexOf(expected) > -1;
46
+ },
47
+
48
+ failure_message: function(expected, actual, not) {
49
+ return 'expected ' + $.print(actual) + (not ? ' to not match ' : ' to match ') + $.print(expected);
50
+ }
51
+ },
52
+
53
+ be_empty: {
54
+ match: function(expected, actual) {
55
+ if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
56
+
57
+ return actual.length == 0;
58
+ },
59
+
60
+ failure_message: function(expected, actual, not) {
61
+ return 'expected ' + $.print(actual) + (not ? ' to not be empty' : ' to be empty');
62
+ }
63
+ },
64
+
65
+ have_length: {
66
+ match: function(expected, actual) {
67
+ if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
68
+
69
+ return actual.length == expected;
70
+ },
71
+
72
+ failure_message: function(expected, actual, not) {
73
+ return 'expected ' + $.print(actual) + (not ? ' to not' : ' to') + ' have length ' + expected;
74
+ }
75
+ },
76
+
77
+ be_null: {
78
+ match: function(expected, actual) {
79
+ return actual == null;
80
+ },
81
+
82
+ failure_message: function(expected, actual, not) {
83
+ return 'expected ' + $.print(actual) + (not ? ' to not be null' : ' to be null');
84
+ }
85
+ },
86
+
87
+ be_undefined: {
88
+ match: function(expected, actual) {
89
+ return actual == undefined;
90
+ },
91
+
92
+ failure_message: function(expected, actual, not) {
93
+ return 'expected ' + $.print(actual) + (not ? ' to not be undefined' : ' to be undefined');
94
+ }
95
+ },
96
+
97
+ be_true: {
98
+ match: function(expected, actual) {
99
+ return actual;
100
+ },
101
+
102
+ failure_message: function(expected, actual, not) {
103
+ return 'expected ' + $.print(actual) + (not ? ' to not be true' : ' to be true');
104
+ }
105
+ },
106
+
107
+ be_false: {
108
+ match: function(expected, actual) {
109
+ return !actual;
110
+ },
111
+
112
+ failure_message: function(expected, actual, not) {
113
+ return 'expected ' + $.print(actual) + (not ? ' to not be false' : ' to be false');
114
+ }
115
+ },
116
+
117
+ match_selector: {
118
+ match: function(expected, actual) {
119
+ if (!(actual instanceof jQuery)) {
120
+ throw expected.toString() + " must be an instance of jQuery to match against a selector"
121
+ }
122
+
123
+ return actual.is(expected);
124
+ },
125
+
126
+ failure_message: function(expected, actual, not) {
127
+ return 'expected ' + $.print(actual) + (not ? ' to not match selector ' : ' to match selector ') + expected;
128
+ }
129
+ },
130
+
131
+ contain_selector: {
132
+ match: function(expected, actual) {
133
+ if (!(actual instanceof jQuery)) {
134
+ throw expected.toString() + " must be an instance of jQuery to match against a selector"
135
+ }
136
+
137
+ return actual.find(expected).length > 0;
138
+ },
139
+
140
+ failure_message: function(expected, actual, not) {
141
+ return 'expected ' + $.print(actual) + (not ? ' to not contain selector ' : ' to contain selector ') + expected;
142
+ }
143
+ }
144
+ }
145
+ })(jQuery);
@@ -0,0 +1,21 @@
1
+ (function($) {
2
+ var ajax = $.ajax;
3
+ $(Screw).bind('after', function() {
4
+ var error_text = $(".error").map(function(i, element) {
5
+ return element.innerHTML;
6
+ }).get().join("\n");
7
+
8
+ var suite_id;
9
+ if(top.runOptions) {
10
+ suite_id = top.runOptions.getSessionId();
11
+ } else {
12
+ suite_id = 'user';
13
+ }
14
+
15
+ ajax({
16
+ type: "POST",
17
+ url: '/suites/' + suite_id + '/finish',
18
+ data: {"text": error_text}
19
+ });
20
+ });
21
+ })(jQuery);
@@ -0,0 +1,178 @@
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("a simple [describe]", function() {
9
+ it("invokes the global [before] before an [it]", function() {
10
+ expect(global_before_invoked).to(equal, true);
11
+ global_before_invoked = false;
12
+ });
13
+
14
+ it("invokes the global [before] before each [it]", function() {
15
+ expect(global_before_invoked).to(equal, true);
16
+ global_after_invoked = false;
17
+ });
18
+
19
+ it("invokes the global [after] after an [it]", function() {
20
+ expect(global_after_invoked).to(equal, true);
21
+ });
22
+ });
23
+
24
+ describe("a [describe] with a [before] and [after] block", function() {
25
+ var before_invoked = false, after_invoked = false;
26
+ before(function() { before_invoked = true });
27
+ after(function() { after_invoked = true });
28
+
29
+ describe('[after] blocks', function() {
30
+ it("does not invoke the [after] until after the first [it]", function() {
31
+ expect(after_invoked).to(equal, false);
32
+ });
33
+
34
+ it("invokes the [after] after the first [it]", function() {
35
+ expect(after_invoked).to(equal, true);
36
+ after_invoked = false;
37
+ });
38
+
39
+ it("invokes the [after] after each [it]", function() {
40
+ expect(after_invoked).to(equal, true);
41
+ });
42
+ });
43
+
44
+ describe('[before] blocks', function() {
45
+ it("invokes the [before] before an it", function() {
46
+ expect(before_invoked).to(equal, true);
47
+ before_invoked = false;
48
+ });
49
+
50
+ it("invokes the [before] before each it", function() {
51
+ expect(before_invoked).to(equal, true);
52
+ });
53
+ });
54
+ });
55
+
56
+ describe("A [describe] with two [before] and two [after] blocks", function() {
57
+ var before_invocations = [], after_invocations = [];
58
+ before(function() { before_invocations.push('before 1') });
59
+ before(function() { before_invocations.push('before 2') });
60
+
61
+ after(function() { after_invocations.push('after 1') });
62
+ after(function() { after_invocations.push('after 2') });
63
+
64
+ it("invokes the [before]s in lexical order before each [it]", function() {
65
+ expect(before_invocations).to(equal, ['before 1', 'before 2']);
66
+ });
67
+
68
+ it("invokes the [afters]s in lexical order after each [it]", function() {
69
+ expect(after_invocations).to(equal, ['after 1', 'after 2']);
70
+ });
71
+ });
72
+
73
+ describe("A describe with a nested describe", function() {
74
+ var before_invocations = [], after_invocations = [];
75
+ before(function() {
76
+ before_invocations = [];
77
+ before_invocations.push("outermost before");
78
+ });
79
+
80
+ after(function() {
81
+ after_invocations = [];
82
+ after_invocations.push("outermost after");
83
+ });
84
+
85
+ it("outside a nested [describe], does not invoke any of the nested's [before]s", function() {
86
+ expect(before_invocations).to(equal, ["outermost before"]);
87
+ });
88
+
89
+ it("outside a nested [describe], does not invoke any of the nested's [after]s", function() {
90
+ expect(after_invocations).to(equal, ["outermost after"]);
91
+ });
92
+
93
+ describe("a nested [describe]", function() {
94
+ before(function() {
95
+ before_invocations.push("inner before");
96
+ });
97
+
98
+ after(function() {
99
+ after_invocations.push("inner after");
100
+ });
101
+
102
+ it("runs [before]s in the parent [describe] before each [it]", function() {
103
+ expect(before_invocations).to(equal, ["outermost before", "inner before"]);
104
+ });
105
+
106
+ it("runs [after]s in the parent [describe] after each [it]", function() {
107
+ expect(after_invocations).to(equal, ["outermost after", "inner after"]);
108
+ });
109
+
110
+ describe("a doubly nested [describe]", function() {
111
+ before(function() {
112
+ before_invocations.push('innermost before');
113
+ });
114
+
115
+ after(function() {
116
+ after_invocations.push('innermost after');
117
+ });
118
+
119
+ describe('[before] blocks', function() {
120
+ it("runs [before]s in all ancestors before an [it]", function() {
121
+ expect(before_invocations).to(equal, ["outermost before", "inner before", "innermost before"]);
122
+ });
123
+
124
+ it("runs [before]s in all ancestors before each [it]", function() {
125
+ expect(before_invocations).to(equal, ["outermost before", "inner before", "innermost before"]);
126
+ });
127
+ });
128
+
129
+ describe('[after] blocks', function() {
130
+ it("runs [after]s in all ancestors after an [it]", function() {
131
+ expect(after_invocations).to(equal, ["outermost after", "inner after", "innermost after"]);
132
+ });
133
+
134
+ it("runs [after]s in all ancestors after each [it]", function() {
135
+ expect(after_invocations).to(equal, ["outermost after", "inner after", "innermost after"]);
136
+ });
137
+ });
138
+ });
139
+ });
140
+ });
141
+
142
+ describe("A describe block with exceptions", function() {
143
+ var after_invoked = false;
144
+ after(function() {
145
+ after_invoked = true;
146
+ });
147
+
148
+ describe("an exception in a test", function() {
149
+ it("fails because it throws an exception", function() {
150
+ throw('an exception');
151
+ });
152
+
153
+ it("invokes [after]s even if the previous [it] raised an exception", function() {
154
+ expect(after_invoked).to(equal, true);
155
+ });
156
+ });
157
+ });
158
+ });
159
+
160
+ describe("#selector", function() {
161
+ describe('a [describe]', function() {
162
+ it('manufactures a CSS selector that uniquely locates the [describe]', function() {
163
+ $('.describe').each(function() {
164
+ expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
165
+ });
166
+ });
167
+ });
168
+
169
+ describe('an [it]', function() {
170
+ it('manufactures a CSS selector that uniquely locates the [it]', function() {
171
+ $('.it').each(function() {
172
+ expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
173
+ });
174
+ });
175
+ });
176
+ });
177
+ });
178
+ });
@@ -0,0 +1,237 @@
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 given an object', function() {
10
+ it("matches Objects with the same keys and values", function() {
11
+ expect({a: 'b', c: 'd'}).to(equal, {a: 'b', c: 'd'});
12
+ expect({a: 'b', c: 'd', e: 'f'}).to_not(equal, {a: 'b', c: 'd', e: 'G'});
13
+ });
14
+
15
+ });
16
+
17
+ describe('when given an array', function() {
18
+ it("matches Arrays with the same elements", function() {
19
+ expect([1, 2, 4]).to(equal, [1, 2, 4]);
20
+ expect([1, 2, 3]).to_not(equal, [3, 2, 1]);
21
+ });
22
+
23
+ it("recursively applies equality to complex elements", function() {
24
+ expect([{a: 'b'}, {c: 'd'}]).to(equal, [{a: 'b'}, {c: 'd'}]);
25
+ expect([{a: 'b'}, {c: 'd'}]).to_not(equal, [{a: 'b'}, {c: 'E'}]);
26
+ });
27
+ });
28
+
29
+ describe(".failure_message", function() {
30
+ it('prints "expected [expected] to (not) be equal [actual]"', function() {
31
+ var message = null;
32
+ try { expect(1).to(equal, 2) } catch(e) { message = e }
33
+ expect(message).to(equal, 'expected 1 to equal 2');
34
+
35
+ try { expect(1).to_not(equal, 1) } catch(e) { message = e }
36
+ expect(message).to(equal, 'expected 1 to not equal 1');
37
+ });
38
+ });
39
+ });
40
+
41
+ describe('#match', function() {
42
+ describe('when given a regular expression', function() {
43
+ it("matches Strings produced by the grammar", function() {
44
+ expect("The wheels of the bus").to(match, /bus/);
45
+ expect("The wheels of the bus").to_not(match, /boat/);
46
+ });
47
+ });
48
+
49
+ describe('when given a string', function() {
50
+ it("matches [expected]s containing [actual]s", function() {
51
+ expect("The wheels of the bus").to(match, "wheels");
52
+ expect("The wheels of the bus").to_not(match, "oars");
53
+ });
54
+ });
55
+
56
+ describe('when given an integer', function() {
57
+ it("matches [expected]s containing [actual]s", function() {
58
+ expect("1 time").to(match, 1);
59
+ expect("2 times").to_not(match, 3);
60
+ });
61
+ });
62
+
63
+ describe(".failure_message", function() {
64
+ it('prints "expected [actual] to (not) match [expected]', function() {
65
+ var message = null;
66
+ try { expect("hello").to(match, "schmello") } catch(e) { message = e }
67
+ expect(message).to(equal, 'expected "hello" to match "schmello"');
68
+
69
+ try { expect("hello").to_not(match, "ello") } catch(e) { message = e }
70
+ expect(message).to(equal, 'expected "hello" to not match "ello"');
71
+ });
72
+ });
73
+ });
74
+
75
+ describe('#be_empty', function() {
76
+ it("matches Arrays with no elements", function() {
77
+ expect([]).to(be_empty);
78
+ expect([1]).to_not(be_empty);
79
+ });
80
+
81
+ describe(".failure_message", function() {
82
+ it("prints 'expected [actual] to (not) be empty", function() {
83
+ var message = null;
84
+ try { expect([1]).to(be_empty) } catch(e) { message = e }
85
+ expect(message).to(equal, 'expected [ 1 ] to be empty');
86
+
87
+ try { expect([]).to_not(be_empty) } catch(e) { message = e }
88
+ expect(message).to(equal, 'expected [] to not be empty');
89
+ });
90
+ });
91
+ });
92
+
93
+ describe('#have_length', function() {
94
+ it("matches Arrays of the expected length", function() {
95
+ expect([]).to(have_length, 0);
96
+ expect([1]).to(have_length, 1);
97
+ expect([1, 2, 3]).to_not(have_length, 4);
98
+ });
99
+
100
+ describe(".failure_message", function() {
101
+ it("prints 'expected [actual] to (not) have length [expected]", function() {
102
+ var message = null;
103
+ try { expect([1, 2]).to(have_length, 4) } catch(e) { message = e }
104
+ expect(message).to(equal, 'expected [ 1, 2 ] to have length 4');
105
+
106
+ try { expect([1]).to_not(have_length, 1) } catch(e) { message = e }
107
+ expect(message).to(equal, 'expected [ 1 ] to not have length 1');
108
+ });
109
+ });
110
+ });
111
+
112
+ describe('#be_null', function() {
113
+ it("matches null", function() {
114
+ expect(null).to(be_null);
115
+ expect(1).to_not(be_null);
116
+ });
117
+
118
+ describe(".failure_message", function() {
119
+ it("prints 'expected [actual] to (not) be null", function() {
120
+ var message = null;
121
+ try { expect(1).to(be_null) } catch(e) { message = e }
122
+ expect(message).to(equal, 'expected 1 to be null');
123
+
124
+ try { expect(null).to_not(be_null) } catch(e) { message = e }
125
+ expect(message).to(equal, 'expected null to not be null');
126
+ });
127
+ });
128
+ });
129
+
130
+ describe('#be_undefined', function() {
131
+ it("matches undefined", function() {
132
+ expect(undefined).to(be_undefined);
133
+ expect(1).to_not(be_undefined);
134
+ });
135
+
136
+ describe(".failure_message", function() {
137
+ it("prints 'expected [actual] to (not) be undefined", function() {
138
+ var message = undefined;
139
+ try { expect(1).to(be_undefined) } catch(e) { message = e }
140
+ expect(message).to(equal, 'expected 1 to be undefined');
141
+
142
+ try { expect(undefined).to_not(be_undefined) } catch(e) { message = e }
143
+ expect(message).to(equal, 'expected undefined to not be undefined');
144
+ });
145
+ });
146
+ });
147
+
148
+ describe('#be_true', function() {
149
+ it("matches values that are considered true conditions", function() {
150
+ expect(true).to(be_true);
151
+ expect(1).to(be_true);
152
+ expect(false).to_not(be_true);
153
+ expect(undefined).to_not(be_true);
154
+ expect(null).to_not(be_true);
155
+ });
156
+
157
+ describe(".failure_message", function() {
158
+ it("prints 'expected [actual] to (not) be true", function() {
159
+ var message = true;
160
+ try { expect(false).to(be_true) } catch(e) { message = e }
161
+ expect(message).to(equal, 'expected false to be true');
162
+
163
+ try { expect(true).to_not(be_true) } catch(e) { message = e }
164
+ expect(message).to(equal, 'expected true to not be true');
165
+ });
166
+ });
167
+ });
168
+
169
+ describe('#be_false', function() {
170
+ it("matches values that are considered false conditions", function() {
171
+ expect(false).to(be_false);
172
+ expect(undefined).to(be_false);
173
+ expect(null).to(be_false);
174
+ expect(true).to_not(be_false);
175
+ expect(1).to_not(be_false);
176
+ });
177
+
178
+ describe(".failure_message", function() {
179
+ it("prints 'expected [actual] to (not) be false", function() {
180
+ var message = false;
181
+ try { expect(true).to(be_false) } catch(e) { message = e }
182
+ expect(message).to(equal, 'expected true to be false');
183
+
184
+ try { expect(false).to_not(be_false) } catch(e) { message = e }
185
+ expect(message).to(equal, 'expected false to not be false');
186
+ });
187
+ });
188
+ });
189
+
190
+ describe('#match_selector', function() {
191
+ var elt;
192
+ before(function() {
193
+ elt = $("<div class='foo'></div>");
194
+ });
195
+
196
+ it("matches a jQuery element against the expected selector", function() {
197
+ expect(elt).to(match_selector, 'div.foo');
198
+ expect(elt).to_not(match_selector, 'div.bar');
199
+ });
200
+
201
+ describe(".failure_message", function() {
202
+ it("prints 'expected [actual] to (not) match selector [expected]", function() {
203
+ var message = false;
204
+ try { expect(elt).to(match_selector, 'div.bar') } catch(e) { message = e }
205
+ expect(message).to(equal, 'expected $([ <div class="foo"> ]) to match selector div.bar');
206
+
207
+ try { expect(elt).to_not(match_selector, 'div.foo') } catch(e) { message = e }
208
+ expect(message).to(equal, 'expected $([ <div class="foo"> ]) to not match selector div.foo');
209
+ });
210
+ });
211
+ });
212
+
213
+ describe('#contain_selector', function() {
214
+ var elt;
215
+ before(function() {
216
+ elt = $("<div><div class='foo'></div></div>");
217
+ });
218
+
219
+ it("matches a jQuery element against the expected selector", function() {
220
+ expect(elt).to(contain_selector, 'div.foo');
221
+ expect(elt).to_not(contain_selector, 'div.bar');
222
+ });
223
+
224
+ describe(".failure_message", function() {
225
+ it("prints 'expected [actual] to (not) match selector [expected]", function() {
226
+ var message = false;
227
+ try { expect(elt).to(contain_selector, 'div.bar') } catch(e) { message = e }
228
+ expect(message).to(equal, 'expected $([ <div> ]) to contain selector div.bar');
229
+
230
+ try { expect(elt).to_not(contain_selector, 'div.foo') } catch(e) { message = e }
231
+ expect(message).to(equal, 'expected $([ <div> ]) to not contain selector div.foo');
232
+ });
233
+ });
234
+ });
235
+
236
+ });
237
+ });