js-test-driver-rails 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/.gitignore +5 -0
  2. data/.gitmodules +6 -0
  3. data/Gemfile +2 -5
  4. data/Gemfile.lock +8 -9
  5. data/Rakefile +3 -28
  6. data/js-test-driver-rails.gemspec +25 -0
  7. data/lib/js_test_driver/version.rb +3 -0
  8. metadata +17 -183
  9. data/VERSION +0 -1
  10. data/vendor/jasmine-jstd-adapter/MIT.LICENSE +0 -22
  11. data/vendor/jasmine-jstd-adapter/README.md +0 -25
  12. data/vendor/jasmine-jstd-adapter/jsTestDriver.conf +0 -6
  13. data/vendor/jasmine-jstd-adapter/jsTestDriverIit.conf +0 -6
  14. data/vendor/jasmine-jstd-adapter/lib/jasmine/jasmine-0.11.1.js +0 -2343
  15. data/vendor/jasmine-jstd-adapter/lib/jstestdriver/JsTestDriver.jar +0 -0
  16. data/vendor/jasmine-jstd-adapter/server.sh +0 -1
  17. data/vendor/jasmine-jstd-adapter/src-test/iit/iitSpec.js +0 -46
  18. data/vendor/jasmine-jstd-adapter/src-test/tests.js +0 -89
  19. data/vendor/jasmine-jstd-adapter/src/JasmineAdapter.js +0 -186
  20. data/vendor/jasmine-jstd-adapter/test-iit.sh +0 -1
  21. data/vendor/jasmine-jstd-adapter/test-regular.sh +0 -2
  22. data/vendor/jasmine-jstd-adapter/test.sh +0 -2
  23. data/vendor/jasmine/Gemfile +0 -6
  24. data/vendor/jasmine/MIT.LICENSE +0 -20
  25. data/vendor/jasmine/README.markdown +0 -28
  26. data/vendor/jasmine/Rakefile +0 -182
  27. data/vendor/jasmine/cruise_config.rb +0 -21
  28. data/vendor/jasmine/example/SpecRunner.html +0 -27
  29. data/vendor/jasmine/example/spec/PlayerSpec.js +0 -58
  30. data/vendor/jasmine/example/spec/SpecHelper.js +0 -9
  31. data/vendor/jasmine/example/src/Player.js +0 -22
  32. data/vendor/jasmine/example/src/Song.js +0 -7
  33. data/vendor/jasmine/images/fail-16.png +0 -0
  34. data/vendor/jasmine/images/fail.png +0 -0
  35. data/vendor/jasmine/images/go-16.png +0 -0
  36. data/vendor/jasmine/images/go.png +0 -0
  37. data/vendor/jasmine/images/pending-16.png +0 -0
  38. data/vendor/jasmine/images/pending.png +0 -0
  39. data/vendor/jasmine/images/question-bk.png +0 -0
  40. data/vendor/jasmine/images/questionbk-16.png +0 -0
  41. data/vendor/jasmine/images/spinner.gif +0 -0
  42. data/vendor/jasmine/jsdoc-template/allclasses.tmpl +0 -17
  43. data/vendor/jasmine/jsdoc-template/allfiles.tmpl +0 -56
  44. data/vendor/jasmine/jsdoc-template/class.tmpl +0 -646
  45. data/vendor/jasmine/jsdoc-template/index.tmpl +0 -39
  46. data/vendor/jasmine/jsdoc-template/publish.js +0 -184
  47. data/vendor/jasmine/jsdoc-template/static/default.css +0 -162
  48. data/vendor/jasmine/jsdoc-template/static/header.html +0 -2
  49. data/vendor/jasmine/jsdoc-template/static/index.html +0 -19
  50. data/vendor/jasmine/jsdoc-template/symbol.tmpl +0 -35
  51. data/vendor/jasmine/lib/jasmine-html.js +0 -188
  52. data/vendor/jasmine/lib/jasmine.css +0 -166
  53. data/vendor/jasmine/lib/jasmine.js +0 -2421
  54. data/vendor/jasmine/lib/json2.js +0 -478
  55. data/vendor/jasmine/spec/runner.html +0 -80
  56. data/vendor/jasmine/spec/suites/BaseSpec.js +0 -27
  57. data/vendor/jasmine/spec/suites/CustomMatchersSpec.js +0 -97
  58. data/vendor/jasmine/spec/suites/EnvSpec.js +0 -158
  59. data/vendor/jasmine/spec/suites/ExceptionsSpec.js +0 -107
  60. data/vendor/jasmine/spec/suites/JsApiReporterSpec.js +0 -103
  61. data/vendor/jasmine/spec/suites/MatchersSpec.js +0 -795
  62. data/vendor/jasmine/spec/suites/MockClockSpec.js +0 -38
  63. data/vendor/jasmine/spec/suites/MultiReporterSpec.js +0 -45
  64. data/vendor/jasmine/spec/suites/NestedResultsSpec.js +0 -54
  65. data/vendor/jasmine/spec/suites/PrettyPrintSpec.js +0 -93
  66. data/vendor/jasmine/spec/suites/QueueSpec.js +0 -23
  67. data/vendor/jasmine/spec/suites/ReporterSpec.js +0 -56
  68. data/vendor/jasmine/spec/suites/RunnerSpec.js +0 -267
  69. data/vendor/jasmine/spec/suites/SpecRunningSpec.js +0 -1253
  70. data/vendor/jasmine/spec/suites/SpecSpec.js +0 -124
  71. data/vendor/jasmine/spec/suites/SpySpec.js +0 -201
  72. data/vendor/jasmine/spec/suites/SuiteSpec.js +0 -120
  73. data/vendor/jasmine/spec/suites/TrivialReporterSpec.js +0 -238
  74. data/vendor/jasmine/spec/suites/UtilSpec.js +0 -40
  75. data/vendor/jasmine/spec/suites/WaitsForBlockSpec.js +0 -87
  76. data/vendor/jasmine/src/Block.js +0 -22
  77. data/vendor/jasmine/src/Env.js +0 -264
  78. data/vendor/jasmine/src/JsApiReporter.js +0 -102
  79. data/vendor/jasmine/src/Matchers.js +0 -354
  80. data/vendor/jasmine/src/MultiReporter.js +0 -35
  81. data/vendor/jasmine/src/NestedResults.js +0 -80
  82. data/vendor/jasmine/src/PrettyPrinter.js +0 -122
  83. data/vendor/jasmine/src/Queue.js +0 -99
  84. data/vendor/jasmine/src/Reporter.js +0 -31
  85. data/vendor/jasmine/src/Runner.js +0 -77
  86. data/vendor/jasmine/src/Spec.js +0 -242
  87. data/vendor/jasmine/src/Suite.js +0 -82
  88. data/vendor/jasmine/src/WaitsBlock.js +0 -13
  89. data/vendor/jasmine/src/WaitsForBlock.js +0 -52
  90. data/vendor/jasmine/src/base.js +0 -589
  91. data/vendor/jasmine/src/html/TrivialReporter.js +0 -188
  92. data/vendor/jasmine/src/html/jasmine.css +0 -166
  93. data/vendor/jasmine/src/mock-timeout.js +0 -183
  94. data/vendor/jasmine/src/util.js +0 -67
  95. data/vendor/jasmine/src/version.json +0 -5
