josephholsten-jasmine 1.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.gitignore +11 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +5 -0
  4. data/HOW_TO_TEST.markdown +9 -0
  5. data/MIT.LICENSE +20 -0
  6. data/README.markdown +71 -0
  7. data/RELEASE.markdown +22 -0
  8. data/Rakefile +76 -0
  9. data/bin/jasmine +6 -0
  10. data/generators/jasmine/jasmine_generator.rb +32 -0
  11. data/generators/jasmine/templates/INSTALL +9 -0
  12. data/generators/jasmine/templates/jasmine-example/SpecRunner.html +27 -0
  13. data/generators/jasmine/templates/jasmine-example/spec/PlayerSpec.js +58 -0
  14. data/generators/jasmine/templates/jasmine-example/spec/SpecHelper.js +9 -0
  15. data/generators/jasmine/templates/jasmine-example/src/Player.js +22 -0
  16. data/generators/jasmine/templates/jasmine-example/src/Song.js +7 -0
  17. data/generators/jasmine/templates/lib/tasks/jasmine.rake +8 -0
  18. data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  19. data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  20. data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  21. data/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  22. data/jasmine/Gemfile +6 -0
  23. data/jasmine/Gemfile.lock +33 -0
  24. data/jasmine/HowToRelease.markdown +29 -0
  25. data/jasmine/MIT.LICENSE +20 -0
  26. data/jasmine/README.markdown +50 -0
  27. data/jasmine/Rakefile +166 -0
  28. data/jasmine/cruise_config.rb +21 -0
  29. data/jasmine/example/SpecRunner.html +27 -0
  30. data/jasmine/example/spec/PlayerSpec.js +58 -0
  31. data/jasmine/example/spec/SpecHelper.js +9 -0
  32. data/jasmine/example/src/Player.js +22 -0
  33. data/jasmine/example/src/Song.js +7 -0
  34. data/jasmine/images/jasmine_favicon.png +0 -0
  35. data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
  36. data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
  37. data/jasmine/jsdoc-template/class.tmpl +646 -0
  38. data/jasmine/jsdoc-template/index.tmpl +39 -0
  39. data/jasmine/jsdoc-template/publish.js +184 -0
  40. data/jasmine/jsdoc-template/static/default.css +162 -0
  41. data/jasmine/jsdoc-template/static/header.html +2 -0
  42. data/jasmine/jsdoc-template/static/index.html +19 -0
  43. data/jasmine/jsdoc-template/symbol.tmpl +35 -0
  44. data/jasmine/jshint/jshint.js +5919 -0
  45. data/jasmine/jshint/run.js +98 -0
  46. data/jasmine/lib/jasmine-html.js +190 -0
  47. data/jasmine/lib/jasmine.css +166 -0
  48. data/jasmine/lib/jasmine.js +2445 -0
  49. data/jasmine/lib/json2.js +478 -0
  50. data/jasmine/spec/node_suite.js +233 -0
  51. data/jasmine/spec/runner.html +82 -0
  52. data/jasmine/spec/suites/BaseSpec.js +27 -0
  53. data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
  54. data/jasmine/spec/suites/EnvSpec.js +158 -0
  55. data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  56. data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
  57. data/jasmine/spec/suites/MatchersSpec.js +795 -0
  58. data/jasmine/spec/suites/MockClockSpec.js +38 -0
  59. data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
  60. data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  61. data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  62. data/jasmine/spec/suites/QueueSpec.js +23 -0
  63. data/jasmine/spec/suites/ReporterSpec.js +56 -0
  64. data/jasmine/spec/suites/RunnerSpec.js +267 -0
  65. data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
  66. data/jasmine/spec/suites/SpecSpec.js +124 -0
  67. data/jasmine/spec/suites/SpySpec.js +201 -0
  68. data/jasmine/spec/suites/SuiteSpec.js +120 -0
  69. data/jasmine/spec/suites/TrivialConsoleReporterSpec.js +431 -0
  70. data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
  71. data/jasmine/spec/suites/UtilSpec.js +39 -0
  72. data/jasmine/spec/suites/WaitsForBlockSpec.js +118 -0
  73. data/jasmine/src/Block.js +22 -0
  74. data/jasmine/src/Env.js +264 -0
  75. data/jasmine/src/JsApiReporter.js +102 -0
  76. data/jasmine/src/Matchers.js +354 -0
  77. data/jasmine/src/MultiReporter.js +35 -0
  78. data/jasmine/src/NestedResults.js +80 -0
  79. data/jasmine/src/PrettyPrinter.js +123 -0
  80. data/jasmine/src/Queue.js +99 -0
  81. data/jasmine/src/Reporter.js +31 -0
  82. data/jasmine/src/Runner.js +77 -0
  83. data/jasmine/src/Spec.js +242 -0
  84. data/jasmine/src/Suite.js +82 -0
  85. data/jasmine/src/WaitsBlock.js +15 -0
  86. data/jasmine/src/WaitsForBlock.js +54 -0
  87. data/jasmine/src/base.js +608 -0
  88. data/jasmine/src/console/TrivialConsoleReporter.js +144 -0
  89. data/jasmine/src/html/TrivialReporter.js +190 -0
  90. data/jasmine/src/html/jasmine.css +166 -0
  91. data/jasmine/src/mock-timeout.js +183 -0
  92. data/jasmine/src/util.js +67 -0
  93. data/jasmine/src/version.json +5 -0
  94. data/jasmine.gemspec +52 -0
  95. data/lib/generators/jasmine/examples/USAGE +11 -0
  96. data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
  97. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
  98. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
  99. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
  100. data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
  101. data/lib/generators/jasmine/install/USAGE +11 -0
  102. data/lib/generators/jasmine/install/install_generator.rb +18 -0
  103. data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
  104. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
  105. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  106. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
  107. data/lib/generators/jasmine/jasmine_generator.rb +32 -0
  108. data/lib/generators/jasmine/templates/INSTALL +9 -0
  109. data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
  110. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  111. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  112. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  113. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  114. data/lib/jasmine/base.rb +66 -0
  115. data/lib/jasmine/command_line_tool.rb +72 -0
  116. data/lib/jasmine/config.rb +190 -0
  117. data/lib/jasmine/railtie.rb +20 -0
  118. data/lib/jasmine/run.html.erb +44 -0
  119. data/lib/jasmine/selenium_driver.rb +49 -0
  120. data/lib/jasmine/server.rb +106 -0
  121. data/lib/jasmine/spec_builder.rb +162 -0
  122. data/lib/jasmine/tasks/jasmine.rake +44 -0
  123. data/lib/jasmine/version.rb +3 -0
  124. data/lib/jasmine.rb +14 -0
  125. data/spec/config_spec.rb +308 -0
  126. data/spec/fixture/jasmine.erb.yml +4 -0
  127. data/spec/jasmine_command_line_tool_spec.rb +29 -0
  128. data/spec/jasmine_pojs_spec.rb +51 -0
  129. data/spec/jasmine_rails2_spec.rb +93 -0
  130. data/spec/jasmine_rails3_spec.rb +71 -0
  131. data/spec/jasmine_self_test_config.rb +15 -0
  132. data/spec/jasmine_self_test_spec.rb +24 -0
  133. data/spec/server_spec.rb +80 -0
  134. data/spec/spec_helper.rb +65 -0
  135. metadata +386 -0
