jasmine 1.0.1.1 → 1.0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +11 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +5 -0
  4. data/HOW_TO_TEST.markdown +11 -0
  5. data/README.markdown +42 -14
  6. data/RELEASE.markdown +22 -0
  7. data/Rakefile +76 -0
  8. data/generators/jasmine/jasmine_generator.rb +15 -13
  9. data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  10. data/install.rb +2 -0
  11. data/jasmine.gemspec +52 -0
  12. data/jasmine/Gemfile +6 -0
  13. data/jasmine/MIT.LICENSE +20 -0
  14. data/jasmine/README.markdown +28 -0
  15. data/jasmine/Rakefile +182 -0
  16. data/jasmine/cruise_config.rb +21 -0
  17. data/jasmine/example/spec/PlayerSpec.js +58 -0
  18. data/jasmine/example/spec/SpecHelper.js +9 -0
  19. data/jasmine/example/src/Player.js +22 -0
  20. data/jasmine/example/src/Song.js +7 -0
  21. data/jasmine/images/fail-16.png +0 -0
  22. data/jasmine/images/fail.png +0 -0
  23. data/jasmine/images/go-16.png +0 -0
  24. data/jasmine/images/go.png +0 -0
  25. data/jasmine/images/pending-16.png +0 -0
  26. data/jasmine/images/pending.png +0 -0
  27. data/jasmine/images/question-bk.png +0 -0
  28. data/jasmine/images/questionbk-16.png +0 -0
  29. data/jasmine/images/spinner.gif +0 -0
  30. data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
  31. data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
  32. data/jasmine/jsdoc-template/class.tmpl +646 -0
  33. data/jasmine/jsdoc-template/index.tmpl +39 -0
  34. data/jasmine/jsdoc-template/publish.js +184 -0
  35. data/jasmine/jsdoc-template/static/default.css +162 -0
  36. data/jasmine/jsdoc-template/static/header.html +2 -0
  37. data/jasmine/jsdoc-template/static/index.html +19 -0
  38. data/jasmine/jsdoc-template/symbol.tmpl +35 -0
  39. data/jasmine/spec/runner.html +80 -0
  40. data/jasmine/spec/suites/BaseSpec.js +27 -0
  41. data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
  42. data/jasmine/spec/suites/EnvSpec.js +158 -0
  43. data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  44. data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
  45. data/jasmine/spec/suites/MatchersSpec.js +795 -0
  46. data/jasmine/spec/suites/MockClockSpec.js +38 -0
  47. data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
  48. data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  49. data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  50. data/jasmine/spec/suites/QueueSpec.js +23 -0
  51. data/jasmine/spec/suites/ReporterSpec.js +56 -0
  52. data/jasmine/spec/suites/RunnerSpec.js +267 -0
  53. data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
  54. data/jasmine/spec/suites/SpecSpec.js +124 -0
  55. data/jasmine/spec/suites/SpySpec.js +201 -0
  56. data/jasmine/spec/suites/SuiteSpec.js +120 -0
  57. data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
  58. data/jasmine/spec/suites/UtilSpec.js +40 -0
  59. data/jasmine/spec/suites/WaitsForBlockSpec.js +87 -0
  60. data/jasmine/src/Block.js +22 -0
  61. data/jasmine/src/Env.js +264 -0
  62. data/jasmine/src/JsApiReporter.js +102 -0
  63. data/jasmine/src/Matchers.js +354 -0
  64. data/jasmine/src/MultiReporter.js +35 -0
  65. data/jasmine/src/NestedResults.js +80 -0
  66. data/jasmine/src/PrettyPrinter.js +122 -0
  67. data/jasmine/src/Queue.js +99 -0
  68. data/jasmine/src/Reporter.js +31 -0
  69. data/jasmine/src/Runner.js +77 -0
  70. data/jasmine/src/Spec.js +242 -0
  71. data/jasmine/src/Suite.js +82 -0
  72. data/jasmine/src/WaitsBlock.js +13 -0
  73. data/jasmine/src/WaitsForBlock.js +52 -0
  74. data/jasmine/src/base.js +589 -0
  75. data/jasmine/src/html/TrivialReporter.js +188 -0
  76. data/jasmine/src/html/jasmine.css +166 -0
  77. data/jasmine/src/mock-timeout.js +183 -0
  78. data/jasmine/src/util.js +67 -0
  79. data/jasmine/src/version.json +5 -0
  80. data/lib/generators/jasmine/examples/USAGE +11 -0
  81. data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
  82. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
  83. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
  84. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
  85. data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
  86. data/lib/generators/jasmine/install/USAGE +11 -0
  87. data/lib/generators/jasmine/install/install_generator.rb +18 -0
  88. data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
  89. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
  90. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  91. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
  92. data/lib/generators/jasmine/jasmine_generator.rb +32 -0
  93. data/lib/generators/jasmine/templates/INSTALL +9 -0
  94. data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
  95. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  96. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  97. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  98. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  99. data/lib/jasmine.rb +31 -6
  100. data/lib/jasmine/command_line_tool.rb +1 -0
  101. data/lib/jasmine/config.rb +16 -44
  102. data/lib/jasmine/generator.rb +9 -0
  103. data/lib/jasmine/selenium_driver.rb +18 -18
  104. data/lib/jasmine/server.rb +0 -24
  105. data/lib/jasmine/spec_builder.rb +4 -4
  106. data/lib/jasmine/tasks/jasmine.rake +2 -2
  107. data/lib/jasmine/version.rb +3 -0
  108. data/spec/config_spec.rb +174 -123
  109. data/spec/fixture/jasmine.erb.yml +4 -0
  110. data/spec/jasmine_pojs_spec.rb +51 -0
  111. data/spec/jasmine_rails2_spec.rb +93 -0
  112. data/spec/jasmine_rails3_spec.rb +71 -0
  113. data/spec/spec_helper.rb +8 -2
  114. metadata +215 -65
  115. data/spec/bug_fixes_spec.rb +0 -32
  116. data/spec/rails_generator_spec.rb +0 -31
