shuriken 0.1.2.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +28 -0
  3. data/coffeescripts/shuriken/test/assertions.coffee +111 -0
  4. data/coffeescripts/shuriken/test/reporters.coffee +61 -0
  5. data/coffeescripts/shuriken/test.coffee +117 -0
  6. data/coffeescripts/shuriken.coffee +2 -2
  7. data/javascripts/shuriken/mixins/callbacks.js +45 -0
  8. data/javascripts/shuriken/mixins.js +58 -0
  9. data/javascripts/shuriken/test/assertions.js +117 -0
  10. data/javascripts/shuriken/test/reporters.js +84 -0
  11. data/javascripts/shuriken/test.js +165 -0
  12. data/javascripts/shuriken.js +195 -0
  13. data/lib/shuriken.rb +1 -1
  14. data/shuriken.gemspec +84 -4
  15. data/tests/basic_namespace_tests.coffee +114 -0
  16. data/tests/template.erb +26 -0
  17. data/tests.watchr +6 -0
  18. data/vendor/jasmine-0.10.0/MIT.LICENSE +20 -0
  19. data/vendor/jasmine-0.10.0/README.markdown +437 -0
  20. data/vendor/jasmine-0.10.0/doc/files.html +460 -0
  21. data/vendor/jasmine-0.10.0/doc/index.html +322 -0
  22. data/vendor/jasmine-0.10.0/doc/symbols/_global_.html +918 -0
  23. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Block.html +417 -0
  24. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Clock.html +678 -0
  25. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Env.html +1169 -0
  26. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.JsApiReporter.html +822 -0
  27. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Matchers.html +1461 -0
  28. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.MultiReporter.html +394 -0
  29. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.NestedResults.html +710 -0
  30. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Reporter.html +574 -0
  31. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Runner.html +710 -0
  32. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Spec.html +1259 -0
  33. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Spy.html +855 -0
  34. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Suite.html +705 -0
  35. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.html +1345 -0
  36. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.util.html +535 -0
  37. data/vendor/jasmine-0.10.0/doc/symbols/src/lib_TrivialReporter.js.html +124 -0
  38. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Block.js.html +29 -0
  39. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Env.js.html +240 -0
  40. data/vendor/jasmine-0.10.0/doc/symbols/src/src_JsApiReporter.js.html +111 -0
  41. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Matchers.js.html +328 -0
  42. data/vendor/jasmine-0.10.0/doc/symbols/src/src_MultiReporter.js.html +36 -0
  43. data/vendor/jasmine-0.10.0/doc/symbols/src/src_NestedResults.js.html +88 -0
  44. data/vendor/jasmine-0.10.0/doc/symbols/src/src_PrettyPrinter.js.html +130 -0
  45. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Queue.js.html +102 -0
  46. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Reporter.js.html +35 -0
  47. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Reporters.js.html +51 -0
  48. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Runner.js.html +75 -0
  49. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Spec.js.html +211 -0
  50. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Suite.js.html +77 -0
  51. data/vendor/jasmine-0.10.0/doc/symbols/src/src_WaitsBlock.js.html +21 -0
  52. data/vendor/jasmine-0.10.0/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
  53. data/vendor/jasmine-0.10.0/doc/symbols/src/src_base.js.html +555 -0
  54. data/vendor/jasmine-0.10.0/doc/symbols/src/src_mock-timeout.js.html +185 -0
  55. data/vendor/jasmine-0.10.0/doc/symbols/src/src_util.js.html +75 -0
  56. data/vendor/jasmine-0.10.0/example/example_runner.html +25 -0
  57. data/vendor/jasmine-0.10.0/example/spec/example_suite.js +11 -0
  58. data/vendor/jasmine-0.10.0/lib/TrivialReporter.js +117 -0
  59. data/vendor/jasmine-0.10.0/lib/consolex.js +28 -0
  60. data/vendor/jasmine-0.10.0/lib/jasmine-0.10.0.js +2261 -0
  61. data/vendor/jasmine-0.10.0/lib/jasmine.css +86 -0
  62. data/vendor/jasmine-0.10.0/spec/runner.html +63 -0
  63. data/vendor/jasmine-0.10.0/spec/suites/CustomMatchersSpec.js +112 -0
  64. data/vendor/jasmine-0.10.0/spec/suites/EnvSpec.js +71 -0
  65. data/vendor/jasmine-0.10.0/spec/suites/ExceptionsSpec.js +107 -0
  66. data/vendor/jasmine-0.10.0/spec/suites/JsApiReporterSpec.js +82 -0
  67. data/vendor/jasmine-0.10.0/spec/suites/MatchersSpec.js +589 -0
  68. data/vendor/jasmine-0.10.0/spec/suites/MockClockSpec.js +34 -0
  69. data/vendor/jasmine-0.10.0/spec/suites/MultiReporterSpec.js +30 -0
  70. data/vendor/jasmine-0.10.0/spec/suites/NestedResultsSpec.js +54 -0
  71. data/vendor/jasmine-0.10.0/spec/suites/PrettyPrintSpec.js +93 -0
  72. data/vendor/jasmine-0.10.0/spec/suites/QueueSpec.js +23 -0
  73. data/vendor/jasmine-0.10.0/spec/suites/ReporterSpec.js +60 -0
  74. data/vendor/jasmine-0.10.0/spec/suites/RunnerSpec.js +258 -0
  75. data/vendor/jasmine-0.10.0/spec/suites/SpecRunningSpec.js +1086 -0
  76. data/vendor/jasmine-0.10.0/spec/suites/SpecSpec.js +110 -0
  77. data/vendor/jasmine-0.10.0/spec/suites/SpySpec.js +187 -0
  78. data/vendor/jasmine-0.10.0/spec/suites/SuiteSpec.js +101 -0
  79. data/vendor/jasmine-0.10.0/spec/suites/TrivialReporterSpec.js +140 -0
  80. data/vendor/jasmine-0.10.0/spec/suites/UtilSpec.js +23 -0
  81. data/vendor/jquery.js +154 -0
  82. data/wip-coffeescripts/example_test.coffee +0 -0
  83. data/wip-coffeescripts/test/assertions.coffee +111 -0
  84. data/wip-coffeescripts/test/reporters.coffee +61 -0
  85. data/wip-coffeescripts/test.coffee +96 -15
  86. metadata +83 -4