@@ -1,103 +0,0 @@
1
- describe('jasmine.jsApiReporter', function() {
2
- describe('results', function () {
3
- var reporter, spec1, spec2, spec3, expectedSpec1Results, expectedSpec2Results;
4
- var env;
5
- var suite, nestedSuite, nestedSpec;
6
-
7
- beforeEach(function() {
8
- env = new jasmine.Env();
9
- env.updateInterval = 0;
10
-
11
- suite = env.describe("top-level suite", function() {
12
- spec1 = env.it("spec 1", function() {
13
- this.expect(true).toEqual(true);
14
-
15
- });
16
-
17
- spec2 = env.it("spec 2", function() {
18
- this.expect(true).toEqual(false);
19
- });
20
-
21
- nestedSuite = env.describe("nested suite", function() {
22
- nestedSpec = env.it("nested spec", function() {
23
- expect(true).toEqual(true);
24
- })
25
- });
26
-
27
- spec3 = env.it("spec 3", function() {
28
- this.log('some debug message');
29
- });
30
- });
31
-
32
- reporter = new jasmine.JsApiReporter();
33
- env.addReporter(reporter);
34
-
35
- env.execute();
36
-
37
- expectedSpec1Results = {
38
- messages: spec1.results().getItems(),
39
- result: "passed"
40
- };
41
- expectedSpec2Results = {
42
- messages: spec2.results().getItems(),
43
- result: "failed"
44
- };
45
- });
46
-
47
- it('resultForSpec() should return the result for the given spec', function () {
48
- expect(reporter.resultsForSpec(spec1.id)).toEqual(expectedSpec1Results);
49
- expect(reporter.resultsForSpec(spec2.id)).toEqual(expectedSpec2Results);
50
- });
51
-
52
- it('results() should return a hash of all results, indexed by spec id', function () {
53
- expect(reporter.results()[spec1.id]).toEqual(expectedSpec1Results);
54
- expect(reporter.results()[spec2.id]).toEqual(expectedSpec2Results);
55
- });
56
-
57
- it("should return nested suites as children of their parents", function() {
58
- expect(reporter.suites()).toEqual([
59
- { id: 0, name: 'top-level suite', type: 'suite',
60
- children: [
61
- { id: 0, name: 'spec 1', type: 'spec', children: [ ] },
62
- { id: 1, name: 'spec 2', type: 'spec', children: [ ] },
63
- { id: 1, name: 'nested suite', type: 'suite',
64
- children: [
65
- { id: 2, name: 'nested spec', type: 'spec', children: [ ] }
66
- ]
67
- },
68
- { id: 3, name: 'spec 3', type: 'spec', children: [ ] }
69
- ]
70
- }
71
- ]);
72
- });
73
-
74
- describe("#summarizeResult_", function() {
75
- it("should summarize a passing result", function() {
76
- var result = reporter.results()[spec1.id];
77
- var summarizedResult = reporter.summarizeResult_(result);
78
- expect(summarizedResult.result).toEqual('passed');
79
- expect(summarizedResult.messages.length).toEqual(1);
80
- expect(summarizedResult.messages[0].message).toEqual(result.messages[0].message);
81
- expect(summarizedResult.messages[0].passed).toBeTruthy();
82
- expect(summarizedResult.messages[0].type).toEqual('expect');
83
- expect(summarizedResult.messages[0].text).toBeUndefined();
84
- expect(summarizedResult.messages[0].trace.stack).toBeUndefined();
85
- });
86
-
87
- it("should have a stack trace for failing specs", function() {
88
- var result = reporter.results()[spec2.id];
89
- var summarizedResult = reporter.summarizeResult_(result);
90
- expect(summarizedResult.result).toEqual('failed');
91
- expect(summarizedResult.messages[0].trace.stack).toEqual(result.messages[0].trace.stack);
92
- });
93
-
94
- it("should have messages for specs with messages", function() {
95
- var result = reporter.results()[spec3.id];
96
- var summarizedResult = reporter.summarizeResult_(result);
97
- expect(summarizedResult.result).toEqual('passed');
98
- expect(summarizedResult.messages[0].type).toEqual('log');
99
- expect(summarizedResult.messages[0].text).toEqual('some debug message');
100
- });
101
- });
102
- });
103
- });
@@ -1,795 +0,0 @@
1
- describe("jasmine.Matchers", function() {
2
- var env, spec;
3
-
4
- beforeEach(function() {
5
- env = new jasmine.Env();
6
- env.updateInterval = 0;
7
-
8
- var suite = env.describe("suite", function() {
9
- spec = env.it("spec", function() {
10
- });
11
- });
12
- spyOn(spec, 'addMatcherResult');
13
-
14
- this.addMatchers({
15
- toPass: function() {
16
- return lastResult().passed();
17
- },
18
- toFail: function() {
19
- return !lastResult().passed();
20
- }
21
- })
22
- });
23
-
24
- function match(value) {
25
- return spec.expect(value);
26
- }
27
-
28
- function lastResult() {
29
- return spec.addMatcherResult.mostRecentCall.args[0];
30
- }
31
-
32
- function catchException(fn) {
33
- try {
34
- fn.call();
35
- } catch (e) {
36
- return e;
37
- }
38
- throw new Error("expected function to throw an exception");
39
- }
40
-
41
- it("toEqual with primitives, objects, dates, etc.", function() {
42
- expect(match(true).toEqual(true)).toPass();
43
-
44
- expect(match({foo:'bar'}).toEqual(null)).toFail();
45
-
46
- var functionA = function() {
47
- return 'hi';
48
- };
49
- var functionB = function() {
50
- return 'hi';
51
- };
52
- expect(match({foo:functionA}).toEqual({foo:functionB})).toFail();
53
- expect(match({foo:functionA}).toEqual({foo:functionA})).toPass();
54
-
55
- expect((match(false).toEqual(true))).toFail();
56
-
57
- var circularGraph = {};
58
- circularGraph.referenceToSelf = circularGraph;
59
- expect((match(circularGraph).toEqual(circularGraph))).toPass();
60
-
61
- expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2009, 1, 3, 15, 17, 19, 1234)))).toFail();
62
- expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2008, 1, 3, 15, 17, 19, 1234)))).toPass();
63
-
64
-
65
- expect(match(true).toNotEqual(false)).toPass();
66
- expect((match(true).toNotEqual(true))).toFail();
67
-
68
- expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toFail();
69
- expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toFail();
70
-
71
- expect((match(new String("cat")).toEqual("cat"))).toPass();
72
- expect((match(new String("cat")).toNotEqual("cat"))).toFail();
73
-
74
- expect((match(new Number(5)).toEqual(5))).toPass();
75
- expect((match(new Number('5')).toEqual(5))).toPass();
76
- expect((match(new Number(5)).toNotEqual(5))).toFail();
77
- expect((match(new Number('5')).toNotEqual(5))).toFail();
78
- });
79
-
80
- it("toEqual with DOM nodes", function() {
81
- var nodeA = document.createElement('div');
82
- var nodeB = document.createElement('div');
83
- expect((match(nodeA).toEqual(nodeA))).toPass();
84
- expect((match(nodeA).toEqual(nodeB))).toFail();
85
- });
86
-
87
- it("toEqual to build an Expectation Result", function() {
88
- var actual = 'a';
89
- var matcher = match(actual);
90
- var expected = 'b';
91
- matcher.toEqual(expected);
92
-
93
- var result = lastResult();
94
-
95
- expect(result.matcherName).toEqual("toEqual");
96
- expect(result.passed()).toFail();
97
- expect(result.message).toMatch(jasmine.pp(actual));
98
- expect(result.message).toMatch(jasmine.pp(expected));
99
- expect(result.expected).toEqual(expected);
100
- expect(result.actual).toEqual(actual);
101
- });
102
-
103
- it("toNotEqual to build an Expectation Result", function() {
104
- var str = 'a';
105
- var matcher = match(str);
106
- matcher.toNotEqual(str);
107
-
108
- var result = lastResult();
109
-
110
- expect(result.matcherName).toEqual("toNotEqual");
111
- expect(result.passed()).toFail();
112
- expect(result.message).toMatch(jasmine.pp(str));
113
- expect(result.message).toMatch('not');
114
- expect(result.expected).toEqual(str);
115
- expect(result.actual).toEqual(str);
116
- });
117
-
118
- it('toBe should return true only if the expected and actual items === each other', function() {
119
- var a = {};
120
- var b = {};
121
- //noinspection UnnecessaryLocalVariableJS
122
- var c = a;
123
- expect((match(a).toBe(b))).toFail();
124
- expect((match(a).toBe(a))).toPass();
125
- expect((match(a).toBe(c))).toPass();
126
- expect((match(a).toNotBe(b))).toPass();
127
- expect((match(a).toNotBe(a))).toFail();
128
- expect((match(a).toNotBe(c))).toFail();
129
- });
130
-
131
- it("toBe to build an ExpectationResult", function() {
132
- var expected = 'b';
133
- var actual = 'a';
134
- var matcher = match(actual);
135
- matcher.toBe(expected);
136
-
137
- var result = lastResult();
138
-
139
- expect(result.matcherName).toEqual("toBe");
140
- expect(result.passed()).toFail();
141
- expect(result.message).toMatch(jasmine.pp(actual));
142
- expect(result.message).toMatch(jasmine.pp(expected));
143
- expect(result.expected).toEqual(expected);
144
- expect(result.actual).toEqual(actual);
145
- });
146
-
147
- it("toNotBe to build an ExpectationResult", function() {
148
- var str = 'a';
149
- var matcher = match(str);
150
- matcher.toNotBe(str);
151
-
152
- var result = lastResult();
153
-
154
- expect(result.matcherName).toEqual("toNotBe");
155
- expect(result.passed()).toFail();
156
- expect(result.message).toMatch(str);
157
- expect(result.expected).toEqual(str);
158
- expect(result.actual).toEqual(str);
159
- });
160
-
161
- it("toMatch and #toNotMatch should perform regular expression matching on strings", function() {
162
- expect((match('foobarbel').toMatch(/bar/))).toPass();
163
- expect((match('foobazbel').toMatch(/bar/))).toFail();
164
-
165
- expect((match('foobarbel').toMatch("bar"))).toPass();
166
- expect((match('foobazbel').toMatch("bar"))).toFail();
167
-
168
- expect((match('foobarbel').toNotMatch(/bar/))).toFail();
169
- expect((match('foobazbel').toNotMatch(/bar/))).toPass();
170
-
171
- expect((match('foobarbel').toNotMatch("bar"))).toFail();
172
- expect((match('foobazbel').toNotMatch("bar"))).toPass();
173
- });
174
-
175
- it("toMatch w/ RegExp to build an ExpectationResult", function() {
176
- var actual = 'a';
177
- var matcher = match(actual);
178
- var expected = /b/;
179
- matcher.toMatch(expected);
180
-
181
- var result = lastResult();
182
-
183
- expect(result.matcherName).toEqual("toMatch");
184
- expect(result.passed()).toFail();
185
- expect(result.message).toMatch(jasmine.pp(actual));
186
- expect(result.message).toMatch(expected.toString());
187
- expect(result.expected).toEqual(expected);
188
- expect(result.actual).toEqual(actual);
189
- });
190
-
191
- it("toMatch w/ String to build an ExpectationResult", function() {
192
- var actual = 'a';
193
- var matcher = match(actual);
194
- var expected = 'b';
195
- matcher.toMatch(expected);
196
-
197
- var result = lastResult();
198
-
199
- expect(result.matcherName).toEqual("toMatch");
200
- expect(result.passed()).toFail();
201
- expect(result.message).toEqual("Expected 'a' to match 'b'.");
202
- expect(result.expected).toEqual(expected);
203
- expect(result.actual).toEqual(actual);
204
- });
205
-
206
- it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
207
- var actual = 'a';
208
- var matcher = match(actual);
209
- var expected = /a/;
210
- matcher.toNotMatch(expected);
211
-
212
- var result = lastResult();
213
-
214
- expect(result.matcherName).toEqual("toNotMatch");
215
- expect(result.passed()).toFail();
216
- expect(result.message).toEqual("Expected 'a' to not match /a/.");
217
- expect(result.expected).toEqual(expected);
218
- expect(result.actual).toEqual(actual);
219
- });
220
-
221
- it("toNotMatch w/ String to build an ExpectationResult", function() {
222
- var str = 'a';
223
- var matcher = match(str);
224
- matcher.toNotMatch(str);
225
-
226
- var result = lastResult();
227
-
228
- expect(result.matcherName).toEqual("toNotMatch");
229
- expect(result.passed()).toFail();
230
- expect(result.message).toEqual("Expected 'a' to not match 'a'.");
231
- expect(result.expected).toEqual(str);
232
- expect(result.actual).toEqual(str);
233
- });
234
-
235
- it("toBeDefined", function() {
236
- expect(match('foo').toBeDefined()).toPass();
237
- expect(match(jasmine.undefined).toBeDefined()).toFail();
238
- });
239
-
240
- it("toBeDefined to build an ExpectationResult", function() {
241
- var matcher = match(jasmine.undefined);
242
- matcher.toBeDefined();
243
-
244
- var result = lastResult();
245
-
246
- expect(result.matcherName).toEqual("toBeDefined");
247
- expect(result.passed()).toFail();
248
- expect(result.message).toEqual('Expected undefined to be defined.');
249
- expect(result.actual).toEqual(jasmine.undefined);
250
- });
251
-
252
- it("toBeUndefined", function() {
253
- expect(match('foo').toBeUndefined()).toFail();
254
- expect(match(jasmine.undefined).toBeUndefined()).toPass();
255
- });
256
-
257
- it("toBeNull", function() {
258
- expect(match(null).toBeNull()).toPass();
259
- expect(match(jasmine.undefined).toBeNull()).toFail();
260
- expect(match("foo").toBeNull()).toFail();
261
- });
262
-
263
- it("toBeNull w/ String to build an ExpectationResult", function() {
264
- var actual = 'a';
265
- var matcher = match(actual);
266
- matcher.toBeNull();
267
-
268
- var result = lastResult();
269
-
270
- expect(result.matcherName).toEqual("toBeNull");
271
- expect(result.passed()).toFail();
272
- expect(result.message).toMatch(jasmine.pp(actual));
273
- expect(result.message).toMatch('null');
274
- expect(result.actual).toEqual(actual);
275
- });
276
-
277
- it("toBeNull w/ Object to build an ExpectationResult", function() {
278
- var actual = {a: 'b'};
279
- var matcher = match(actual);
280
- matcher.toBeNull();
281
-
282
- var result = lastResult();
283
-
284
- expect(result.matcherName).toEqual("toBeNull");
285
- expect(result.passed()).toFail();
286
- expect(result.message).toMatch(jasmine.pp(actual));
287
- expect(result.message).toMatch('null');
288
- expect(result.actual).toEqual(actual);
289
- });
290
-
291
- it("toBeFalsy", function() {
292
- expect(match(false).toBeFalsy()).toPass();
293
- expect(match(true).toBeFalsy()).toFail();
294
- expect(match(jasmine.undefined).toBeFalsy()).toPass();
295
- expect(match(0).toBeFalsy()).toPass();
296
- expect(match("").toBeFalsy()).toPass();
297
- });
298
-
299
- it("toBeFalsy to build an ExpectationResult", function() {
300
- var actual = 'a';
301
- var matcher = match(actual);
302
- matcher.toBeFalsy();
303
-
304
- var result = lastResult();
305
-
306
- expect(result.matcherName).toEqual("toBeFalsy");
307
- expect(result.passed()).toFail();
308
- expect(result.message).toMatch(jasmine.pp(actual));
309
- expect(result.message).toMatch('falsy');
310
- expect(result.actual).toEqual(actual);
311
- });
312
-
313
- it("toBeTruthy", function() {
314
- expect(match(false).toBeTruthy()).toFail();
315
- expect(match(true).toBeTruthy()).toPass();
316
- expect(match(jasmine.undefined).toBeTruthy()).toFail();
317
- expect(match(0).toBeTruthy()).toFail();
318
- expect(match("").toBeTruthy()).toFail();
319
- expect(match("hi").toBeTruthy()).toPass();
320
- expect(match(5).toBeTruthy()).toPass();
321
- expect(match({foo: 1}).toBeTruthy()).toPass();
322
- });
323
-
324
- it("toBeTruthy to build an ExpectationResult", function() {
325
- var matcher = match(false);
326
- matcher.toBeTruthy();
327
-
328
- var result = lastResult();
329
-
330
- expect(result.matcherName).toEqual("toBeTruthy");
331
- expect(result.passed()).toFail();
332
- expect(result.message).toEqual("Expected false to be truthy.");
333
- expect(result.actual).toFail();
334
- });
335
-
336
- it("toEqual", function() {
337
- expect(match(jasmine.undefined).toEqual(jasmine.undefined)).toPass();
338
- expect(match({foo:'bar'}).toEqual({foo:'bar'})).toPass();
339
- expect(match("foo").toEqual({bar: jasmine.undefined})).toFail();
340
- expect(match({foo: jasmine.undefined}).toEqual("goo")).toFail();
341
- expect(match({foo: {bar :jasmine.undefined}}).toEqual("goo")).toFail();
342
- });
343
-
344
- it("toEqual with jasmine.any()", function() {
345
- expect(match("foo").toEqual(jasmine.any(String))).toPass();
346
- expect(match(3).toEqual(jasmine.any(Number))).toPass();
347
- expect(match("foo").toEqual(jasmine.any(Function))).toFail();
348
- expect(match("foo").toEqual(jasmine.any(Object))).toFail();
349
- expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toPass();
350
- expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toFail();
351
- expect(match(function() {
352
- }).toEqual(jasmine.any(Object))).toFail();
353
- expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toPass();
354
- expect(match(function() {
355
- }).toEqual(jasmine.any(Function))).toPass();
356
- expect(match(["a", function() {
357
- }]).toEqual(["a", jasmine.any(Function)])).toPass();
358
- });
359
-
360
- it("toEqual handles circular objects ok", function() {
361
- expect(match({foo: "bar", baz: jasmine.undefined}).toEqual({foo: "bar", baz: jasmine.undefined})).toPass();
362
- expect(match({foo:['bar','baz','quux']}).toEqual({foo:['bar','baz','quux']})).toPass();
363
- expect(match({foo: {bar:'baz'}, quux:'corge'}).toEqual({foo:{bar:'baz'}, quux:'corge'})).toPass();
364
-
365
- var circularObject = {};
366
- var secondCircularObject = {};
367
- circularObject.field = circularObject;
368
- secondCircularObject.field = secondCircularObject;
369
- expect(match(circularObject).toEqual(secondCircularObject)).toPass();
370
- });
371
-
372
- it("toNotEqual as slightly surprising behavior, but is it intentional?", function() {
373
- expect(match({x:"x", y:"y", z:"w"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
374
- expect(match({x:"x", y:"y", w:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
375
- expect(match({x:"x", y:"y", z:"z"}).toNotEqual({w: "w", x:"x", y:"y", z:"z"})).toPass();
376
- expect(match({w: "w", x:"x", y:"y", z:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
377
- });
378
-
379
- it("toEqual handles arrays", function() {
380
- expect(match([1, "A"]).toEqual([1, "A"])).toPass();
381
- });
382
-
383
- it("toContain and toNotContain", function() {
384
- expect(match('ABC').toContain('A')).toPass();
385
- expect(match('ABC').toContain('X')).toFail();
386
-
387
- expect(match(['A', 'B', 'C']).toContain('A')).toPass();
388
- expect(match(['A', 'B', 'C']).toContain('F')).toFail();
389
- expect(match(['A', 'B', 'C']).toNotContain('F')).toPass();
390
- expect(match(['A', 'B', 'C']).toNotContain('A')).toFail();
391
-
392
- expect(match(['A', {some:'object'}, 'C']).toContain({some:'object'})).toPass();
393
- expect(match(['A', {some:'object'}, 'C']).toContain({some:'other object'})).toFail();
394
- });
395
-
396
- it("toContain to build an ExpectationResult", function() {
397
- var actual = ['a','b','c'];
398
- var matcher = match(actual);
399
- var expected = 'x';
400
- matcher.toContain(expected);
401
-
402
- var result = lastResult();
403
-
404
- expect(result.matcherName).toEqual("toContain");
405
- expect(result.passed()).toFail();
406
- expect(result.message).toMatch(jasmine.pp(actual));
407
- expect(result.message).toMatch('contain');
408
- expect(result.message).toMatch(jasmine.pp(expected));
409
- expect(result.actual).toEqual(actual);
410
- expect(result.expected).toEqual(expected);
411
- });
412
-
413
- it("toNotContain to build an ExpectationResult", function() {
414
- var actual = ['a','b','c'];
415
- var matcher = match(actual);
416
- var expected = 'b';
417
- matcher.toNotContain(expected);
418
-
419
- var result = lastResult();
420
-
421
- expect(result.matcherName).toEqual("toNotContain");
422
- expect(result.passed()).toFail();
423
- expect(result.message).toMatch(jasmine.pp(actual));
424
- expect(result.message).toMatch('not contain');
425
- expect(result.message).toMatch(jasmine.pp(expected));
426
- expect(result.actual).toEqual(actual);
427
- expect(result.expected).toEqual(expected);
428
- });
429
-
430
- it("toBeLessThan should pass if actual is less than expected", function() {
431
- expect(match(37).toBeLessThan(42)).toPass();
432
- expect(match(37).toBeLessThan(-42)).toFail();
433
- expect(match(37).toBeLessThan(37)).toFail();
434
- });
435
-
436
- it("toBeLessThan to build an ExpectationResult", function() {
437
- var actual = 3;
438
- var matcher = match(actual);
439
- var expected = 1;
440
- matcher.toBeLessThan(expected);
441
-
442
- var result = lastResult();
443
-
444
- expect(result.matcherName).toEqual("toBeLessThan");
445
- expect(result.passed()).toFail();
446
- expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
447
- expect(result.message).toMatch(jasmine.pp(expected));
448
- expect(result.actual).toEqual(actual);
449
- expect(result.expected).toEqual(expected);
450
- });
451
-
452
- it("toBeGreaterThan should pass if actual is greater than expected", function() {
453
- expect(match(37).toBeGreaterThan(42)).toFail();
454
- expect(match(37).toBeGreaterThan(-42)).toPass();
455
- expect(match(37).toBeGreaterThan(37)).toFail();
456
- });
457
-
458
- it("toBeGreaterThan to build an ExpectationResult", function() {
459
- var actual = 1;
460
- var matcher = match(actual);
461
- var expected = 3;
462
- matcher.toBeGreaterThan(expected);
463
-
464
- var result = lastResult();
465
-
466
- expect(result.matcherName).toEqual("toBeGreaterThan");
467
- expect(result.passed()).toFail();
468
- expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
469
- expect(result.message).toMatch(jasmine.pp(expected));
470
- expect(result.actual).toEqual(actual);
471
- expect(result.expected).toEqual(expected);
472
- });
473
-
474
- describe("toThrow", function() {
475
- describe("when code block throws an exception", function() {
476
- var throwingFn;
477
-
478
- beforeEach(function() {
479
- throwingFn = function() {
480
- throw new Error("Fake Error");
481
- };
482
- });
483
-
484
- it("should match any exception", function() {
485
- expect(match(throwingFn).toThrow()).toPass();
486
- });
487
-
488
- it("should match exceptions specified by message", function() {
489
- expect(match(throwingFn).toThrow("Fake Error")).toPass();
490
- expect(match(throwingFn).toThrow("Other Error")).toFail();
491
- expect(lastResult().message).toMatch("Other Error");
492
- });
493
-
494
- it("should match exceptions specified by Error", function() {
495
- expect(match(throwingFn).toThrow(new Error("Fake Error"))).toPass();
496
- expect(match(throwingFn).toThrow(new Error("Other Error"))).toFail();
497
- expect(lastResult().message).toMatch("Other Error");
498
- });
499
-
500
- describe("and matcher is inverted with .not", function() {
501
- it("should match any exception", function() {
502
- expect(match(throwingFn).not.toThrow()).toFail();
503
- expect(lastResult().message).toMatch(/Expected function not to throw an exception/);
504
- });
505
-
506
- it("should match exceptions specified by message", function() {
507
- expect(match(throwingFn).not.toThrow("Fake Error")).toFail();
508
- // expect(lastResult().message).toMatch(/Expected function not to throw Fake Error./);
509
- expect(match(throwingFn).not.toThrow("Other Error")).toPass();
510
- });
511
-
512
- it("should match exceptions specified by Error", function() {
513
- expect(match(throwingFn).not.toThrow(new Error("Fake Error"))).toFail();
514
- // expect(lastResult().message).toMatch("Other Error");
515
- expect(match(throwingFn).not.toThrow(new Error("Other Error"))).toPass();
516
- });
517
- });
518
- });
519
-
520
- describe("when actual is not a function", function() {
521
- it("should fail with an exception", function() {
522
- var exception = catchException(function() {
523
- match('not-a-function').toThrow();
524
- });
525
- expect(exception).toBeDefined();
526
- expect(exception.message).toEqual('Actual is not a function');
527
- });
528
-
529
- describe("and matcher is inverted with .not", function() {
530
- it("should fail with an exception", function() {
531
- var exception = catchException(function() {
532
- match('not-a-function').not.toThrow();
533
- });
534
- expect(exception).toBeDefined();
535
- expect(exception.message).toEqual('Actual is not a function');
536
- });
537
- });
538
- });
539
-
540
-
541
- describe("when code block does not throw an exception", function() {
542
- it("should fail (or pass when inverted with .not)", function() {
543
- expect(match(function() {
544
- }).toThrow()).toFail();
545
- expect(lastResult().message).toEqual('Expected function to throw an exception.');
546
- });
547
- });
548
- });
549
-
550
- describe(".not.matcher", function() {
551
- it("should invert the sense of any matcher", function() {
552
- expect(match(37).not.toBeGreaterThan(42)).toPass();
553
- expect(match(42).not.toBeGreaterThan(37)).toFail();
554
- expect(match("abc").not.toEqual("def")).toPass();
555
- expect(match("abc").not.toEqual("abc")).toFail();
556
- });
557
-
558
- it("should provide an inverted default message", function() {
559
- match(37).not.toBeGreaterThan(42);
560
- expect(lastResult().message).toEqual("Passed.");
561
-
562
- match(42).not.toBeGreaterThan(37);
563
- expect(lastResult().message).toEqual("Expected 42 not to be greater than 37.");
564
- });
565
-
566
- it("should use the second message when the matcher sets an array of custom messages", function() {
567
- spec.addMatchers({
568
- custom: function() {
569
- this.message = function() {
570
- return ['Expected it was called.', 'Expected it wasn\'t called.'];
571
- };
572
- return this.actual;
573
- }
574
- });
575
-
576
- match(true).custom();
577
- expect(lastResult().message).toEqual("Passed.");
578
- match(false).custom();
579
- expect(lastResult().message).toEqual("Expected it was called.");
580
- match(true).not.custom();
581
- expect(lastResult().message).toEqual("Expected it wasn't called.");
582
- match(false).not.custom();
583
- expect(lastResult().message).toEqual("Passed.");
584
- });
585
- });
586
-
587
- describe("spy matchers >>", function() {
588
- var TestClass;
589
- beforeEach(function() {
590
- TestClass = {
591
- normalFunction: function() {
592
- },
593
- spyFunction: jasmine.createSpy("My spy")
594
- };
595
- });
596
-
597
- function shouldThrowAnExceptionWhenInvokedOnANonSpy(methodName) {
598
- return function() {
599
- expect(function() {
600
- match(TestClass.normalFunction)[methodName]();
601
- }).toThrow('Expected a spy, but got Function.');
602
-
603
- expect(function() {
604
- match(jasmine.undefined)[methodName]();
605
- }).toThrow('Expected a spy, but got undefined.');
606
-
607
- expect(function() {
608
- match({some:'object'})[methodName]();
609
- }).toThrow('Expected a spy, but got { some : \'object\' }.');
610
-
611
- expect(function() {
612
- match("<b>")[methodName]();
613
- }).toThrow('Expected a spy, but got \'<b>\'.');
614
- };
615
- }
616
-
617
- describe("toHaveBeenCalled", function() {
618
- it("should pass if the spy was called", function() {
619
- expect(match(TestClass.spyFunction).toHaveBeenCalled()).toFail();
620
-
621
- TestClass.spyFunction();
622
- expect(match(TestClass.spyFunction).toHaveBeenCalled()).toPass();
623
- });
624
-
625
- it("should throw an exception when invoked with any arguments", function() {
626
- expect(function() {
627
- match(TestClass.normalFunction).toHaveBeenCalled("unwanted argument");
628
- }).toThrow('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
629
- });
630
-
631
- it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalled'));
632
- });
633
-
634
- describe("wasCalled", function() {
635
- it("should alias toHaveBeenCalled", function() {
636
- spyOn(TestClass, 'normalFunction');
637
-
638
- TestClass.normalFunction();
639
-
640
- expect(TestClass.normalFunction).wasCalled();
641
- });
642
- });
643
-
644
-
645
- describe("wasNotCalled", function() {
646
- it("should pass iff the spy was not called", function() {
647
- expect(match(TestClass.spyFunction).wasNotCalled()).toPass();
648
-
649
- TestClass.spyFunction();
650
- expect(match(TestClass.spyFunction).wasNotCalled()).toFail();
651
- });
652
-
653
- it("should throw an exception when invoked with any arguments", function() {
654
- expect(function() {
655
- match(TestClass.normalFunction).wasNotCalled("unwanted argument");
656
- }).toThrow('wasNotCalled does not take arguments');
657
- });
658
-
659
- it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalled'));
660
- });
661
-
662
- describe("toHaveBeenCalledWith", function() {
663
- it('toHaveBeenCalledWith should return true if it was called with the expected args', function() {
664
- TestClass.spyFunction('a', 'b', 'c');
665
- expect(match(TestClass.spyFunction).toHaveBeenCalledWith('a', 'b', 'c')).toPass();
666
- });
667
-
668
- it('should return false if it was not called with the expected args', function() {
669
- TestClass.spyFunction('a', 'b', 'c');
670
- var expected = match(TestClass.spyFunction);
671
- expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail();
672
- var result = lastResult();
673
- expect(result.passed()).toFail();
674
- expect(result.expected).toEqual(['c', 'b', 'a']);
675
- expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
676
- expect(result.message).toContain(jasmine.pp(result.expected));
677
- expect(result.message).toContain(jasmine.pp(result.actual.mostRecentCall.args));
678
- });
679
-
680
- it('should return false if it was not called', function() {
681
- var expected = match(TestClass.spyFunction);
682
- expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail();
683
- var result = lastResult();
684
- expect(result.passed()).toFail();
685
- expect(result.expected).toEqual(['c', 'b', 'a']);
686
- expect(result.actual.argsForCall).toEqual([]);
687
- expect(result.message).toContain(jasmine.pp(result.expected));
688
- });
689
-
690
- it('should allow matches across multiple calls', function() {
691
- TestClass.spyFunction('a', 'b', 'c');
692
- TestClass.spyFunction('d', 'e', 'f');
693
- var expected = match(TestClass.spyFunction);
694
- expect(expected.toHaveBeenCalledWith('a', 'b', 'c')).toPass();
695
- expect(expected.toHaveBeenCalledWith('d', 'e', 'f')).toPass();
696
- expect(expected.toHaveBeenCalledWith('x', 'y', 'z')).toFail();
697
- });
698
-
699
- it("should return a decent message", function() {
700
- TestClass.spyFunction('a', 'b', 'c');
701
- TestClass.spyFunction('d', 'e', 'f');
702
- var expected = match(TestClass.spyFunction);
703
- expect(expected.toHaveBeenCalledWith('a', 'b')).toFail();
704
- expect(lastResult().message).toEqual("Expected spy to have been called with [ 'a', 'b' ] but was called with [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]");
705
- });
706
-
707
- it("should return a decent message when inverted", function() {
708
- TestClass.spyFunction('a', 'b', 'c');
709
- TestClass.spyFunction('d', 'e', 'f');
710
- var expected = match(TestClass.spyFunction);
711
- expect(expected.not.toHaveBeenCalledWith('a', 'b', 'c')).toFail();
712
- expect(lastResult().message).toEqual("Expected spy not to have been called with [ 'a', 'b', 'c' ] but was called with [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]");
713
- });
714
-
715
- it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalledWith'));
716
-
717
- describe("to build an ExpectationResult", function () {
718
- beforeEach(function() {
719
- var currentSuite;
720
- var spec;
721
- currentSuite = env.describe('default current suite', function() {
722
- spec = env.it();
723
- }, spec);
724
- TestClass = { someFunction: function(a, b) {
725
- } };
726
- spec.spyOn(TestClass, 'someFunction');
727
- });
728
-
729
- it("should should handle the case of a spy", function() {
730
- TestClass.someFunction('a', 'c');
731
- var matcher = match(TestClass.someFunction);
732
- matcher.toHaveBeenCalledWith('a', 'b');
733
-
734
- var result = lastResult();
735
- expect(result.matcherName).toEqual("toHaveBeenCalledWith");
736
- expect(result.passed()).toFail();
737
- expect(result.message).toContain(jasmine.pp(['a', 'b']));
738
- expect(result.message).toContain(jasmine.pp(['a', 'c']));
739
- expect(result.actual).toEqual(TestClass.someFunction);
740
- expect(result.expected).toEqual(['a','b']);
741
- });
742
- });
743
- });
744
-
745
- describe("wasCalledWith", function() {
746
- it("should alias toHaveBeenCalledWith", function() {
747
- spyOn(TestClass, 'normalFunction');
748
-
749
- TestClass.normalFunction(123);
750
-
751
- expect(TestClass.normalFunction).wasCalledWith(123);
752
- });
753
- });
754
-
755
- describe("wasNotCalledWith", function() {
756
- it('should return true if the spy was NOT called with the expected args', function() {
757
- TestClass.spyFunction('a', 'b', 'c');
758
- expect(match(TestClass.spyFunction).wasNotCalledWith('c', 'b', 'a')).toPass();
759
- });
760
-
761
- it('should return false if it WAS called with the expected args', function() {
762
- TestClass.spyFunction('a', 'b', 'c');
763
- var expected = match(TestClass.spyFunction);
764
- expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail();
765
- var result = lastResult();
766
- expect(result.passed()).toFail();
767
- expect(result.expected).toEqual(['a', 'b', 'c']);
768
- expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
769
- expect(result.message).toContain(jasmine.pp(result.expected));
770
- });
771
-
772
- it('should return true if it was not called', function() {
773
- var expected = match(TestClass.spyFunction);
774
- expect(expected.wasNotCalledWith('c', 'b', 'a')).toPass();
775
- });
776
-
777
- it('should allow matches across multiple calls', function() {
778
- var expected = match(TestClass.spyFunction);
779
- TestClass.spyFunction('a', 'b', 'c');
780
- TestClass.spyFunction('d', 'e', 'f');
781
- expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail();
782
- expect(expected.wasNotCalledWith('d', 'e', 'f')).toFail();
783
- expect(expected.wasNotCalledWith('x', 'y', 'z')).toPass();
784
- });
785
-
786
- it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalledWith'));
787
- });
788
- });
789
-
790
- describe("all matchers", function() {
791
- it("should return null, for future-proofing, since we might eventually allow matcher chaining", function() {
792
- expect(match(true).toBe(true)).toBeUndefined();
793
- });
794
- });
795
- });