snapdragon 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 245a1080431376a79728953a841a85f5a2df4eae
4
- data.tar.gz: a71b35a34b7edb62a612ab8fe69a6cfb792ff485
3
+ metadata.gz: 12b80206b51f0e8cf95cc1ad2a15c9616a44b7fd
4
+ data.tar.gz: eadce0bb49b9cb9893dfd70ed39946074990425c
5
5
  SHA512:
6
- metadata.gz: 320be3c918fbbcd98da4958b7fa86fb4cbad056a0cfcdd970dbb23302278cc73687138e509056dcc1ad7d46824c88ebe8c7d7c3b032e488b6ff36f5b94ac60f7
7
- data.tar.gz: 4da5eaacb64b3adbfa400fc848110a3f5c92f27e5189fbabd4eea3fdd96e03f6c1745ec8e2ed9cbdb7fba6097a53e7e2fe4c5fd1f5b009993631b9d6538599dd
6
+ metadata.gz: dbdf8c80bf54b8bdd3c2a8c64f01c093d60f80245f787e0589384b6b364c8c47a7f25945c5168ff38274ef5ed67266e15ebbca6266c1ed2b8d8d5b24c7da9eec
7
+ data.tar.gz: df79660a917f07f1d91852847401cc607e1cd401ab995baa43705ad12afee74d301eee048db76437215b9bfb8b086b07cb7eb12389dc59c3295a041533e37ce7
@@ -0,0 +1,54 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
+ "http://www.w3.org/TR/html4/loose.dtd">
3
+ <html>
4
+ <head>
5
+ <title>Jasmine Spec Runner</title>
6
+
7
+ <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.1.0.rc1/jasmine_favicon.png">
8
+
9
+ <link rel="stylesheet" type="text/css" href="lib/jasmine-1.1.0.rc1/jasmine.css">
10
+ <script type="text/javascript" src="lib/jasmine-1.1.0.rc1/jasmine.js"></script>
11
+ <script type="text/javascript" src="lib/jasmine-1.1.0.rc1/jasmine-html.js"></script>
12
+
13
+ <!-- include spec files here... -->
14
+ <script type="text/javascript" src="spec/SpecHelper.js"></script>
15
+ <script type="text/javascript" src="spec/PlayerSpec.js"></script>
16
+
17
+ <!-- include source files here... -->
18
+ <script type="text/javascript" src="src/Player.js"></script>
19
+ <script type="text/javascript" src="src/Song.js"></script>
20
+
21
+ <script type="text/javascript">
22
+ (function() {
23
+ var jasmineEnv = jasmine.getEnv();
24
+ jasmineEnv.updateInterval = 1000;
25
+
26
+ var trivialReporter = new jasmine.TrivialReporter();
27
+
28
+ jasmineEnv.addReporter(trivialReporter);
29
+
30
+ jasmineEnv.specFilter = function(spec) {
31
+ return trivialReporter.specFilter(spec);
32
+ };
33
+
34
+ var currentWindowOnload = window.onload;
35
+
36
+ window.onload = function() {
37
+ if (currentWindowOnload) {
38
+ currentWindowOnload();
39
+ }
40
+ execJasmine();
41
+ };
42
+
43
+ function execJasmine() {
44
+ jasmineEnv.execute();
45
+ }
46
+
47
+ })();
48
+ </script>
49
+
50
+ </head>
51
+
52
+ <body>
53
+ </body>
54
+ </html>
@@ -1,5 +1,5 @@
1
1
  beforeEach(function() {
2
- addMatchers({
2
+ this.addMatchers({
3
3
  toBePlaying: function(expectedSong) {
4
4
  var player = this.actual;
5
5
  return player.currentlyPlayingSong === expectedSong &&
@@ -1,344 +1,681 @@
1
- /*
2
- Copyright (c) 2008-2013 Pivotal Labs
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining
5
- a copy of this software and associated documentation files (the
6
- "Software"), to deal in the Software without restriction, including
7
- without limitation the rights to use, copy, modify, merge, publish,
8
- distribute, sublicense, and/or sell copies of the Software, and to
9
- permit persons to whom the Software is furnished to do so, subject to
10
- the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- */
23
- jasmineRequire.html = function(j$) {
24
- j$.ResultsNode = jasmineRequire.ResultsNode();
25
- j$.HtmlReporter = jasmineRequire.HtmlReporter();
26
- j$.QueryString = jasmineRequire.QueryString();
27
- j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
1
+ jasmine.HtmlReporterHelpers = {};
2
+
3
+ jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
4
+ var el = document.createElement(type);
5
+
6
+ for (var i = 2; i < arguments.length; i++) {
7
+ var child = arguments[i];
8
+
9
+ if (typeof child === 'string') {
10
+ el.appendChild(document.createTextNode(child));
11
+ } else {
12
+ if (child) {
13
+ el.appendChild(child);
14
+ }
15
+ }
16
+ }
17
+
18
+ for (var attr in attrs) {
19
+ if (attr == "className") {
20
+ el[attr] = attrs[attr];
21
+ } else {
22
+ el.setAttribute(attr, attrs[attr]);
23
+ }
24
+ }
25
+
26
+ return el;
28
27
  };
29
- jasmineRequire.HtmlReporter = function() {
30
- function HtmlReporter(options) {
31
- var env = options.env || {},
32
- getContainer = options.getContainer,
33
- createElement = options.createElement,
34
- createTextNode = options.createTextNode,
35
- onRaiseExceptionsClick = options.onRaiseExceptionsClick,
36
- results = [],
37
- specsExecuted = 0,
38
- failureCount = 0,
39
- pendingSpecCount = 0,
40
- htmlReporterMain,
41
- symbols;
42
-
43
- this.initialize = function() {
44
- htmlReporterMain = createDom("div", {className: "html-reporter"},
45
- createDom("div", {className: "banner"},
46
- createDom("span", {className: "title"}, "Jasmine"),
47
- createDom("span", {className: "version"}, jasmine.version)
48
- ),
49
- createDom("ul", {className: "symbol-summary"}),
50
- createDom("div", {className: "alert"}),
51
- createDom("div", {className: "results"},
52
- createDom("div", {className: "failures"})
53
- )
54
- );
55
- getContainer().appendChild(htmlReporterMain);
56
28
 
57
- symbols = find(".symbol-summary");
58
- };
29
+ jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
30
+ var results = child.results();
31
+ var status = results.passed() ? 'passed' : 'failed';
32
+ if (results.skipped) {
33
+ status = 'skipped';
34
+ }
59
35
 
60
- var totalSpecsDefined;
61
- this.jasmineStarted = function(options) {
62
- totalSpecsDefined = options.totalSpecsDefined || 0;
63
- };
36
+ return status;
37
+ };
64
38
 
65
- var summary = createDom("div", {className: "summary"});
39
+ jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
40
+ var parentDiv = this.dom.summary;
41
+ var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
42
+ var parent = child[parentSuite];
66
43
 
67
- var topResults = new jasmine.ResultsNode({}, "", null),
68
- currentParent = topResults;
44
+ if (parent) {
45
+ if (typeof this.views.suites[parent.id] == 'undefined') {
46
+ this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
47
+ }
48
+ parentDiv = this.views.suites[parent.id].element;
49
+ }
69
50
 
70
- this.suiteStarted = function(result) {
71
- currentParent.addChild(result, "suite");
72
- currentParent = currentParent.last();
73
- };
51
+ parentDiv.appendChild(childElement);
52
+ };
74
53
 
75
- this.suiteDone = function(result) {
76
- if (currentParent == topResults) {
77
- return;
54
+
55
+ jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
56
+ for(var fn in jasmine.HtmlReporterHelpers) {
57
+ ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
58
+ }
59
+ };
60
+
61
+ jasmine.HtmlReporter = function(_doc) {
62
+ var self = this;
63
+ var doc = _doc || window.document;
64
+
65
+ var reporterView;
66
+
67
+ var dom = {};
68
+
69
+ // Jasmine Reporter Public Interface
70
+ self.logRunningSpecs = false;
71
+
72
+ self.reportRunnerStarting = function(runner) {
73
+ var specs = runner.specs() || [];
74
+
75
+ if (specs.length == 0) {
76
+ return;
77
+ }
78
+
79
+ createReporterDom(runner.env.versionString());
80
+ doc.body.appendChild(dom.reporter);
81
+ setExceptionHandling();
82
+
83
+ reporterView = new jasmine.HtmlReporter.ReporterView(dom);
84
+ reporterView.addSpecs(specs, self.specFilter);
85
+ };
86
+
87
+ self.reportRunnerResults = function(runner) {
88
+ reporterView && reporterView.complete();
89
+ };
90
+
91
+ self.reportSuiteResults = function(suite) {
92
+ reporterView.suiteComplete(suite);
93
+ };
94
+
95
+ self.reportSpecStarting = function(spec) {
96
+ if (self.logRunningSpecs) {
97
+ self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
98
+ }
99
+ };
100
+
101
+ self.reportSpecResults = function(spec) {
102
+ reporterView.specComplete(spec);
103
+ };
104
+
105
+ self.log = function() {
106
+ var console = jasmine.getGlobal().console;
107
+ if (console && console.log) {
108
+ if (console.log.apply) {
109
+ console.log.apply(console, arguments);
110
+ } else {
111
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
78
112
  }
113
+ }
114
+ };
79
115
 
80
- currentParent = currentParent.parent;
81
- };
116
+ self.specFilter = function(spec) {
117
+ if (!focusedSpecName()) {
118
+ return true;
119
+ }
82
120
 
83
- this.specStarted = function(result) {
84
- currentParent.addChild(result, "spec");
85
- };
121
+ return spec.getFullName().indexOf(focusedSpecName()) === 0;
122
+ };
123
+
124
+ return self;
86
125
 
87
- var failures = [];
88
- this.specDone = function(result) {
89
- if (result.status != "disabled") {
90
- specsExecuted++;
126
+ function focusedSpecName() {
127
+ var specName;
128
+
129
+ (function memoizeFocusedSpec() {
130
+ if (specName) {
131
+ return;
91
132
  }
92
133
 
93
- symbols.appendChild(createDom("li", {
94
- className: result.status,
95
- id: "spec_" + result.id,
96
- title: result.fullName}
97
- ));
98
-
99
- if (result.status == "failed") {
100
- failureCount++;
101
-
102
- var failure =
103
- createDom("div", {className: "spec-detail failed"},
104
- createDom("a", {className: "description", title: result.fullName, href: specHref(result)}, result.fullName),
105
- createDom("div", {className: "messages"})
106
- );
107
- var messages = failure.childNodes[1];
108
-
109
- for (var i = 0; i < result.failedExpectations.length; i++) {
110
- var expectation = result.failedExpectations[i];
111
- messages.appendChild(createDom("div", {className: "result-message"}, expectation.message));
112
- messages.appendChild(createDom("div", {className: "stack-trace"}, expectation.stack));
113
- }
114
-
115
- failures.push(failure);
134
+ var paramMap = [];
135
+ var params = jasmine.HtmlReporter.parameters(doc);
136
+
137
+ for (var i = 0; i < params.length; i++) {
138
+ var p = params[i].split('=');
139
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
116
140
  }
117
141
 
118
- if (result.status == "pending") {
119
- pendingSpecCount++;
142
+ specName = paramMap.spec;
143
+ })();
144
+
145
+ return specName;
146
+ }
147
+
148
+ function createReporterDom(version) {
149
+ dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
150
+ dom.banner = self.createDom('div', { className: 'banner' },
151
+ self.createDom('span', { className: 'title' }, "Jasmine "),
152
+ self.createDom('span', { className: 'version' }, version)),
153
+
154
+ dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
155
+ dom.alert = self.createDom('div', {className: 'alert'},
156
+ self.createDom('span', { className: 'exceptions' },
157
+ self.createDom('label', { className: 'label', 'for': 'no_try_catch' }, 'No try/catch'),
158
+ self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))),
159
+ dom.results = self.createDom('div', {className: 'results'},
160
+ dom.summary = self.createDom('div', { className: 'summary' }),
161
+ dom.details = self.createDom('div', { id: 'details' }))
162
+ );
163
+ }
164
+
165
+ function noTryCatch() {
166
+ return window.location.search.match(/catch=false/);
167
+ }
168
+
169
+ function searchWithCatch() {
170
+ var params = jasmine.HtmlReporter.parameters(window.document);
171
+ var removed = false;
172
+ var i = 0;
173
+
174
+ while (!removed && i < params.length) {
175
+ if (params[i].match(/catch=/)) {
176
+ params.splice(i, 1);
177
+ removed = true;
120
178
  }
179
+ i++;
180
+ }
181
+ if (jasmine.CATCH_EXCEPTIONS) {
182
+ params.push("catch=false");
183
+ }
184
+
185
+ return params.join("&");
186
+ }
187
+
188
+ function setExceptionHandling() {
189
+ var chxCatch = document.getElementById('no_try_catch');
190
+
191
+ if (noTryCatch()) {
192
+ chxCatch.setAttribute('checked', true);
193
+ jasmine.CATCH_EXCEPTIONS = false;
194
+ }
195
+ chxCatch.onclick = function() {
196
+ window.location.search = searchWithCatch();
121
197
  };
198
+ }
199
+ };
200
+ jasmine.HtmlReporter.parameters = function(doc) {
201
+ var paramStr = doc.location.search.substring(1);
202
+ var params = [];
122
203
 
123
- this.jasmineDone = function(options) {
124
- var banner = find(".banner");
125
- banner.appendChild(createDom("span", {className: "duration"}, "finished in " + options.executionTime / 1000 + "s"));
126
-
127
- var alert = find(".alert");
128
-
129
- alert.appendChild(createDom("span", { className: "exceptions" },
130
- createDom("label", { className: "label", 'for': "raise-exceptions" }, "raise exceptions"),
131
- createDom("input", {
132
- className: "raise",
133
- id: "raise-exceptions",
134
- type: "checkbox"
135
- })
136
- ));
137
- var checkbox = find("input");
138
-
139
- checkbox.checked = !env.catchingExceptions();
140
- checkbox.onclick = onRaiseExceptionsClick;
141
-
142
- if (specsExecuted < totalSpecsDefined) {
143
- var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
144
- alert.appendChild(
145
- createDom("span", {className: "bar skipped"},
146
- createDom("a", {href: "?", title: "Run all specs"}, skippedMessage)
147
- )
148
- );
149
- }
150
- var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount);
151
- if (pendingSpecCount) { statusBarMessage += ", " + pluralize("pending spec", pendingSpecCount); }
152
-
153
- var statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
154
- alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage));
155
-
156
- var results = find(".results");
157
- results.appendChild(summary);
158
-
159
- summaryList(topResults, summary);
160
-
161
- function summaryList(resultsTree, domParent) {
162
- var specListNode;
163
- for (var i = 0; i < resultsTree.children.length; i++) {
164
- var resultNode = resultsTree.children[i];
165
- if (resultNode.type == "suite") {
166
- var suiteListNode = createDom("ul", {className: "suite", id: "suite-" + resultNode.result.id},
167
- createDom("li", {className: "suite-detail"},
168
- createDom("a", {href: specHref(resultNode.result)}, resultNode.result.description)
169
- )
170
- );
171
-
172
- summaryList(resultNode, suiteListNode);
173
- domParent.appendChild(suiteListNode);
174
- }
175
- if (resultNode.type == "spec") {
176
- if (domParent.getAttribute("class") != "specs") {
177
- specListNode = createDom("ul", {className: "specs"});
178
- domParent.appendChild(specListNode);
179
- }
180
- specListNode.appendChild(
181
- createDom("li", {
182
- className: resultNode.result.status,
183
- id: "spec-" + resultNode.result.id
184
- },
185
- createDom("a", {href: specHref(resultNode.result)}, resultNode.result.description)
186
- )
187
- );
188
- }
189
- }
190
- }
204
+ if (paramStr.length > 0) {
205
+ params = paramStr.split('&');
206
+ }
207
+ return params;
208
+ }
209
+ jasmine.HtmlReporter.sectionLink = function(sectionName) {
210
+ var link = '?';
211
+ var params = [];
212
+
213
+ if (sectionName) {
214
+ params.push('spec=' + encodeURIComponent(sectionName));
215
+ }
216
+ if (!jasmine.CATCH_EXCEPTIONS) {
217
+ params.push("catch=false");
218
+ }
219
+ if (params.length > 0) {
220
+ link += params.join("&");
221
+ }
191
222
 
192
- if (failures.length) {
193
- alert.appendChild(
194
- createDom('span', {className: "menu bar spec-list"},
195
- createDom("span", {}, "Spec List | "),
196
- createDom('a', {className: "failures-menu", href: "#"}, "Failures")));
197
- alert.appendChild(
198
- createDom('span', {className: "menu bar failure-list"},
199
- createDom('a', {className: "spec-list-menu", href: "#"}, "Spec List"),
200
- createDom("span", {}, " | Failures ")));
201
-
202
- find(".failures-menu").onclick = function() {
203
- setMenuModeTo('failure-list');
204
- };
205
- find(".spec-list-menu").onclick = function() {
206
- setMenuModeTo('spec-list');
207
- };
208
-
209
- setMenuModeTo('failure-list');
210
-
211
- var failureNode = find(".failures");
212
- for (var i = 0; i < failures.length; i++) {
213
- failureNode.appendChild(failures[i]);
214
- }
215
- }
223
+ return link;
224
+ };
225
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);
226
+ jasmine.HtmlReporter.ReporterView = function(dom) {
227
+ this.startedAt = new Date();
228
+ this.runningSpecCount = 0;
229
+ this.completeSpecCount = 0;
230
+ this.passedCount = 0;
231
+ this.failedCount = 0;
232
+ this.skippedCount = 0;
233
+
234
+ this.createResultsMenu = function() {
235
+ this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
236
+ this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
237
+ ' | ',
238
+ this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
239
+
240
+ this.summaryMenuItem.onclick = function() {
241
+ dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
216
242
  };
217
243
 
218
- return this;
244
+ this.detailsMenuItem.onclick = function() {
245
+ showDetails();
246
+ };
247
+ };
248
+
249
+ this.addSpecs = function(specs, specFilter) {
250
+ this.totalSpecCount = specs.length;
251
+
252
+ this.views = {
253
+ specs: {},
254
+ suites: {}
255
+ };
219
256
 
220
- function find(selector) {
221
- return getContainer().querySelector(selector);
257
+ for (var i = 0; i < specs.length; i++) {
258
+ var spec = specs[i];
259
+ this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
260
+ if (specFilter(spec)) {
261
+ this.runningSpecCount++;
262
+ }
222
263
  }
264
+ };
223
265
 
224
- function createDom(type, attrs, childrenVarArgs) {
225
- var el = createElement(type);
266
+ this.specComplete = function(spec) {
267
+ this.completeSpecCount++;
226
268
 
227
- for (var i = 2; i < arguments.length; i++) {
228
- var child = arguments[i];
269
+ if (isUndefined(this.views.specs[spec.id])) {
270
+ this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
271
+ }
229
272
 
230
- if (typeof child === 'string') {
231
- el.appendChild(createTextNode(child));
232
- } else {
233
- if (child) {
234
- el.appendChild(child);
235
- }
236
- }
237
- }
273
+ var specView = this.views.specs[spec.id];
238
274
 
239
- for (var attr in attrs) {
240
- if (attr == "className") {
241
- el[attr] = attrs[attr];
242
- } else {
243
- el.setAttribute(attr, attrs[attr]);
244
- }
245
- }
275
+ switch (specView.status()) {
276
+ case 'passed':
277
+ this.passedCount++;
278
+ break;
279
+
280
+ case 'failed':
281
+ this.failedCount++;
282
+ break;
283
+
284
+ case 'skipped':
285
+ this.skippedCount++;
286
+ break;
287
+ }
288
+
289
+ specView.refresh();
290
+ this.refresh();
291
+ };
292
+
293
+ this.suiteComplete = function(suite) {
294
+ var suiteView = this.views.suites[suite.id];
295
+ if (isUndefined(suiteView)) {
296
+ return;
297
+ }
298
+ suiteView.refresh();
299
+ };
300
+
301
+ this.refresh = function() {
302
+
303
+ if (isUndefined(this.resultsMenu)) {
304
+ this.createResultsMenu();
305
+ }
306
+
307
+ // currently running UI
308
+ if (isUndefined(this.runningAlert)) {
309
+ this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" });
310
+ dom.alert.appendChild(this.runningAlert);
311
+ }
312
+ this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
313
+
314
+ // skipped specs UI
315
+ if (isUndefined(this.skippedAlert)) {
316
+ this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" });
317
+ }
318
+
319
+ this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
246
320
 
247
- return el;
321
+ if (this.skippedCount === 1 && isDefined(dom.alert)) {
322
+ dom.alert.appendChild(this.skippedAlert);
248
323
  }
249
324
 
250
- function pluralize(singular, count) {
251
- var word = (count == 1 ? singular : singular + "s");
325
+ // passing specs UI
326
+ if (isUndefined(this.passedAlert)) {
327
+ this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" });
328
+ }
329
+ this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
330
+
331
+ // failing specs UI
332
+ if (isUndefined(this.failedAlert)) {
333
+ this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
334
+ }
335
+ this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
252
336
 
253
- return "" + count + " " + word;
337
+ if (this.failedCount === 1 && isDefined(dom.alert)) {
338
+ dom.alert.appendChild(this.failedAlert);
339
+ dom.alert.appendChild(this.resultsMenu);
254
340
  }
255
341
 
256
- function specHref(result) {
257
- return "?spec=" + encodeURIComponent(result.fullName);
342
+ // summary info
343
+ this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
344
+ this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
345
+ };
346
+
347
+ this.complete = function() {
348
+ dom.alert.removeChild(this.runningAlert);
349
+
350
+ this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
351
+
352
+ if (this.failedCount === 0) {
353
+ dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
354
+ } else {
355
+ showDetails();
258
356
  }
259
357
 
260
- function setMenuModeTo(mode) {
261
- htmlReporterMain.setAttribute("class", "html-reporter " + mode);
358
+ dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
359
+ };
360
+
361
+ return this;
362
+
363
+ function showDetails() {
364
+ if (dom.reporter.className.search(/showDetails/) === -1) {
365
+ dom.reporter.className += " showDetails";
262
366
  }
263
367
  }
264
368
 
265
- return HtmlReporter;
266
- };
369
+ function isUndefined(obj) {
370
+ return typeof obj === 'undefined';
371
+ }
267
372
 
268
- jasmineRequire.HtmlSpecFilter = function() {
269
- function HtmlSpecFilter(options) {
270
- var filterPattern = new RegExp(options && options.filterString());
373
+ function isDefined(obj) {
374
+ return !isUndefined(obj);
375
+ }
271
376
 
272
- this.matches = function(specName) {
273
- return filterPattern.test(specName);
274
- };
377
+ function specPluralizedFor(count) {
378
+ var str = count + " spec";
379
+ if (count > 1) {
380
+ str += "s"
381
+ }
382
+ return str;
275
383
  }
276
384
 
277
- return HtmlSpecFilter;
278
385
  };
279
- jasmineRequire.ResultsNode = function() {
280
- function ResultsNode(result, type, parent) {
281
- this.result = result;
282
- this.type = type;
283
- this.parent = parent;
284
386
 
285
- this.children = [];
387
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
286
388
 
287
- this.addChild = function(result, type) {
288
- this.children.push(new ResultsNode(result, type, this));
289
- };
290
389
 
291
- this.last = function() {
292
- return this.children[this.children.length - 1];
293
- };
390
+ jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
391
+ this.spec = spec;
392
+ this.dom = dom;
393
+ this.views = views;
394
+
395
+ this.symbol = this.createDom('li', { className: 'pending' });
396
+ this.dom.symbolSummary.appendChild(this.symbol);
397
+
398
+ this.summary = this.createDom('div', { className: 'specSummary' },
399
+ this.createDom('a', {
400
+ className: 'description',
401
+ href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()),
402
+ title: this.spec.getFullName()
403
+ }, this.spec.description)
404
+ );
405
+
406
+ this.detail = this.createDom('div', { className: 'specDetail' },
407
+ this.createDom('a', {
408
+ className: 'description',
409
+ href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
410
+ title: this.spec.getFullName()
411
+ }, this.spec.getFullName())
412
+ );
413
+ };
414
+
415
+ jasmine.HtmlReporter.SpecView.prototype.status = function() {
416
+ return this.getSpecStatus(this.spec);
417
+ };
418
+
419
+ jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
420
+ this.symbol.className = this.status();
421
+
422
+ switch (this.status()) {
423
+ case 'skipped':
424
+ break;
425
+
426
+ case 'passed':
427
+ this.appendSummaryToSuiteDiv();
428
+ break;
429
+
430
+ case 'failed':
431
+ this.appendSummaryToSuiteDiv();
432
+ this.appendFailureDetail();
433
+ break;
294
434
  }
435
+ };
295
436
 
296
- return ResultsNode;
437
+ jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
438
+ this.summary.className += ' ' + this.status();
439
+ this.appendToSummary(this.spec, this.summary);
297
440
  };
298
- jasmineRequire.QueryString = function() {
299
- function QueryString(options) {
300
441
 
301
- this.setParam = function(key, value) {
302
- var paramMap = queryStringToParamMap();
303
- paramMap[key] = value;
304
- options.getWindowLocation().search = toQueryString(paramMap);
305
- };
442
+ jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
443
+ this.detail.className += ' ' + this.status();
306
444
 
307
- this.getParam = function(key) {
308
- return queryStringToParamMap()[key];
309
- };
445
+ var resultItems = this.spec.results().getItems();
446
+ var messagesDiv = this.createDom('div', { className: 'messages' });
447
+
448
+ for (var i = 0; i < resultItems.length; i++) {
449
+ var result = resultItems[i];
310
450
 
311
- return this;
451
+ if (result.type == 'log') {
452
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
453
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
454
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
312
455
 
313
- function toQueryString(paramMap) {
314
- var qStrPairs = [];
315
- for (var prop in paramMap) {
316
- qStrPairs.push(encodeURIComponent(prop) + "=" + encodeURIComponent(paramMap[prop]));
456
+ if (result.trace.stack) {
457
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
317
458
  }
318
- return "?" + qStrPairs.join('&');
319
- }
320
-
321
- function queryStringToParamMap() {
322
- var paramStr = options.getWindowLocation().search.substring(1),
323
- params = [],
324
- paramMap = {};
325
-
326
- if (paramStr.length > 0) {
327
- params = paramStr.split('&');
328
- for (var i = 0; i < params.length; i++) {
329
- var p = params[i].split('=');
330
- var value = decodeURIComponent(p[1]);
331
- if (value === "true" || value === "false") {
332
- value = JSON.parse(value);
333
- }
334
- paramMap[decodeURIComponent(p[0])] = value;
335
- }
459
+ }
460
+ }
461
+
462
+ if (messagesDiv.childNodes.length > 0) {
463
+ this.detail.appendChild(messagesDiv);
464
+ this.dom.details.appendChild(this.detail);
465
+ }
466
+ };
467
+
468
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
469
+ this.suite = suite;
470
+ this.dom = dom;
471
+ this.views = views;
472
+
473
+ this.element = this.createDom('div', { className: 'suite' },
474
+ this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description)
475
+ );
476
+
477
+ this.appendToSummary(this.suite, this.element);
478
+ };
479
+
480
+ jasmine.HtmlReporter.SuiteView.prototype.status = function() {
481
+ return this.getSpecStatus(this.suite);
482
+ };
483
+
484
+ jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
485
+ this.element.className += " " + this.status();
486
+ };
487
+
488
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
489
+
490
+ /* @deprecated Use jasmine.HtmlReporter instead
491
+ */
492
+ jasmine.TrivialReporter = function(doc) {
493
+ this.document = doc || document;
494
+ this.suiteDivs = {};
495
+ this.logRunningSpecs = false;
496
+ };
497
+
498
+ jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
499
+ var el = document.createElement(type);
500
+
501
+ for (var i = 2; i < arguments.length; i++) {
502
+ var child = arguments[i];
503
+
504
+ if (typeof child === 'string') {
505
+ el.appendChild(document.createTextNode(child));
506
+ } else {
507
+ if (child) { el.appendChild(child); }
508
+ }
509
+ }
510
+
511
+ for (var attr in attrs) {
512
+ if (attr == "className") {
513
+ el[attr] = attrs[attr];
514
+ } else {
515
+ el.setAttribute(attr, attrs[attr]);
516
+ }
517
+ }
518
+
519
+ return el;
520
+ };
521
+
522
+ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
523
+ var showPassed, showSkipped;
524
+
525
+ this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
526
+ this.createDom('div', { className: 'banner' },
527
+ this.createDom('div', { className: 'logo' },
528
+ this.createDom('span', { className: 'title' }, "Jasmine"),
529
+ this.createDom('span', { className: 'version' }, runner.env.versionString())),
530
+ this.createDom('div', { className: 'options' },
531
+ "Show ",
532
+ showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
533
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
534
+ showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
535
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
536
+ )
537
+ ),
538
+
539
+ this.runnerDiv = this.createDom('div', { className: 'runner running' },
540
+ this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
541
+ this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
542
+ this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
543
+ );
544
+
545
+ this.document.body.appendChild(this.outerDiv);
546
+
547
+ var suites = runner.suites();
548
+ for (var i = 0; i < suites.length; i++) {
549
+ var suite = suites[i];
550
+ var suiteDiv = this.createDom('div', { className: 'suite' },
551
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
552
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
553
+ this.suiteDivs[suite.id] = suiteDiv;
554
+ var parentDiv = this.outerDiv;
555
+ if (suite.parentSuite) {
556
+ parentDiv = this.suiteDivs[suite.parentSuite.id];
557
+ }
558
+ parentDiv.appendChild(suiteDiv);
559
+ }
560
+
561
+ this.startedAt = new Date();
562
+
563
+ var self = this;
564
+ showPassed.onclick = function(evt) {
565
+ if (showPassed.checked) {
566
+ self.outerDiv.className += ' show-passed';
567
+ } else {
568
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
569
+ }
570
+ };
571
+
572
+ showSkipped.onclick = function(evt) {
573
+ if (showSkipped.checked) {
574
+ self.outerDiv.className += ' show-skipped';
575
+ } else {
576
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
577
+ }
578
+ };
579
+ };
580
+
581
+ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
582
+ var results = runner.results();
583
+ var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
584
+ this.runnerDiv.setAttribute("class", className);
585
+ //do it twice for IE
586
+ this.runnerDiv.setAttribute("className", className);
587
+ var specs = runner.specs();
588
+ var specCount = 0;
589
+ for (var i = 0; i < specs.length; i++) {
590
+ if (this.specFilter(specs[i])) {
591
+ specCount++;
592
+ }
593
+ }
594
+ var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
595
+ message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
596
+ this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
597
+
598
+ this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
599
+ };
600
+
601
+ jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
602
+ var results = suite.results();
603
+ var status = results.passed() ? 'passed' : 'failed';
604
+ if (results.totalCount === 0) { // todo: change this to check results.skipped
605
+ status = 'skipped';
606
+ }
607
+ this.suiteDivs[suite.id].className += " " + status;
608
+ };
609
+
610
+ jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
611
+ if (this.logRunningSpecs) {
612
+ this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
613
+ }
614
+ };
615
+
616
+ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
617
+ var results = spec.results();
618
+ var status = results.passed() ? 'passed' : 'failed';
619
+ if (results.skipped) {
620
+ status = 'skipped';
621
+ }
622
+ var specDiv = this.createDom('div', { className: 'spec ' + status },
623
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
624
+ this.createDom('a', {
625
+ className: 'description',
626
+ href: '?spec=' + encodeURIComponent(spec.getFullName()),
627
+ title: spec.getFullName()
628
+ }, spec.description));
629
+
630
+
631
+ var resultItems = results.getItems();
632
+ var messagesDiv = this.createDom('div', { className: 'messages' });
633
+ for (var i = 0; i < resultItems.length; i++) {
634
+ var result = resultItems[i];
635
+
636
+ if (result.type == 'log') {
637
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
638
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
639
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
640
+
641
+ if (result.trace.stack) {
642
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
336
643
  }
644
+ }
645
+ }
646
+
647
+ if (messagesDiv.childNodes.length > 0) {
648
+ specDiv.appendChild(messagesDiv);
649
+ }
337
650
 
338
- return paramMap;
651
+ this.suiteDivs[spec.suite.id].appendChild(specDiv);
652
+ };
653
+
654
+ jasmine.TrivialReporter.prototype.log = function() {
655
+ var console = jasmine.getGlobal().console;
656
+ if (console && console.log) {
657
+ if (console.log.apply) {
658
+ console.log.apply(console, arguments);
659
+ } else {
660
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
339
661
  }
662
+ }
663
+ };
664
+
665
+ jasmine.TrivialReporter.prototype.getLocation = function() {
666
+ return this.document.location;
667
+ };
340
668
 
669
+ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
670
+ var paramMap = {};
671
+ var params = this.getLocation().search.substring(1).split('&');
672
+ for (var i = 0; i < params.length; i++) {
673
+ var p = params[i].split('=');
674
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
341
675
  }
342
676
 
343
- return QueryString;
344
- };
677
+ if (!paramMap.spec) {
678
+ return true;
679
+ }
680
+ return spec.getFullName().indexOf(paramMap.spec) === 0;
681
+ };