@@ -0,0 +1,589 @@
1
+ describe("jasmine.Matchers", function() {
2
+ var env, mockSpec;
3
+
4
+ beforeEach(function() {
5
+ env = new jasmine.Env();
6
+ env.updateInterval = 0;
7
+ mockSpec = jasmine.createSpyObj('spec', ['addMatcherResult']);
8
+ });
9
+
10
+ function match(value) {
11
+ return new env.matchersClass(env, value, mockSpec);
12
+ }
13
+
14
+ it("toEqual with primitives, objects, dates, html nodes, etc.", function() {
15
+ expect(match(true).toEqual(true)).toEqual(true);
16
+
17
+ expect(match({foo:'bar'}).toEqual(null)).toEqual(false);
18
+
19
+ var functionA = function() {
20
+ return 'hi';
21
+ };
22
+ var functionB = function() {
23
+ return 'hi';
24
+ };
25
+ expect(match({foo:functionA}).toEqual({foo:functionB})).toEqual(false);
26
+ expect(match({foo:functionA}).toEqual({foo:functionA})).toEqual(true);
27
+
28
+ expect((match(false).toEqual(true))).toEqual(false);
29
+
30
+ var circularGraph = {};
31
+ circularGraph.referenceToSelf = circularGraph;
32
+ expect((match(circularGraph).toEqual(circularGraph))).toEqual(true);
33
+
34
+ var nodeA = document.createElement('div');
35
+ var nodeB = document.createElement('div');
36
+ expect((match(nodeA).toEqual(nodeA))).toEqual(true);
37
+ expect((match(nodeA).toEqual(nodeB))).toEqual(false);
38
+
39
+ expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2009, 1, 3, 15, 17, 19, 1234)))).toEqual(false);
40
+ expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2008, 1, 3, 15, 17, 19, 1234)))).toEqual(true);
41
+
42
+
43
+ expect(match(true).toNotEqual(false)).toEqual(true);
44
+ expect((match(true).toNotEqual(true))).toEqual(false);
45
+
46
+ expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toEqual(false);
47
+ expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toEqual(false);
48
+ });
49
+
50
+ it("toEqual to build an Expectation Result", function() {
51
+ var actual = 'a';
52
+ var matcher = match(actual);
53
+ var expected = 'b';
54
+ matcher.toEqual(expected);
55
+
56
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
57
+
58
+ expect(result.matcherName).toEqual("toEqual");
59
+ expect(result.passed()).toEqual(false);
60
+ expect(result.message).toMatch(jasmine.pp(actual));
61
+ expect(result.message).toMatch(jasmine.pp(expected));
62
+ expect(result.expected).toEqual(expected);
63
+ expect(result.actual).toEqual(actual);
64
+ });
65
+
66
+ it("toNotEqual to build an Expectation Result", function() {
67
+ var str = 'a';
68
+ var matcher = match(str);
69
+ matcher.toNotEqual(str);
70
+
71
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
72
+
73
+ expect(result.matcherName).toEqual("toNotEqual");
74
+ expect(result.passed()).toEqual(false);
75
+ expect(result.message).toMatch(jasmine.pp(str));
76
+ expect(result.message).toMatch('not');
77
+ expect(result.expected).toEqual(str);
78
+ expect(result.actual).toEqual(str);
79
+ });
80
+
81
+ it('toBe should return true only if the expected and actual items === each other', function() {
82
+ var a = {};
83
+ var b = {};
84
+ //noinspection UnnecessaryLocalVariableJS
85
+ var c = a;
86
+ expect((match(a).toBe(b))).toEqual(false);
87
+ expect((match(a).toBe(a))).toEqual(true);
88
+ expect((match(a).toBe(c))).toEqual(true);
89
+ expect((match(a).toNotBe(b))).toEqual(true);
90
+ expect((match(a).toNotBe(a))).toEqual(false);
91
+ expect((match(a).toNotBe(c))).toEqual(false);
92
+ });
93
+
94
+ it("toBe to build an ExpectationResult", function() {
95
+ var expected = 'b';
96
+ var actual = 'a';
97
+ var matcher = match(actual);
98
+ matcher.toBe(expected);
99
+
100
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
101
+
102
+ expect(result.matcherName).toEqual("toBe");
103
+ expect(result.passed()).toEqual(false);
104
+ expect(result.message).toMatch(jasmine.pp(actual));
105
+ expect(result.message).toMatch(jasmine.pp(expected));
106
+ expect(result.expected).toEqual(expected);
107
+ expect(result.actual).toEqual(actual);
108
+ });
109
+
110
+ it("toNotBe to build an ExpectationResult", function() {
111
+ var str = 'a';
112
+ var matcher = match(str);
113
+ matcher.toNotBe(str);
114
+
115
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
116
+
117
+ expect(result.matcherName).toEqual("toNotBe");
118
+ expect(result.passed()).toEqual(false);
119
+ expect(result.message).toMatch(str);
120
+ expect(result.expected).toEqual(str);
121
+ expect(result.actual).toEqual(str);
122
+ });
123
+
124
+ it("toMatch and #toNotMatch should perform regular expression matching on strings", function() {
125
+ expect((match('foobarbel').toMatch(/bar/))).toEqual(true);
126
+ expect((match('foobazbel').toMatch(/bar/))).toEqual(false);
127
+
128
+ expect((match('foobarbel').toMatch("bar"))).toEqual(true);
129
+ expect((match('foobazbel').toMatch("bar"))).toEqual(false);
130
+
131
+ expect((match('foobarbel').toNotMatch(/bar/))).toEqual(false);
132
+ expect((match('foobazbel').toNotMatch(/bar/))).toEqual(true);
133
+
134
+ expect((match('foobarbel').toNotMatch("bar"))).toEqual(false);
135
+ expect((match('foobazbel').toNotMatch("bar"))).toEqual(true);
136
+ });
137
+
138
+ it("toMatch w/ RegExp to build an ExpectationResult", function() {
139
+ var actual = 'a';
140
+ var matcher = match(actual);
141
+ var expected = /b/;
142
+ matcher.toMatch(expected);
143
+
144
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
145
+
146
+ expect(result.matcherName).toEqual("toMatch");
147
+ expect(result.passed()).toEqual(false);
148
+ expect(result.message).toMatch(jasmine.pp(actual));
149
+ expect(result.message).toMatch(expected.toString());
150
+ expect(result.expected).toEqual(expected);
151
+ expect(result.actual).toEqual(actual);
152
+ });
153
+
154
+ it("toMatch w/ String to build an ExpectationResult", function() {
155
+ var actual = 'a';
156
+ var matcher = match(actual);
157
+ var expected = 'b';
158
+ matcher.toMatch(expected);
159
+
160
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
161
+
162
+ expect(result.matcherName).toEqual("toMatch");
163
+ expect(result.passed()).toEqual(false);
164
+ expect(result.message).toEqual("Expected 'a' to match 'b'.");
165
+ expect(result.expected).toEqual(expected);
166
+ expect(result.actual).toEqual(actual);
167
+ });
168
+
169
+ it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
170
+ var actual = 'a';
171
+ var matcher = match(actual);
172
+ var expected = /a/;
173
+ matcher.toNotMatch(expected);
174
+
175
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
176
+
177
+ expect(result.matcherName).toEqual("toNotMatch");
178
+ expect(result.passed()).toEqual(false);
179
+ expect(result.message).toEqual("Expected 'a' to not match /a/.");
180
+ expect(result.expected).toEqual(expected);
181
+ expect(result.actual).toEqual(actual);
182
+ });
183
+
184
+ it("toNotMatch w/ String to build an ExpectationResult", function() {
185
+ var str = 'a';
186
+ var matcher = match(str);
187
+ matcher.toNotMatch(str);
188
+
189
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
190
+
191
+ expect(result.matcherName).toEqual("toNotMatch");
192
+ expect(result.passed()).toEqual(false);
193
+ expect(result.message).toEqual("Expected 'a' to not match 'a'.");
194
+ expect(result.expected).toEqual(str);
195
+ expect(result.actual).toEqual(str);
196
+ });
197
+
198
+ it("toBeDefined", function() {
199
+ expect(match('foo').toBeDefined()).toEqual(true);
200
+ expect(match(jasmine.undefined).toBeDefined()).toEqual(false);
201
+ });
202
+
203
+ it("toBeDefined to build an ExpectationResult", function() {
204
+ var matcher = match(jasmine.undefined);
205
+ matcher.toBeDefined();
206
+
207
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
208
+
209
+ expect(result.matcherName).toEqual("toBeDefined");
210
+ expect(result.passed()).toEqual(false);
211
+ expect(result.message).toEqual('Expected undefined to be defined.');
212
+ expect(result.actual).toEqual(jasmine.undefined);
213
+ });
214
+
215
+ it("toBeUndefined", function() {
216
+ expect(match('foo').toBeUndefined()).toEqual(false);
217
+ expect(match(jasmine.undefined).toBeUndefined()).toEqual(true);
218
+ });
219
+
220
+ it("toBeNull", function() {
221
+ expect(match(null).toBeNull()).toEqual(true);
222
+ expect(match(jasmine.undefined).toBeNull()).toEqual(false);
223
+ expect(match("foo").toBeNull()).toEqual(false);
224
+ });
225
+
226
+ it("toBeNull w/ String to build an ExpectationResult", function() {
227
+ var actual = 'a';
228
+ var matcher = match(actual);
229
+ matcher.toBeNull();
230
+
231
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
232
+
233
+ expect(result.matcherName).toEqual("toBeNull");
234
+ expect(result.passed()).toEqual(false);
235
+ expect(result.message).toMatch(jasmine.pp(actual));
236
+ expect(result.message).toMatch('null');
237
+ expect(result.actual).toEqual(actual);
238
+ });
239
+
240
+ it("toBeNull w/ Object to build an ExpectationResult", function() {
241
+ var actual = {a: 'b'};
242
+ var matcher = match(actual);
243
+ matcher.toBeNull();
244
+
245
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
246
+
247
+ expect(result.matcherName).toEqual("toBeNull");
248
+ expect(result.passed()).toEqual(false);
249
+ expect(result.message).toMatch(jasmine.pp(actual));
250
+ expect(result.message).toMatch('null');
251
+ expect(result.actual).toEqual(actual);
252
+ });
253
+
254
+ it("toBeFalsy", function() {
255
+ expect(match(false).toBeFalsy()).toEqual(true);
256
+ expect(match(true).toBeFalsy()).toEqual(false);
257
+ expect(match(jasmine.undefined).toBeFalsy()).toEqual(true);
258
+ expect(match(0).toBeFalsy()).toEqual(true);
259
+ expect(match("").toBeFalsy()).toEqual(true);
260
+ });
261
+
262
+ it("toBeFalsy to build an ExpectationResult", function() {
263
+ var actual = 'a';
264
+ var matcher = match(actual);
265
+ matcher.toBeFalsy();
266
+
267
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
268
+
269
+ expect(result.matcherName).toEqual("toBeFalsy");
270
+ expect(result.passed()).toEqual(false);
271
+ expect(result.message).toMatch(jasmine.pp(actual));
272
+ expect(result.message).toMatch('falsy');
273
+ expect(result.actual).toEqual(actual);
274
+ });
275
+
276
+ it("toBeTruthy", function() {
277
+ expect(match(false).toBeTruthy()).toEqual(false);
278
+ expect(match(true).toBeTruthy()).toEqual(true);
279
+ expect(match(jasmine.undefined).toBeTruthy()).toEqual(false);
280
+ expect(match(0).toBeTruthy()).toEqual(false);
281
+ expect(match("").toBeTruthy()).toEqual(false);
282
+ expect(match("hi").toBeTruthy()).toEqual(true);
283
+ expect(match(5).toBeTruthy()).toEqual(true);
284
+ expect(match({foo: 1}).toBeTruthy()).toEqual(true);
285
+ });
286
+
287
+ it("toBeTruthy to build an ExpectationResult", function() {
288
+ var matcher = match(false);
289
+ matcher.toBeTruthy();
290
+
291
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
292
+
293
+ expect(result.matcherName).toEqual("toBeTruthy");
294
+ expect(result.passed()).toEqual(false);
295
+ expect(result.message).toEqual("Expected false to be truthy.");
296
+ expect(result.actual).toEqual(false);
297
+ });
298
+
299
+ it("toEqual", function() {
300
+ expect(match(jasmine.undefined).toEqual(jasmine.undefined)).toEqual(true);
301
+ expect(match({foo:'bar'}).toEqual({foo:'bar'})).toEqual(true);
302
+ expect(match("foo").toEqual({bar: jasmine.undefined})).toEqual(false);
303
+ expect(match({foo: jasmine.undefined}).toEqual("goo")).toEqual(false);
304
+ expect(match({foo: {bar :jasmine.undefined}}).toEqual("goo")).toEqual(false);
305
+ });
306
+
307
+ it("toEqual with jasmine.any()", function() {
308
+ expect(match("foo").toEqual(jasmine.any(String))).toEqual(true);
309
+ expect(match(3).toEqual(jasmine.any(Number))).toEqual(true);
310
+ expect(match("foo").toEqual(jasmine.any(Function))).toEqual(false);
311
+ expect(match("foo").toEqual(jasmine.any(Object))).toEqual(false);
312
+ expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toEqual(true);
313
+ expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toEqual(false);
314
+ expect(match(function() {
315
+ }).toEqual(jasmine.any(Object))).toEqual(false);
316
+ expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toEqual(true);
317
+ expect(match(function() {
318
+ }).toEqual(jasmine.any(Function))).toEqual(true);
319
+ expect(match(["a", function() {
320
+ }]).toEqual(["a", jasmine.any(Function)])).toEqual(true);
321
+ });
322
+
323
+ it("toEqual handles circular objects ok", function() {
324
+ expect(match({foo: "bar", baz: jasmine.undefined}).toEqual({foo: "bar", baz: jasmine.undefined})).toEqual(true);
325
+ expect(match({foo:['bar','baz','quux']}).toEqual({foo:['bar','baz','quux']})).toEqual(true);
326
+ expect(match({foo: {bar:'baz'}, quux:'corge'}).toEqual({foo:{bar:'baz'}, quux:'corge'})).toEqual(true);
327
+
328
+ var circularObject = {};
329
+ var secondCircularObject = {};
330
+ circularObject.field = circularObject;
331
+ secondCircularObject.field = secondCircularObject;
332
+ expect(match(circularObject).toEqual(secondCircularObject)).toEqual(true);
333
+ });
334
+
335
+ it("toNotEqual as slightly surprising behavior, but is it intentional?", function() {
336
+ expect(match({x:"x", y:"y", z:"w"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
337
+ expect(match({x:"x", y:"y", w:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
338
+ expect(match({x:"x", y:"y", z:"z"}).toNotEqual({w: "w", x:"x", y:"y", z:"z"})).toEqual(true);
339
+ expect(match({w: "w", x:"x", y:"y", z:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
340
+ });
341
+
342
+ it("toEqual handles arrays", function() {
343
+ expect(match([1, "A"]).toEqual([1, "A"])).toEqual(true);
344
+ });
345
+
346
+ it("toContain and toNotContain", function() {
347
+ expect(match('ABC').toContain('A')).toEqual(true);
348
+ expect(match('ABC').toContain('X')).toEqual(false);
349
+
350
+ expect(match(['A', 'B', 'C']).toContain('A')).toEqual(true);
351
+ expect(match(['A', 'B', 'C']).toContain('F')).toEqual(false);
352
+ expect(match(['A', 'B', 'C']).toNotContain('F')).toEqual(true);
353
+ expect(match(['A', 'B', 'C']).toNotContain('A')).toEqual(false);
354
+
355
+ expect(match(['A', {some:'object'}, 'C']).toContain({some:'object'})).toEqual(true);
356
+ expect(match(['A', {some:'object'}, 'C']).toContain({some:'other object'})).toEqual(false);
357
+ });
358
+
359
+ it("toContain to build an ExpectationResult", function() {
360
+ var actual = ['a','b','c'];
361
+ var matcher = match(actual);
362
+ var expected = 'x';
363
+ matcher.toContain(expected);
364
+
365
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
366
+
367
+ expect(result.matcherName).toEqual("toContain");
368
+ expect(result.passed()).toEqual(false);
369
+ expect(result.message).toMatch(jasmine.pp(actual));
370
+ expect(result.message).toMatch('contain');
371
+ expect(result.message).toMatch(jasmine.pp(expected));
372
+ expect(result.actual).toEqual(actual);
373
+ expect(result.expected).toEqual(expected);
374
+ });
375
+
376
+ it("toNotContain to build an ExpectationResult", function() {
377
+ var actual = ['a','b','c'];
378
+ var matcher = match(actual);
379
+ var expected = 'b';
380
+ matcher.toNotContain(expected);
381
+
382
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
383
+
384
+ expect(result.matcherName).toEqual("toNotContain");
385
+ expect(result.passed()).toEqual(false);
386
+ expect(result.message).toMatch(jasmine.pp(actual));
387
+ expect(result.message).toMatch('not contain');
388
+ expect(result.message).toMatch(jasmine.pp(expected));
389
+ expect(result.actual).toEqual(actual);
390
+ expect(result.expected).toEqual(expected);
391
+ });
392
+
393
+ it("toBeLessThan should pass if actual is less than expected", function() {
394
+ expect(match(37).toBeLessThan(42)).toEqual(true);
395
+ expect(match(37).toBeLessThan(-42)).toEqual(false);
396
+ expect(match(37).toBeLessThan(37)).toEqual(false);
397
+ });
398
+
399
+ it("toBeLessThan to build an ExpectationResult", function() {
400
+ var actual = 3;
401
+ var matcher = match(actual);
402
+ var expected = 1;
403
+ matcher.toBeLessThan(expected);
404
+
405
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
406
+
407
+ expect(result.matcherName).toEqual("toBeLessThan");
408
+ expect(result.passed()).toEqual(false);
409
+ expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
410
+ expect(result.message).toMatch(jasmine.pp(expected));
411
+ expect(result.actual).toEqual(actual);
412
+ expect(result.expected).toEqual(expected);
413
+ });
414
+
415
+ it("toBeGreaterThan should pass if actual is greater than expected", function() {
416
+ expect(match(37).toBeGreaterThan(42)).toEqual(false);
417
+ expect(match(37).toBeGreaterThan(-42)).toEqual(true);
418
+ expect(match(37).toBeGreaterThan(37)).toEqual(false);
419
+ });
420
+
421
+ it("toBeGreaterThan to build an ExpectationResult", function() {
422
+ var actual = 1;
423
+ var matcher = match(actual);
424
+ var expected = 3;
425
+ matcher.toBeGreaterThan(expected);
426
+
427
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
428
+
429
+ expect(result.matcherName).toEqual("toBeGreaterThan");
430
+ expect(result.passed()).toEqual(false);
431
+ expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
432
+ expect(result.message).toMatch(jasmine.pp(expected));
433
+ expect(result.actual).toEqual(actual);
434
+ expect(result.expected).toEqual(expected);
435
+ });
436
+
437
+ it("toThrow", function() {
438
+ var expected = match(function() {
439
+ throw new Error("Fake Error");
440
+ });
441
+ expect(expected.toThrow()).toEqual(true);
442
+ expect(expected.toThrow("Fake Error")).toEqual(true);
443
+ expect(expected.toThrow(new Error("Fake Error"))).toEqual(true);
444
+
445
+ expect(expected.toThrow("Other Error")).toEqual(false);
446
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
447
+ expect(result.message).toMatch("Other Error");
448
+
449
+ expect(expected.toThrow(new Error("Other Error"))).toEqual(false);
450
+ result = mockSpec.addMatcherResult.mostRecentCall.args[0];
451
+ expect(result.message).toMatch("Other Error");
452
+
453
+ var exception;
454
+ try {
455
+ (function () {
456
+ new jasmine.Matchers(env, 'not-a-function', mockSpec).toThrow();
457
+ })();
458
+ } catch (e) {
459
+ exception = e;
460
+ }
461
+
462
+ expect(exception).toBeDefined();
463
+ expect(exception.message).toEqual('Actual is not a function');
464
+
465
+
466
+ expect(match(function() {
467
+ }).toThrow()).toEqual(false);
468
+ result = mockSpec.addMatcherResult.mostRecentCall.args[0];
469
+ expect(result.message).toEqual('Expected function to throw an exception.');
470
+
471
+
472
+ });
473
+
474
+ describe("spy matchers >>", function() {
475
+ var TestClass;
476
+ beforeEach(function() {
477
+ TestClass = {
478
+ normalFunction: function() {
479
+ },
480
+ spyFunction: jasmine.createSpy("My spy")
481
+ };
482
+ });
483
+
484
+ function shouldThrowAnExceptionWhenInvokedOnANonSpy(methodName) {
485
+ return function() {
486
+ expect(function() {
487
+ match(TestClass.normalFunction)[methodName]();
488
+ }).toThrow('Expected a spy, but got Function.');
489
+
490
+ expect(function() {
491
+ match(jasmine.undefined)[methodName]();
492
+ }).toThrow('Expected a spy, but got undefined.');
493
+
494
+ expect(function() {
495
+ match({some:'object'})[methodName]();
496
+ }).toThrow('Expected a spy, but got { some : \'object\' }.');
497
+ };
498
+ }
499
+
500
+ describe("wasCalled", function() {
501
+ it("should pass iff the spy was called", function() {
502
+ expect(match(TestClass.spyFunction).wasCalled()).toEqual(false);
503
+
504
+ TestClass.spyFunction();
505
+ expect(match(TestClass.spyFunction).wasCalled()).toEqual(true);
506
+ });
507
+
508
+ it("should throw an exception when invoked with any arguments", function() {
509
+ expect(function() {
510
+ match(TestClass.normalFunction).wasCalled("unwanted argument");
511
+ }).toThrow('wasCalled does not take arguments, use wasCalledWith');
512
+ });
513
+
514
+ it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasCalled'));
515
+ });
516
+
517
+ describe("wasNotCalled", function() {
518
+ it("should pass iff the spy was not called", function() {
519
+ expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(true);
520
+
521
+ TestClass.spyFunction();
522
+ expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(false);
523
+ });
524
+
525
+ it("should throw an exception when invoked with any arguments", function() {
526
+ expect(function() {
527
+ match(TestClass.normalFunction).wasNotCalled("unwanted argument");
528
+ }).toThrow('wasNotCalled does not take arguments');
529
+ });
530
+
531
+ it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalled'));
532
+ });
533
+
534
+ describe("wasCalledWith", function() {
535
+ it('wasCalledWith should return true if it was called with the expected args', function() {
536
+ TestClass.spyFunction('a', 'b', 'c');
537
+ expect(match(TestClass.spyFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
538
+ });
539
+
540
+ it('should return false if it was not called with the expected args', function() {
541
+ TestClass.spyFunction('a', 'b', 'c');
542
+ var expected = match(TestClass.spyFunction);
543
+ expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
544
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
545
+ expect(result.passed()).toEqual(false);
546
+ expect(result.expected).toEqual(['c', 'b', 'a']);
547
+ expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
548
+ });
549
+
550
+ it('should allow matches across multiple calls', function() {
551
+ var expected = match(TestClass.spyFunction);
552
+ TestClass.spyFunction('a', 'b', 'c');
553
+ TestClass.spyFunction('d', 'e', 'f');
554
+ expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true);
555
+ expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
556
+ expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false);
557
+ });
558
+
559
+ it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasCalledWith'));
560
+
561
+ describe("to build an ExpectationResult", function () {
562
+ beforeEach(function() {
563
+ var currentSuite;
564
+ var spec;
565
+ currentSuite = env.describe('default current suite', function() {
566
+ spec = env.it();
567
+ }, spec);
568
+ TestClass = { someFunction: function(a, b) {
569
+ } };
570
+ spec.spyOn(TestClass, 'someFunction');
571
+ });
572
+
573
+ it("should should handle the case of a spy", function() {
574
+ TestClass.someFunction('a', 'c');
575
+ var matcher = match(TestClass.someFunction);
576
+ matcher.wasCalledWith('a', 'b');
577
+
578
+ var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
579
+ expect(result.matcherName).toEqual("wasCalledWith");
580
+ expect(result.passed()).toEqual(false);
581
+ expect(result.message).toMatch("['a', 'b']");
582
+ expect(result.message).toMatch("['a', 'c']");
583
+ expect(result.actual).toEqual(TestClass.someFunction);
584
+ expect(result.expected).toEqual(['a','b']);
585
+ });
586
+ });
587
+ });
588
+ });
589
+ });
@@ -0,0 +1,34 @@
1
+ describe("MockClock", function () {
2
+
3
+ beforeEach(function() {
4
+ jasmine.Clock.useMock();
5
+ });
6
+
7
+ describe("setTimeout", function () {
8
+ it("should mock the clock when useMock is in a beforeEach", function() {
9
+ var expected = false;
10
+ setTimeout(function() {
11
+ expected = true;
12
+ }, 30000);
13
+ expect(expected).toBe(false);
14
+ jasmine.Clock.tick(30001);
15
+ expect(expected).toBe(true);
16
+ });
17
+ });
18
+
19
+ describe("setInterval", function () {
20
+ it("should mock the clock when useMock is in a beforeEach", function() {
21
+ var interval = 0;
22
+ setInterval(function() {
23
+ interval++;
24
+ }, 30000);
25
+ expect(interval).toEqual(0);
26
+ jasmine.Clock.tick(30001);
27
+ expect(interval).toEqual(1);
28
+ jasmine.Clock.tick(30001);
29
+ expect(interval).toEqual(2);
30
+ jasmine.Clock.tick(1);
31
+ expect(interval).toEqual(2);
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,30 @@
1
+ describe("jasmine.MultiReporter", function() {
2
+ var multiReporter, fakeReporter1, fakeReporter2;
3
+
4
+ beforeEach(function() {
5
+ multiReporter = new jasmine.MultiReporter();
6
+ fakeReporter1 = jasmine.createSpyObj("fakeReporter1", ["reportSpecResults"]);
7
+ fakeReporter2 = jasmine.createSpyObj("fakeReporter2", ["reportSpecResults", "reportRunnerStarting"]);
8
+ multiReporter.addReporter(fakeReporter1);
9
+ multiReporter.addReporter(fakeReporter2);
10
+ });
11
+
12
+ it("should support all the method calls that jasmine.Reporter supports", function() {
13
+ multiReporter.reportRunnerStarting();
14
+ multiReporter.reportRunnerResults();
15
+ multiReporter.reportSuiteResults();
16
+ multiReporter.reportSpecResults();
17
+ multiReporter.log();
18
+ });
19
+
20
+ it("should delegate to any and all subreporters", function() {
21
+ multiReporter.reportSpecResults('blah', 'foo');
22
+ expect(fakeReporter1.reportSpecResults).wasCalledWith('blah', 'foo');
23
+ expect(fakeReporter2.reportSpecResults).wasCalledWith('blah', 'foo');
24
+ });
25
+
26
+ it("should quietly skip delegating to any subreporters which lack the given method", function() {
27
+ multiReporter.reportRunnerStarting('blah', 'foo');
28
+ expect(fakeReporter2.reportRunnerStarting).wasCalledWith('blah', 'foo');
29
+ });
30
+ });