@@ -0,0 +1,354 @@
1
+ /**
2
+ * @constructor
3
+ * @param {jasmine.Env} env
4
+ * @param actual
5
+ * @param {jasmine.Spec} spec
6
+ */
7
+ jasmine.Matchers = function(env, actual, spec, opt_isNot) {
8
+ this.env = env;
9
+ this.actual = actual;
10
+ this.spec = spec;
11
+ this.isNot = opt_isNot || false;
12
+ this.reportWasCalled_ = false;
13
+ };
14
+
15
+ // todo: @deprecated as of Jasmine 0.11, remove soon [xw]
16
+ jasmine.Matchers.pp = function(str) {
17
+ throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!");
18
+ };
19
+
20
+ // todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw]
21
+ jasmine.Matchers.prototype.report = function(result, failing_message, details) {
22
+ throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs");
23
+ };
24
+
25
+ jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
26
+ for (var methodName in prototype) {
27
+ if (methodName == 'report') continue;
28
+ var orig = prototype[methodName];
29
+ matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig);
30
+ }
31
+ };
32
+
33
+ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
34
+ return function() {
35
+ var matcherArgs = jasmine.util.argsToArray(arguments);
36
+ var result = matcherFunction.apply(this, arguments);
37
+
38
+ if (this.isNot) {
39
+ result = !result;
40
+ }
41
+
42
+ if (this.reportWasCalled_) return result;
43
+
44
+ var message;
45
+ if (!result) {
46
+ if (this.message) {
47
+ message = this.message.apply(this, arguments);
48
+ if (jasmine.isArray_(message)) {
49
+ message = message[this.isNot ? 1 : 0];
50
+ }
51
+ } else {
52
+ var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
53
+ message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate;
54
+ if (matcherArgs.length > 0) {
55
+ for (var i = 0; i < matcherArgs.length; i++) {
56
+ if (i > 0) message += ",";
57
+ message += " " + jasmine.pp(matcherArgs[i]);
58
+ }
59
+ }
60
+ message += ".";
61
+ }
62
+ }
63
+ var expectationResult = new jasmine.ExpectationResult({
64
+ matcherName: matcherName,
65
+ passed: result,
66
+ expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
67
+ actual: this.actual,
68
+ message: message
69
+ });
70
+ this.spec.addMatcherResult(expectationResult);
71
+ return jasmine.undefined;
72
+ };
73
+ };
74
+
75
+
76
+
77
+
78
+ /**
79
+ * toBe: compares the actual to the expected using ===
80
+ * @param expected
81
+ */
82
+ jasmine.Matchers.prototype.toBe = function(expected) {
83
+ return this.actual === expected;
84
+ };
85
+
86
+ /**
87
+ * toNotBe: compares the actual to the expected using !==
88
+ * @param expected
89
+ * @deprecated as of 1.0. Use not.toBe() instead.
90
+ */
91
+ jasmine.Matchers.prototype.toNotBe = function(expected) {
92
+ return this.actual !== expected;
93
+ };
94
+
95
+ /**
96
+ * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc.
97
+ *
98
+ * @param expected
99
+ */
100
+ jasmine.Matchers.prototype.toEqual = function(expected) {
101
+ return this.env.equals_(this.actual, expected);
102
+ };
103
+
104
+ /**
105
+ * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
106
+ * @param expected
107
+ * @deprecated as of 1.0. Use not.toNotEqual() instead.
108
+ */
109
+ jasmine.Matchers.prototype.toNotEqual = function(expected) {
110
+ return !this.env.equals_(this.actual, expected);
111
+ };
112
+
113
+ /**
114
+ * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes
115
+ * a pattern or a String.
116
+ *
117
+ * @param expected
118
+ */
119
+ jasmine.Matchers.prototype.toMatch = function(expected) {
120
+ return new RegExp(expected).test(this.actual);
121
+ };
122
+
123
+ /**
124
+ * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
125
+ * @param expected
126
+ * @deprecated as of 1.0. Use not.toMatch() instead.
127
+ */
128
+ jasmine.Matchers.prototype.toNotMatch = function(expected) {
129
+ return !(new RegExp(expected).test(this.actual));
130
+ };
131
+
132
+ /**
133
+ * Matcher that compares the actual to jasmine.undefined.
134
+ */
135
+ jasmine.Matchers.prototype.toBeDefined = function() {
136
+ return (this.actual !== jasmine.undefined);
137
+ };
138
+
139
+ /**
140
+ * Matcher that compares the actual to jasmine.undefined.
141
+ */
142
+ jasmine.Matchers.prototype.toBeUndefined = function() {
143
+ return (this.actual === jasmine.undefined);
144
+ };
145
+
146
+ /**
147
+ * Matcher that compares the actual to null.
148
+ */
149
+ jasmine.Matchers.prototype.toBeNull = function() {
150
+ return (this.actual === null);
151
+ };
152
+
153
+ /**
154
+ * Matcher that boolean not-nots the actual.
155
+ */
156
+ jasmine.Matchers.prototype.toBeTruthy = function() {
157
+ return !!this.actual;
158
+ };
159
+
160
+
161
+ /**
162
+ * Matcher that boolean nots the actual.
163
+ */
164
+ jasmine.Matchers.prototype.toBeFalsy = function() {
165
+ return !this.actual;
166
+ };
167
+
168
+
169
+ /**
170
+ * Matcher that checks to see if the actual, a Jasmine spy, was called.
171
+ */
172
+ jasmine.Matchers.prototype.toHaveBeenCalled = function() {
173
+ if (arguments.length > 0) {
174
+ throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
175
+ }
176
+
177
+ if (!jasmine.isSpy(this.actual)) {
178
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
179
+ }
180
+
181
+ this.message = function() {
182
+ return [
183
+ "Expected spy " + this.actual.identity + " to have been called.",
184
+ "Expected spy " + this.actual.identity + " not to have been called."
185
+ ];
186
+ };
187
+
188
+ return this.actual.wasCalled;
189
+ };
190
+
191
+ /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
192
+ jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled;
193
+
194
+ /**
195
+ * Matcher that checks to see if the actual, a Jasmine spy, was not called.
196
+ *
197
+ * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead
198
+ */
199
+ jasmine.Matchers.prototype.wasNotCalled = function() {
200
+ if (arguments.length > 0) {
201
+ throw new Error('wasNotCalled does not take arguments');
202
+ }
203
+
204
+ if (!jasmine.isSpy(this.actual)) {
205
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
206
+ }
207
+
208
+ this.message = function() {
209
+ return [
210
+ "Expected spy " + this.actual.identity + " to not have been called.",
211
+ "Expected spy " + this.actual.identity + " to have been called."
212
+ ];
213
+ };
214
+
215
+ return !this.actual.wasCalled;
216
+ };
217
+
218
+ /**
219
+ * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
220
+ *
221
+ * @example
222
+ *
223
+ */
224
+ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
225
+ var expectedArgs = jasmine.util.argsToArray(arguments);
226
+ if (!jasmine.isSpy(this.actual)) {
227
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
228
+ }
229
+ this.message = function() {
230
+ if (this.actual.callCount === 0) {
231
+ // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
232
+ return [
233
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
234
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
235
+ ];
236
+ } else {
237
+ return [
238
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
239
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
240
+ ];
241
+ }
242
+ };
243
+
244
+ return this.env.contains_(this.actual.argsForCall, expectedArgs);
245
+ };
246
+
247
+ /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
248
+ jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith;
249
+
250
+ /** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */
251
+ jasmine.Matchers.prototype.wasNotCalledWith = function() {
252
+ var expectedArgs = jasmine.util.argsToArray(arguments);
253
+ if (!jasmine.isSpy(this.actual)) {
254
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
255
+ }
256
+
257
+ this.message = function() {
258
+ return [
259
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
260
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
261
+ ];
262
+ };
263
+
264
+ return !this.env.contains_(this.actual.argsForCall, expectedArgs);
265
+ };
266
+
267
+ /**
268
+ * Matcher that checks that the expected item is an element in the actual Array.
269
+ *
270
+ * @param {Object} expected
271
+ */
272
+ jasmine.Matchers.prototype.toContain = function(expected) {
273
+ return this.env.contains_(this.actual, expected);
274
+ };
275
+
276
+ /**
277
+ * Matcher that checks that the expected item is NOT an element in the actual Array.
278
+ *
279
+ * @param {Object} expected
280
+ * @deprecated as of 1.0. Use not.toNotContain() instead.
281
+ */
282
+ jasmine.Matchers.prototype.toNotContain = function(expected) {
283
+ return !this.env.contains_(this.actual, expected);
284
+ };
285
+
286
+ jasmine.Matchers.prototype.toBeLessThan = function(expected) {
287
+ return this.actual < expected;
288
+ };
289
+
290
+ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
291
+ return this.actual > expected;
292
+ };
293
+
294
+ /**
295
+ * Matcher that checks that the expected exception was thrown by the actual.
296
+ *
297
+ * @param {String} expected
298
+ */
299
+ jasmine.Matchers.prototype.toThrow = function(expected) {
300
+ var result = false;
301
+ var exception;
302
+ if (typeof this.actual != 'function') {
303
+ throw new Error('Actual is not a function');
304
+ }
305
+ try {
306
+ this.actual();
307
+ } catch (e) {
308
+ exception = e;
309
+ }
310
+ if (exception) {
311
+ result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
312
+ }
313
+
314
+ var not = this.isNot ? "not " : "";
315
+
316
+ this.message = function() {
317
+ if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
318
+ return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
319
+ } else {
320
+ return "Expected function to throw an exception.";
321
+ }
322
+ };
323
+
324
+ return result;
325
+ };
326
+
327
+ jasmine.Matchers.Any = function(expectedClass) {
328
+ this.expectedClass = expectedClass;
329
+ };
330
+
331
+ jasmine.Matchers.Any.prototype.matches = function(other) {
332
+ if (this.expectedClass == String) {
333
+ return typeof other == 'string' || other instanceof String;
334
+ }
335
+
336
+ if (this.expectedClass == Number) {
337
+ return typeof other == 'number' || other instanceof Number;
338
+ }
339
+
340
+ if (this.expectedClass == Function) {
341
+ return typeof other == 'function' || other instanceof Function;
342
+ }
343
+
344
+ if (this.expectedClass == Object) {
345
+ return typeof other == 'object';
346
+ }
347
+
348
+ return other instanceof this.expectedClass;
349
+ };
350
+
351
+ jasmine.Matchers.Any.prototype.toString = function() {
352
+ return '<jasmine.any(' + this.expectedClass + ')>';
353
+ };
354
+
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @constructor
3
+ */
4
+ jasmine.MultiReporter = function() {
5
+ this.subReporters_ = [];
6
+ };
7
+ jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter);
8
+
9
+ jasmine.MultiReporter.prototype.addReporter = function(reporter) {
10
+ this.subReporters_.push(reporter);
11
+ };
12
+
13
+ (function() {
14
+ var functionNames = [
15
+ "reportRunnerStarting",
16
+ "reportRunnerResults",
17
+ "reportSuiteResults",
18
+ "reportSpecStarting",
19
+ "reportSpecResults",
20
+ "log"
21
+ ];
22
+ for (var i = 0; i < functionNames.length; i++) {
23
+ var functionName = functionNames[i];
24
+ jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
25
+ return function() {
26
+ for (var j = 0; j < this.subReporters_.length; j++) {
27
+ var subReporter = this.subReporters_[j];
28
+ if (subReporter[functionName]) {
29
+ subReporter[functionName].apply(subReporter, arguments);
30
+ }
31
+ }
32
+ };
33
+ })(functionName);
34
+ }
35
+ })();
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults
3
+ *
4
+ * @constructor
5
+ */
6
+ jasmine.NestedResults = function() {
7
+ /**
8
+ * The total count of results
9
+ */
10
+ this.totalCount = 0;
11
+ /**
12
+ * Number of passed results
13
+ */
14
+ this.passedCount = 0;
15
+ /**
16
+ * Number of failed results
17
+ */
18
+ this.failedCount = 0;
19
+ /**
20
+ * Was this suite/spec skipped?
21
+ */
22
+ this.skipped = false;
23
+ /**
24
+ * @ignore
25
+ */
26
+ this.items_ = [];
27
+ };
28
+
29
+ /**
30
+ * Roll up the result counts.
31
+ *
32
+ * @param result
33
+ */
34
+ jasmine.NestedResults.prototype.rollupCounts = function(result) {
35
+ this.totalCount += result.totalCount;
36
+ this.passedCount += result.passedCount;
37
+ this.failedCount += result.failedCount;
38
+ };
39
+
40
+ /**
41
+ * Adds a log message.
42
+ * @param values Array of message parts which will be concatenated later.
43
+ */
44
+ jasmine.NestedResults.prototype.log = function(values) {
45
+ this.items_.push(new jasmine.MessageResult(values));
46
+ };
47
+
48
+ /**
49
+ * Getter for the results: message & results.
50
+ */
51
+ jasmine.NestedResults.prototype.getItems = function() {
52
+ return this.items_;
53
+ };
54
+
55
+ /**
56
+ * Adds a result, tracking counts (total, passed, & failed)
57
+ * @param {jasmine.ExpectationResult|jasmine.NestedResults} result
58
+ */
59
+ jasmine.NestedResults.prototype.addResult = function(result) {
60
+ if (result.type != 'log') {
61
+ if (result.items_) {
62
+ this.rollupCounts(result);
63
+ } else {
64
+ this.totalCount++;
65
+ if (result.passed()) {
66
+ this.passedCount++;
67
+ } else {
68
+ this.failedCount++;
69
+ }
70
+ }
71
+ }
72
+ this.items_.push(result);
73
+ };
74
+
75
+ /**
76
+ * @returns {Boolean} True if <b>everything</b> below passed
77
+ */
78
+ jasmine.NestedResults.prototype.passed = function() {
79
+ return this.passedCount === this.totalCount;
80
+ };
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Base class for pretty printing for expectation results.
3
+ */
4
+ jasmine.PrettyPrinter = function() {
5
+ this.ppNestLevel_ = 0;
6
+ };
7
+
8
+ /**
9
+ * Formats a value in a nice, human-readable string.
10
+ *
11
+ * @param value
12
+ */
13
+ jasmine.PrettyPrinter.prototype.format = function(value) {
14
+ if (this.ppNestLevel_ > 40) {
15
+ throw new Error('jasmine.PrettyPrinter: format() nested too deeply!');
16
+ }
17
+
18
+ this.ppNestLevel_++;
19
+ try {
20
+ if (value === jasmine.undefined) {
21
+ this.emitScalar('undefined');
22
+ } else if (value === null) {
23
+ this.emitScalar('null');
24
+ } else if (value === jasmine.getGlobal()) {
25
+ this.emitScalar('<global>');
26
+ } else if (value instanceof jasmine.Matchers.Any) {
27
+ this.emitScalar(value.toString());
28
+ } else if (typeof value === 'string') {
29
+ this.emitString(value);
30
+ } else if (jasmine.isSpy(value)) {
31
+ this.emitScalar("spy on " + value.identity);
32
+ } else if (value instanceof RegExp) {
33
+ this.emitScalar(value.toString());
34
+ } else if (typeof value === 'function') {
35
+ this.emitScalar('Function');
36
+ } else if (typeof value.nodeType === 'number') {
37
+ this.emitScalar('HTMLNode');
38
+ } else if (value instanceof Date) {
39
+ this.emitScalar('Date(' + value + ')');
40
+ } else if (value.__Jasmine_been_here_before__) {
41
+ this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>');
42
+ } else if (jasmine.isArray_(value) || typeof value == 'object') {
43
+ value.__Jasmine_been_here_before__ = true;
44
+ if (jasmine.isArray_(value)) {
45
+ this.emitArray(value);
46
+ } else {
47
+ this.emitObject(value);
48
+ }
49
+ delete value.__Jasmine_been_here_before__;
50
+ } else {
51
+ this.emitScalar(value.toString());
52
+ }
53
+ } finally {
54
+ this.ppNestLevel_--;
55
+ }
56
+ };
57
+
58
+ jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
59
+ for (var property in obj) {
60
+ if (property == '__Jasmine_been_here_before__') continue;
61
+ fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
62
+ obj.__lookupGetter__(property) !== null) : false);
63
+ }
64
+ };
65
+
66
+ jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_;
67
+ jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_;
68
+ jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_;
69
+ jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_;
70
+
71
+ jasmine.StringPrettyPrinter = function() {
72
+ jasmine.PrettyPrinter.call(this);
73
+
74
+ this.string = '';
75
+ };
76
+ jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter);
77
+
78
+ jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) {
79
+ this.append(value);
80
+ };
81
+
82
+ jasmine.StringPrettyPrinter.prototype.emitString = function(value) {
83
+ this.append("'" + value + "'");
84
+ };
85
+
86
+ jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
87
+ this.append('[ ');
88
+ for (var i = 0; i < array.length; i++) {
89
+ if (i > 0) {
90
+ this.append(', ');
91
+ }
92
+ this.format(array[i]);
93
+ }
94
+ this.append(' ]');
95
+ };
96
+
97
+ jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) {
98
+ var self = this;
99
+ this.append('{ ');
100
+ var first = true;
101
+
102
+ this.iterateObject(obj, function(property, isGetter) {
103
+ if (first) {
104
+ first = false;
105
+ } else {
106
+ self.append(', ');
107
+ }
108
+
109
+ self.append(property);
110
+ self.append(' : ');
111
+ if (isGetter) {
112
+ self.append('<getter>');
113
+ } else {
114
+ self.format(obj[property]);
115
+ }
116
+ });
117
+
118
+ this.append(' }');
119
+ };
120
+
121
+ jasmine.StringPrettyPrinter.prototype.append = function(value) {
122
+ this.string += value;
123
+ };
@@ -0,0 +1,99 @@
1
+ jasmine.Queue = function(env) {
2
+ this.env = env;
3
+ this.blocks = [];
4
+ this.running = false;
5
+ this.index = 0;
6
+ this.offset = 0;
7
+ this.abort = false;
8
+ };
9
+
10
+ jasmine.Queue.prototype.addBefore = function(block) {
11
+ this.blocks.unshift(block);
12
+ };
13
+
14
+ jasmine.Queue.prototype.add = function(block) {
15
+ this.blocks.push(block);
16
+ };
17
+
18
+ jasmine.Queue.prototype.insertNext = function(block) {
19
+ this.blocks.splice((this.index + this.offset + 1), 0, block);
20
+ this.offset++;
21
+ };
22
+
23
+ jasmine.Queue.prototype.start = function(onComplete) {
24
+ this.running = true;
25
+ this.onComplete = onComplete;
26
+ this.next_();
27
+ };
28
+
29
+ jasmine.Queue.prototype.isRunning = function() {
30
+ return this.running;
31
+ };
32
+
33
+ jasmine.Queue.LOOP_DONT_RECURSE = true;
34
+
35
+ jasmine.Queue.prototype.next_ = function() {
36
+ var self = this;
37
+ var goAgain = true;
38
+
39
+ while (goAgain) {
40
+ goAgain = false;
41
+
42
+ if (self.index < self.blocks.length && !this.abort) {
43
+ var calledSynchronously = true;
44
+ var completedSynchronously = false;
45
+
46
+ var onComplete = function () {
47
+ if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) {
48
+ completedSynchronously = true;
49
+ return;
50
+ }
51
+
52
+ if (self.blocks[self.index].abort) {
53
+ self.abort = true;
54
+ }
55
+
56
+ self.offset = 0;
57
+ self.index++;
58
+
59
+ var now = new Date().getTime();
60
+ if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
61
+ self.env.lastUpdate = now;
62
+ self.env.setTimeout(function() {
63
+ self.next_();
64
+ }, 0);
65
+ } else {
66
+ if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
67
+ goAgain = true;
68
+ } else {
69
+ self.next_();
70
+ }
71
+ }
72
+ };
73
+ self.blocks[self.index].execute(onComplete);
74
+
75
+ calledSynchronously = false;
76
+ if (completedSynchronously) {
77
+ onComplete();
78
+ }
79
+
80
+ } else {
81
+ self.running = false;
82
+ if (self.onComplete) {
83
+ self.onComplete();
84
+ }
85
+ }
86
+ }
87
+ };
88
+
89
+ jasmine.Queue.prototype.results = function() {
90
+ var results = new jasmine.NestedResults();
91
+ for (var i = 0; i < this.blocks.length; i++) {
92
+ if (this.blocks[i].results) {
93
+ results.addResult(this.blocks[i].results());
94
+ }
95
+ }
96
+ return results;
97
+ };
98
+
99
+