@@ -0,0 +1,40 @@
1
+ describe("jasmine.util", function() {
2
+ describe("extend", function () {
3
+ it("should add properies to a destination object ", function() {
4
+ var destination = {baz: 'baz'};
5
+ jasmine.util.extend(destination, {
6
+ foo: 'foo', bar: 'bar'
7
+ });
8
+ expect(destination).toEqual({foo: 'foo', bar: 'bar', baz: 'baz'});
9
+ });
10
+
11
+ it("should replace properies that already exist on a destination object", function() {
12
+ var destination = {foo: 'foo'};
13
+ jasmine.util.extend(destination, {
14
+ foo: 'bar'
15
+ });
16
+ expect(destination).toEqual({foo: 'bar'});
17
+ jasmine.util.extend(destination, {
18
+ foo: null
19
+ });
20
+ expect(destination).toEqual({foo: null});
21
+ });
22
+ });
23
+
24
+ describe("isArray_", function() {
25
+ it("should return true if the argument is an array", function() {
26
+ expect(jasmine.isArray_([])).toBe(true);
27
+ expect(jasmine.isArray_(['a'])).toBe(true);
28
+ expect(jasmine.isArray_(new Array())).toBe(true);
29
+ });
30
+
31
+ it("should return false if the argument is not an array", function() {
32
+ expect(jasmine.isArray_(undefined)).toBe(false);
33
+ expect(jasmine.isArray_({})).toBe(false);
34
+ expect(jasmine.isArray_(function() {})).toBe(false);
35
+ expect(jasmine.isArray_('foo')).toBe(false);
36
+ expect(jasmine.isArray_(5)).toBe(false);
37
+ expect(jasmine.isArray_(null)).toBe(false);
38
+ });
39
+ });
40
+ });
@@ -0,0 +1,87 @@
1
+ describe('WaitsForBlock', function () {
2
+ var env, suite, timeout, spec, message, onComplete, fakeTimer;
3
+ beforeEach(function() {
4
+ env = new jasmine.Env();
5
+ env.updateInterval = 0;
6
+ suite = new jasmine.Suite(env, 'suite 1');
7
+ timeout = 1000;
8
+ spec = new jasmine.Spec(env, suite);
9
+ message = "some error message";
10
+ onComplete = jasmine.createSpy("onComplete");
11
+ });
12
+
13
+ it('onComplete should be called if the latchFunction returns true', function () {
14
+ var latchFunction = function() {
15
+ return true;
16
+ };
17
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
18
+ expect(onComplete).not.toHaveBeenCalled();
19
+ block.execute(onComplete);
20
+ expect(onComplete).toHaveBeenCalled();
21
+ });
22
+
23
+ it('latchFunction should run in same scope as spec', function () {
24
+ var result;
25
+ var latchFunction = function() {
26
+ result = this.scopedValue;
27
+ };
28
+ spec.scopedValue = 'foo';
29
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
30
+ block.execute(onComplete);
31
+ expect(result).toEqual('foo');
32
+ });
33
+
34
+ it('should fail spec and call onComplete if there is an error in the latchFunction', function() {
35
+ var latchFunction = jasmine.createSpy('latchFunction').andThrow('some error');
36
+ spyOn(spec, 'fail');
37
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
38
+ block.execute(onComplete);
39
+ expect(spec.fail).toHaveBeenCalledWith('some error');
40
+ expect(onComplete).toHaveBeenCalled();
41
+ });
42
+
43
+ describe("if latchFunction returns false", function() {
44
+ var latchFunction, fakeTimer;
45
+ beforeEach(function() {
46
+ latchFunction = jasmine.createSpy('latchFunction').andReturn(false);
47
+ fakeTimer = new jasmine.FakeTimer();
48
+ env.setTimeout = fakeTimer.setTimeout;
49
+ env.clearTimeout = fakeTimer.clearTimeout;
50
+ env.setInterval = fakeTimer.setInterval;
51
+ env.clearInterval = fakeTimer.clearInterval;
52
+ });
53
+
54
+ it('latchFunction should be retried after 10 ms', function () {
55
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
56
+ expect(latchFunction).not.toHaveBeenCalled();
57
+ block.execute(onComplete);
58
+ expect(latchFunction.callCount).toEqual(1);
59
+ fakeTimer.tick(5);
60
+ expect(latchFunction.callCount).toEqual(1);
61
+ fakeTimer.tick(5);
62
+ expect(latchFunction.callCount).toEqual(2);
63
+ });
64
+
65
+ it('onComplete should be called if latchFunction returns true before timeout', function () {
66
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
67
+ expect(onComplete).not.toHaveBeenCalled();
68
+ block.execute(onComplete);
69
+ expect(onComplete).not.toHaveBeenCalled();
70
+ latchFunction.andReturn(true);
71
+ fakeTimer.tick(100);
72
+ expect(onComplete).toHaveBeenCalled();
73
+ });
74
+
75
+ it('spec should fail with the passed message if the timeout is reached (and not call onComplete)', function () {
76
+ spyOn(spec, 'fail');
77
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
78
+ block.execute(onComplete);
79
+ expect(spec.fail).not.toHaveBeenCalled();
80
+ fakeTimer.tick(timeout);
81
+ expect(spec.fail).toHaveBeenCalled();
82
+ var failMessage = spec.fail.mostRecentCall.args[0].message;
83
+ expect(failMessage).toMatch(message);
84
+ expect(onComplete).toHaveBeenCalled();
85
+ });
86
+ });
87
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Blocks are functions with executable code that make up a spec.
3
+ *
4
+ * @constructor
5
+ * @param {jasmine.Env} env
6
+ * @param {Function} func
7
+ * @param {jasmine.Spec} spec
8
+ */
9
+ jasmine.Block = function(env, func, spec) {
10
+ this.env = env;
11
+ this.func = func;
12
+ this.spec = spec;
13
+ };
14
+
15
+ jasmine.Block.prototype.execute = function(onComplete) {
16
+ try {
17
+ this.func.apply(this.spec);
18
+ } catch (e) {
19
+ this.spec.fail(e);
20
+ }
21
+ onComplete();
22
+ };
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Environment for Jasmine
3
+ *
4
+ * @constructor
5
+ */
6
+ jasmine.Env = function() {
7
+ this.currentSpec = null;
8
+ this.currentSuite = null;
9
+ this.currentRunner_ = new jasmine.Runner(this);
10
+
11
+ this.reporter = new jasmine.MultiReporter();
12
+
13
+ this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
14
+ this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
15
+ this.lastUpdate = 0;
16
+ this.specFilter = function() {
17
+ return true;
18
+ };
19
+
20
+ this.nextSpecId_ = 0;
21
+ this.nextSuiteId_ = 0;
22
+ this.equalityTesters_ = [];
23
+
24
+ // wrap matchers
25
+ this.matchersClass = function() {
26
+ jasmine.Matchers.apply(this, arguments);
27
+ };
28
+ jasmine.util.inherit(this.matchersClass, jasmine.Matchers);
29
+
30
+ jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass);
31
+ };
32
+
33
+
34
+ jasmine.Env.prototype.setTimeout = jasmine.setTimeout;
35
+ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
36
+ jasmine.Env.prototype.setInterval = jasmine.setInterval;
37
+ jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
38
+
39
+ /**
40
+ * @returns an object containing jasmine version build info, if set.
41
+ */
42
+ jasmine.Env.prototype.version = function () {
43
+ if (jasmine.version_) {
44
+ return jasmine.version_;
45
+ } else {
46
+ throw new Error('Version not set');
47
+ }
48
+ };
49
+
50
+ /**
51
+ * @returns string containing jasmine version build info, if set.
52
+ */
53
+ jasmine.Env.prototype.versionString = function() {
54
+ if (jasmine.version_) {
55
+ var version = this.version();
56
+ return version.major + "." + version.minor + "." + version.build + " revision " + version.revision;
57
+ } else {
58
+ return "version unknown";
59
+ }
60
+ };
61
+
62
+ /**
63
+ * @returns a sequential integer starting at 0
64
+ */
65
+ jasmine.Env.prototype.nextSpecId = function () {
66
+ return this.nextSpecId_++;
67
+ };
68
+
69
+ /**
70
+ * @returns a sequential integer starting at 0
71
+ */
72
+ jasmine.Env.prototype.nextSuiteId = function () {
73
+ return this.nextSuiteId_++;
74
+ };
75
+
76
+ /**
77
+ * Register a reporter to receive status updates from Jasmine.
78
+ * @param {jasmine.Reporter} reporter An object which will receive status updates.
79
+ */
80
+ jasmine.Env.prototype.addReporter = function(reporter) {
81
+ this.reporter.addReporter(reporter);
82
+ };
83
+
84
+ jasmine.Env.prototype.execute = function() {
85
+ this.currentRunner_.execute();
86
+ };
87
+
88
+ jasmine.Env.prototype.describe = function(description, specDefinitions) {
89
+ var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite);
90
+
91
+ var parentSuite = this.currentSuite;
92
+ if (parentSuite) {
93
+ parentSuite.add(suite);
94
+ } else {
95
+ this.currentRunner_.add(suite);
96
+ }
97
+
98
+ this.currentSuite = suite;
99
+
100
+ var declarationError = null;
101
+ try {
102
+ specDefinitions.call(suite);
103
+ } catch(e) {
104
+ declarationError = e;
105
+ }
106
+
107
+ this.currentSuite = parentSuite;
108
+
109
+ if (declarationError) {
110
+ this.it("encountered a declaration exception", function() {
111
+ throw declarationError;
112
+ });
113
+ }
114
+
115
+ return suite;
116
+ };
117
+
118
+ jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
119
+ if (this.currentSuite) {
120
+ this.currentSuite.beforeEach(beforeEachFunction);
121
+ } else {
122
+ this.currentRunner_.beforeEach(beforeEachFunction);
123
+ }
124
+ };
125
+
126
+ jasmine.Env.prototype.currentRunner = function () {
127
+ return this.currentRunner_;
128
+ };
129
+
130
+ jasmine.Env.prototype.afterEach = function(afterEachFunction) {
131
+ if (this.currentSuite) {
132
+ this.currentSuite.afterEach(afterEachFunction);
133
+ } else {
134
+ this.currentRunner_.afterEach(afterEachFunction);
135
+ }
136
+
137
+ };
138
+
139
+ jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
140
+ return {
141
+ execute: function() {
142
+ }
143
+ };
144
+ };
145
+
146
+ jasmine.Env.prototype.it = function(description, func) {
147
+ var spec = new jasmine.Spec(this, this.currentSuite, description);
148
+ this.currentSuite.add(spec);
149
+ this.currentSpec = spec;
150
+
151
+ if (func) {
152
+ spec.runs(func);
153
+ }
154
+
155
+ return spec;
156
+ };
157
+
158
+ jasmine.Env.prototype.xit = function(desc, func) {
159
+ return {
160
+ id: this.nextSpecId(),
161
+ runs: function() {
162
+ }
163
+ };
164
+ };
165
+
166
+ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
167
+ if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
168
+ return true;
169
+ }
170
+
171
+ a.__Jasmine_been_here_before__ = b;
172
+ b.__Jasmine_been_here_before__ = a;
173
+
174
+ var hasKey = function(obj, keyName) {
175
+ return obj != null && obj[keyName] !== jasmine.undefined;
176
+ };
177
+
178
+ for (var property in b) {
179
+ if (!hasKey(a, property) && hasKey(b, property)) {
180
+ mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
181
+ }
182
+ }
183
+ for (property in a) {
184
+ if (!hasKey(b, property) && hasKey(a, property)) {
185
+ mismatchKeys.push("expected missing key '" + property + "', but present in actual.");
186
+ }
187
+ }
188
+ for (property in b) {
189
+ if (property == '__Jasmine_been_here_before__') continue;
190
+ if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) {
191
+ mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual.");
192
+ }
193
+ }
194
+
195
+ if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
196
+ mismatchValues.push("arrays were not the same length");
197
+ }
198
+
199
+ delete a.__Jasmine_been_here_before__;
200
+ delete b.__Jasmine_been_here_before__;
201
+ return (mismatchKeys.length == 0 && mismatchValues.length == 0);
202
+ };
203
+
204
+ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
205
+ mismatchKeys = mismatchKeys || [];
206
+ mismatchValues = mismatchValues || [];
207
+
208
+ for (var i = 0; i < this.equalityTesters_.length; i++) {
209
+ var equalityTester = this.equalityTesters_[i];
210
+ var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
211
+ if (result !== jasmine.undefined) return result;
212
+ }
213
+
214
+ if (a === b) return true;
215
+
216
+ if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
217
+ return (a == jasmine.undefined && b == jasmine.undefined);
218
+ }
219
+
220
+ if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
221
+ return a === b;
222
+ }
223
+
224
+ if (a instanceof Date && b instanceof Date) {
225
+ return a.getTime() == b.getTime();
226
+ }
227
+
228
+ if (a instanceof jasmine.Matchers.Any) {
229
+ return a.matches(b);
230
+ }
231
+
232
+ if (b instanceof jasmine.Matchers.Any) {
233
+ return b.matches(a);
234
+ }
235
+
236
+ if (jasmine.isString_(a) && jasmine.isString_(b)) {
237
+ return (a == b);
238
+ }
239
+
240
+ if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
241
+ return (a == b);
242
+ }
243
+
244
+ if (typeof a === "object" && typeof b === "object") {
245
+ return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
246
+ }
247
+
248
+ //Straight check
249
+ return (a === b);
250
+ };
251
+
252
+ jasmine.Env.prototype.contains_ = function(haystack, needle) {
253
+ if (jasmine.isArray_(haystack)) {
254
+ for (var i = 0; i < haystack.length; i++) {
255
+ if (this.equals_(haystack[i], needle)) return true;
256
+ }
257
+ return false;
258
+ }
259
+ return haystack.indexOf(needle) >= 0;
260
+ };
261
+
262
+ jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
263
+ this.equalityTesters_.push(equalityTester);
264
+ };
@@ -0,0 +1,102 @@
1
+ /** JavaScript API reporter.
2
+ *
3
+ * @constructor
4
+ */
5
+ jasmine.JsApiReporter = function() {
6
+ this.started = false;
7
+ this.finished = false;
8
+ this.suites_ = [];
9
+ this.results_ = {};
10
+ };
11
+
12
+ jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
13
+ this.started = true;
14
+ var suites = runner.topLevelSuites();
15
+ for (var i = 0; i < suites.length; i++) {
16
+ var suite = suites[i];
17
+ this.suites_.push(this.summarize_(suite));
18
+ }
19
+ };
20
+
21
+ jasmine.JsApiReporter.prototype.suites = function() {
22
+ return this.suites_;
23
+ };
24
+
25
+ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
26
+ var isSuite = suiteOrSpec instanceof jasmine.Suite;
27
+ var summary = {
28
+ id: suiteOrSpec.id,
29
+ name: suiteOrSpec.description,
30
+ type: isSuite ? 'suite' : 'spec',
31
+ children: []
32
+ };
33
+
34
+ if (isSuite) {
35
+ var children = suiteOrSpec.children();
36
+ for (var i = 0; i < children.length; i++) {
37
+ summary.children.push(this.summarize_(children[i]));
38
+ }
39
+ }
40
+ return summary;
41
+ };
42
+
43
+ jasmine.JsApiReporter.prototype.results = function() {
44
+ return this.results_;
45
+ };
46
+
47
+ jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) {
48
+ return this.results_[specId];
49
+ };
50
+
51
+ //noinspection JSUnusedLocalSymbols
52
+ jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) {
53
+ this.finished = true;
54
+ };
55
+
56
+ //noinspection JSUnusedLocalSymbols
57
+ jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) {
58
+ };
59
+
60
+ //noinspection JSUnusedLocalSymbols
61
+ jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) {
62
+ this.results_[spec.id] = {
63
+ messages: spec.results().getItems(),
64
+ result: spec.results().failedCount > 0 ? "failed" : "passed"
65
+ };
66
+ };
67
+
68
+ //noinspection JSUnusedLocalSymbols
69
+ jasmine.JsApiReporter.prototype.log = function(str) {
70
+ };
71
+
72
+ jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){
73
+ var results = {};
74
+ for (var i = 0; i < specIds.length; i++) {
75
+ var specId = specIds[i];
76
+ results[specId] = this.summarizeResult_(this.results_[specId]);
77
+ }
78
+ return results;
79
+ };
80
+
81
+ jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
82
+ var summaryMessages = [];
83
+ var messagesLength = result.messages.length;
84
+ for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) {
85
+ var resultMessage = result.messages[messageIndex];
86
+ summaryMessages.push({
87
+ text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined,
88
+ passed: resultMessage.passed ? resultMessage.passed() : true,
89
+ type: resultMessage.type,
90
+ message: resultMessage.message,
91
+ trace: {
92
+ stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
93
+ }
94
+ });
95
+ }
96
+
97
+ return {
98
+ result : result.result,
99
+ messages : summaryMessages
100
+ };
101
+ };
102
+