rack-noncache 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.pryrc +6 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +15 -0
  7. data/README.md +36 -52
  8. data/Rakefile +16 -1
  9. data/features/cache_control.feature +22 -0
  10. data/features/step_definitions/steps.rb +46 -0
  11. data/features/support/continous_integration.rb +47 -0
  12. data/features/support/coverage.rb +18 -0
  13. data/features/support/env.rb +9 -0
  14. data/features/support/helpers.rb +13 -0
  15. data/features/support/web_app/application.rb +70 -0
  16. data/features/support/web_app/config_blacklist.ru +13 -0
  17. data/features/support/web_app/config_whitelist.ru +13 -0
  18. data/features/support/web_app/public/app/collections/todos.js +17 -0
  19. data/features/support/web_app/public/app/config.js +18 -0
  20. data/features/support/web_app/public/app/main.js +21 -0
  21. data/features/support/web_app/public/app/models/todo.js +33 -0
  22. data/features/support/web_app/public/app/templates/todo-add.html +3 -0
  23. data/features/support/web_app/public/app/templates/todo-editor.html +1 -0
  24. data/features/support/web_app/public/app/templates/todo-item.html +2 -0
  25. data/features/support/web_app/public/app/templates/todo-list-empty.html +1 -0
  26. data/features/support/web_app/public/app/templates/todo-stats.html +4 -0
  27. data/features/support/web_app/public/app/views/stats.js +26 -0
  28. data/features/support/web_app/public/app/views/todo.js +55 -0
  29. data/features/support/web_app/public/app/views/todoadd.js +48 -0
  30. data/features/support/web_app/public/app/views/todoedit.js +70 -0
  31. data/features/support/web_app/public/app/views/todolist.js +69 -0
  32. data/features/support/web_app/public/assets/css/bootstrap.css +3990 -0
  33. data/features/support/web_app/public/assets/css/style.css +82 -0
  34. data/features/support/web_app/public/assets/js/libs/backbone.js +1428 -0
  35. data/features/support/web_app/public/assets/js/libs/jquery-1.7.2.js +9404 -0
  36. data/features/support/web_app/public/assets/js/libs/require.js +2053 -0
  37. data/features/support/web_app/public/assets/js/libs/underscore.js +1008 -0
  38. data/features/support/web_app/public/assets/js/plugins/text.js +288 -0
  39. data/features/support/web_app/public/test/SpecRunner.html +42 -0
  40. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/MIT.LICENSE +20 -0
  41. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine-html.js +616 -0
  42. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine.css +81 -0
  43. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine.js +2530 -0
  44. data/features/support/web_app/public/test/lib/jasmine-jquery.js +306 -0
  45. data/features/support/web_app/public/test/spec/models/todo.coffee +37 -0
  46. data/features/support/web_app/public/test/spec/models/todo.js +48 -0
  47. data/features/support/web_app/public/test/spec/spec_helper.coffee +20 -0
  48. data/features/support/web_app/public/test/spec/spec_helper.js +17 -0
  49. data/features/support/web_app/public/test/spec/views/stats.coffee +9 -0
  50. data/features/support/web_app/public/test/spec/views/stats.js +13 -0
  51. data/features/support/web_app/public/test/spec/views/todo.coffee +22 -0
  52. data/features/support/web_app/public/test/spec/views/todo.js +26 -0
  53. data/features/support/web_app/public/test/spec/views/todoadd.coffee +22 -0
  54. data/features/support/web_app/public/test/spec/views/todoadd.js +29 -0
  55. data/features/support/web_app/public/test/spec/views/todoedit.coffee +59 -0
  56. data/features/support/web_app/public/test/spec/views/todoedit.js +72 -0
  57. data/features/support/web_app/public/test/spec/views/todolist.coffee +28 -0
  58. data/features/support/web_app/public/test/spec/views/todolist.js +39 -0
  59. data/features/support/web_app/views/details.erb +14 -0
  60. data/features/support/web_app/views/index.erb +43 -0
  61. data/lib/rack/noncache.rb +5 -7
  62. data/lib/rack/noncache/engine.rb +10 -26
  63. data/lib/rack/noncache/filters.rb +75 -0
  64. data/lib/rack/noncache/version.rb +1 -1
  65. data/rack-noncache.gemspec +32 -10
  66. metadata +382 -7
@@ -0,0 +1,288 @@
1
+ /**
2
+ * @license RequireJS text 1.0.7 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
3
+ * Available via the MIT or new BSD license.
4
+ * see: http://github.com/jrburke/requirejs for details
5
+ */
6
+ /*jslint regexp: false, nomen: false, plusplus: false, strict: false */
7
+ /*global require: false, XMLHttpRequest: false, ActiveXObject: false,
8
+ define: false, window: false, process: false, Packages: false,
9
+ java: false, location: false */
10
+
11
+ (function () {
12
+ var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
13
+ xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
14
+ bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
15
+ hasLocation = typeof location !== 'undefined' && location.href,
16
+ defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''),
17
+ defaultHostName = hasLocation && location.hostname,
18
+ defaultPort = hasLocation && (location.port || undefined),
19
+ buildMap = [];
20
+
21
+ define(function () {
22
+ var text, get, fs;
23
+
24
+ if (typeof window !== "undefined" && window.navigator && window.document) {
25
+ get = function (url, callback) {
26
+ var xhr = text.createXhr();
27
+ xhr.open('GET', url, true);
28
+ xhr.onreadystatechange = function (evt) {
29
+ //Do not explicitly handle errors, those should be
30
+ //visible via console output in the browser.
31
+ if (xhr.readyState === 4) {
32
+ callback(xhr.responseText);
33
+ }
34
+ };
35
+ xhr.send(null);
36
+ };
37
+ } else if (typeof process !== "undefined" &&
38
+ process.versions &&
39
+ !!process.versions.node) {
40
+ //Using special require.nodeRequire, something added by r.js.
41
+ fs = require.nodeRequire('fs');
42
+
43
+ get = function (url, callback) {
44
+ var file = fs.readFileSync(url, 'utf8');
45
+ //Remove BOM (Byte Mark Order) from utf8 files if it is there.
46
+ if (file.indexOf('\uFEFF') === 0) {
47
+ file = file.substring(1);
48
+ }
49
+ callback(file);
50
+ };
51
+ } else if (typeof Packages !== 'undefined') {
52
+ //Why Java, why is this so awkward?
53
+ get = function (url, callback) {
54
+ var encoding = "utf-8",
55
+ file = new java.io.File(url),
56
+ lineSeparator = java.lang.System.getProperty("line.separator"),
57
+ input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
58
+ stringBuffer, line,
59
+ content = '';
60
+ try {
61
+ stringBuffer = new java.lang.StringBuffer();
62
+ line = input.readLine();
63
+
64
+ // Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
65
+ // http://www.unicode.org/faq/utf_bom.html
66
+
67
+ // Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
68
+ // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
69
+ if (line && line.length() && line.charAt(0) === 0xfeff) {
70
+ // Eat the BOM, since we've already found the encoding on this file,
71
+ // and we plan to concatenating this buffer with others; the BOM should
72
+ // only appear at the top of a file.
73
+ line = line.substring(1);
74
+ }
75
+
76
+ stringBuffer.append(line);
77
+
78
+ while ((line = input.readLine()) !== null) {
79
+ stringBuffer.append(lineSeparator);
80
+ stringBuffer.append(line);
81
+ }
82
+ //Make sure we return a JavaScript string and not a Java string.
83
+ content = String(stringBuffer.toString()); //String
84
+ } finally {
85
+ input.close();
86
+ }
87
+ callback(content);
88
+ };
89
+ }
90
+
91
+ text = {
92
+ version: '1.0.7',
93
+
94
+ strip: function (content) {
95
+ //Strips <?xml ...?> declarations so that external SVG and XML
96
+ //documents can be added to a document without worry. Also, if the string
97
+ //is an HTML document, only the part inside the body tag is returned.
98
+ if (content) {
99
+ content = content.replace(xmlRegExp, "");
100
+ var matches = content.match(bodyRegExp);
101
+ if (matches) {
102
+ content = matches[1];
103
+ }
104
+ } else {
105
+ content = "";
106
+ }
107
+ return content;
108
+ },
109
+
110
+ jsEscape: function (content) {
111
+ return content.replace(/(['\\])/g, '\\$1')
112
+ .replace(/[\f]/g, "\\f")
113
+ .replace(/[\b]/g, "\\b")
114
+ .replace(/[\n]/g, "\\n")
115
+ .replace(/[\t]/g, "\\t")
116
+ .replace(/[\r]/g, "\\r");
117
+ },
118
+
119
+ createXhr: function () {
120
+ //Would love to dump the ActiveX crap in here. Need IE 6 to die first.
121
+ var xhr, i, progId;
122
+ if (typeof XMLHttpRequest !== "undefined") {
123
+ return new XMLHttpRequest();
124
+ } else {
125
+ for (i = 0; i < 3; i++) {
126
+ progId = progIds[i];
127
+ try {
128
+ xhr = new ActiveXObject(progId);
129
+ } catch (e) {}
130
+
131
+ if (xhr) {
132
+ progIds = [progId]; // so faster next time
133
+ break;
134
+ }
135
+ }
136
+ }
137
+
138
+ if (!xhr) {
139
+ throw new Error("createXhr(): XMLHttpRequest not available");
140
+ }
141
+
142
+ return xhr;
143
+ },
144
+
145
+ get: get,
146
+
147
+ /**
148
+ * Parses a resource name into its component parts. Resource names
149
+ * look like: module/name.ext!strip, where the !strip part is
150
+ * optional.
151
+ * @param {String} name the resource name
152
+ * @returns {Object} with properties "moduleName", "ext" and "strip"
153
+ * where strip is a boolean.
154
+ */
155
+ parseName: function (name) {
156
+ var strip = false, index = name.indexOf("."),
157
+ modName = name.substring(0, index),
158
+ ext = name.substring(index + 1, name.length);
159
+
160
+ index = ext.indexOf("!");
161
+ if (index !== -1) {
162
+ //Pull off the strip arg.
163
+ strip = ext.substring(index + 1, ext.length);
164
+ strip = strip === "strip";
165
+ ext = ext.substring(0, index);
166
+ }
167
+
168
+ return {
169
+ moduleName: modName,
170
+ ext: ext,
171
+ strip: strip
172
+ };
173
+ },
174
+
175
+ xdRegExp: /^((\w+)\:)?\/\/([^\/\\]+)/,
176
+
177
+ /**
178
+ * Is an URL on another domain. Only works for browser use, returns
179
+ * false in non-browser environments. Only used to know if an
180
+ * optimized .js version of a text resource should be loaded
181
+ * instead.
182
+ * @param {String} url
183
+ * @returns Boolean
184
+ */
185
+ useXhr: function (url, protocol, hostname, port) {
186
+ var match = text.xdRegExp.exec(url),
187
+ uProtocol, uHostName, uPort;
188
+ if (!match) {
189
+ return true;
190
+ }
191
+ uProtocol = match[2];
192
+ uHostName = match[3];
193
+
194
+ uHostName = uHostName.split(':');
195
+ uPort = uHostName[1];
196
+ uHostName = uHostName[0];
197
+
198
+ return (!uProtocol || uProtocol === protocol) &&
199
+ (!uHostName || uHostName === hostname) &&
200
+ ((!uPort && !uHostName) || uPort === port);
201
+ },
202
+
203
+ finishLoad: function (name, strip, content, onLoad, config) {
204
+ content = strip ? text.strip(content) : content;
205
+ if (config.isBuild) {
206
+ buildMap[name] = content;
207
+ }
208
+ onLoad(content);
209
+ },
210
+
211
+ load: function (name, req, onLoad, config) {
212
+ //Name has format: some.module.filext!strip
213
+ //The strip part is optional.
214
+ //if strip is present, then that means only get the string contents
215
+ //inside a body tag in an HTML string. For XML/SVG content it means
216
+ //removing the <?xml ...?> declarations so the content can be inserted
217
+ //into the current doc without problems.
218
+
219
+ // Do not bother with the work if a build and text will
220
+ // not be inlined.
221
+ if (config.isBuild && !config.inlineText) {
222
+ onLoad();
223
+ return;
224
+ }
225
+
226
+ var parsed = text.parseName(name),
227
+ nonStripName = parsed.moduleName + '.' + parsed.ext,
228
+ url = req.toUrl(nonStripName),
229
+ useXhr = (config && config.text && config.text.useXhr) ||
230
+ text.useXhr;
231
+
232
+ //Load the text. Use XHR if possible and in a browser.
233
+ if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) {
234
+ text.get(url, function (content) {
235
+ text.finishLoad(name, parsed.strip, content, onLoad, config);
236
+ });
237
+ } else {
238
+ //Need to fetch the resource across domains. Assume
239
+ //the resource has been optimized into a JS module. Fetch
240
+ //by the module name + extension, but do not include the
241
+ //!strip part to avoid file system issues.
242
+ req([nonStripName], function (content) {
243
+ text.finishLoad(parsed.moduleName + '.' + parsed.ext,
244
+ parsed.strip, content, onLoad, config);
245
+ });
246
+ }
247
+ },
248
+
249
+ write: function (pluginName, moduleName, write, config) {
250
+ if (moduleName in buildMap) {
251
+ var content = text.jsEscape(buildMap[moduleName]);
252
+ write.asModule(pluginName + "!" + moduleName,
253
+ "define(function () { return '" +
254
+ content +
255
+ "';});\n");
256
+ }
257
+ },
258
+
259
+ writeFile: function (pluginName, moduleName, req, write, config) {
260
+ var parsed = text.parseName(moduleName),
261
+ nonStripName = parsed.moduleName + '.' + parsed.ext,
262
+ //Use a '.js' file name so that it indicates it is a
263
+ //script that can be loaded across domains.
264
+ fileName = req.toUrl(parsed.moduleName + '.' +
265
+ parsed.ext) + '.js';
266
+
267
+ //Leverage own load() method to load plugin value, but only
268
+ //write out values that do not have the strip argument,
269
+ //to avoid any potential issues with ! in file names.
270
+ text.load(nonStripName, req, function (value) {
271
+ //Use own write() method to construct full module value.
272
+ //But need to create shell that translates writeFile's
273
+ //write() to the right interface.
274
+ var textWrite = function (contents) {
275
+ return write(fileName, contents);
276
+ };
277
+ textWrite.asModule = function (moduleName, contents) {
278
+ return write.asModule(moduleName, fileName, contents);
279
+ };
280
+
281
+ text.write(pluginName, nonStripName, textWrite, config);
282
+ }, config);
283
+ }
284
+ };
285
+
286
+ return text;
287
+ });
288
+ }());
@@ -0,0 +1,42 @@
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.2.0.rc3/jasmine_favicon.png">
8
+ <link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0.rc3/jasmine.css">
9
+
10
+ <script src="lib/jasmine-1.2.0.rc3/jasmine.js"></script>
11
+ <script src="lib/jasmine-1.2.0.rc3/jasmine-html.js"></script>
12
+ <script src="lib/jasmine-jquery.js"></script>
13
+
14
+ <script data-main="../app/config" src="../assets/js/libs/require.js"></script>
15
+ <script>
16
+ require.config({
17
+ baseUrl: "../app/",
18
+ paths: {
19
+ spec : "../test/spec/"
20
+ }
21
+ });
22
+
23
+ require([
24
+
25
+ "spec/spec_helper",
26
+ "spec/models/todo",
27
+ "spec/views/stats",
28
+ "spec/views/todolist",
29
+ "spec/views/todo",
30
+ "spec/views/todoedit",
31
+ "spec/views/todoadd"
32
+
33
+ ], function() {
34
+ jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
35
+ jasmine.getEnv().execute();
36
+ });
37
+
38
+ </script>
39
+ </head>
40
+ <body>
41
+ </body>
42
+ </html>
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2011 Pivotal Labs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,616 @@
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;
27
+ };
28
+
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
+ }
35
+
36
+ return status;
37
+ };
38
+
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];
43
+
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
+ }
50
+
51
+ parentDiv.appendChild(childElement);
52
+ };
53
+
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
+
82
+ reporterView = new jasmine.HtmlReporter.ReporterView(dom);
83
+ reporterView.addSpecs(specs, self.specFilter);
84
+ };
85
+
86
+ self.reportRunnerResults = function(runner) {
87
+ reporterView && reporterView.complete();
88
+ };
89
+
90
+ self.reportSuiteResults = function(suite) {
91
+ reporterView.suiteComplete(suite);
92
+ };
93
+
94
+ self.reportSpecStarting = function(spec) {
95
+ if (self.logRunningSpecs) {
96
+ self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
97
+ }
98
+ };
99
+
100
+ self.reportSpecResults = function(spec) {
101
+ reporterView.specComplete(spec);
102
+ };
103
+
104
+ self.log = function() {
105
+ var console = jasmine.getGlobal().console;
106
+ if (console && console.log) {
107
+ if (console.log.apply) {
108
+ console.log.apply(console, arguments);
109
+ } else {
110
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
111
+ }
112
+ }
113
+ };
114
+
115
+ self.specFilter = function(spec) {
116
+ if (!focusedSpecName()) {
117
+ return true;
118
+ }
119
+
120
+ return spec.getFullName().indexOf(focusedSpecName()) === 0;
121
+ };
122
+
123
+ return self;
124
+
125
+ function focusedSpecName() {
126
+ var specName;
127
+
128
+ (function memoizeFocusedSpec() {
129
+ if (specName) {
130
+ return;
131
+ }
132
+
133
+ var paramMap = [];
134
+ var params = doc.location.search.substring(1).split('&');
135
+
136
+ for (var i = 0; i < params.length; i++) {
137
+ var p = params[i].split('=');
138
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
139
+ }
140
+
141
+ specName = paramMap.spec;
142
+ })();
143
+
144
+ return specName;
145
+ }
146
+
147
+ function createReporterDom(version) {
148
+ dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
149
+ dom.banner = self.createDom('div', { className: 'banner' },
150
+ self.createDom('span', { className: 'title' }, "Jasmine "),
151
+ self.createDom('span', { className: 'version' }, version)),
152
+
153
+ dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
154
+ dom.alert = self.createDom('div', {className: 'alert'}),
155
+ dom.results = self.createDom('div', {className: 'results'},
156
+ dom.summary = self.createDom('div', { className: 'summary' }),
157
+ dom.details = self.createDom('div', { id: 'details' }))
158
+ );
159
+ }
160
+ };
161
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporter.ReporterView = function(dom) {
162
+ this.startedAt = new Date();
163
+ this.runningSpecCount = 0;
164
+ this.completeSpecCount = 0;
165
+ this.passedCount = 0;
166
+ this.failedCount = 0;
167
+ this.skippedCount = 0;
168
+
169
+ this.createResultsMenu = function() {
170
+ this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
171
+ this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
172
+ ' | ',
173
+ this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
174
+
175
+ this.summaryMenuItem.onclick = function() {
176
+ dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
177
+ };
178
+
179
+ this.detailsMenuItem.onclick = function() {
180
+ showDetails();
181
+ };
182
+ };
183
+
184
+ this.addSpecs = function(specs, specFilter) {
185
+ this.totalSpecCount = specs.length;
186
+
187
+ this.views = {
188
+ specs: {},
189
+ suites: {}
190
+ };
191
+
192
+ for (var i = 0; i < specs.length; i++) {
193
+ var spec = specs[i];
194
+ this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
195
+ if (specFilter(spec)) {
196
+ this.runningSpecCount++;
197
+ }
198
+ }
199
+ };
200
+
201
+ this.specComplete = function(spec) {
202
+ this.completeSpecCount++;
203
+
204
+ if (isUndefined(this.views.specs[spec.id])) {
205
+ this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
206
+ }
207
+
208
+ var specView = this.views.specs[spec.id];
209
+
210
+ switch (specView.status()) {
211
+ case 'passed':
212
+ this.passedCount++;
213
+ break;
214
+
215
+ case 'failed':
216
+ this.failedCount++;
217
+ break;
218
+
219
+ case 'skipped':
220
+ this.skippedCount++;
221
+ break;
222
+ }
223
+
224
+ specView.refresh();
225
+ this.refresh();
226
+ };
227
+
228
+ this.suiteComplete = function(suite) {
229
+ var suiteView = this.views.suites[suite.id];
230
+ if (isUndefined(suiteView)) {
231
+ return;
232
+ }
233
+ suiteView.refresh();
234
+ };
235
+
236
+ this.refresh = function() {
237
+
238
+ if (isUndefined(this.resultsMenu)) {
239
+ this.createResultsMenu();
240
+ }
241
+
242
+ // currently running UI
243
+ if (isUndefined(this.runningAlert)) {
244
+ this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"});
245
+ dom.alert.appendChild(this.runningAlert);
246
+ }
247
+ this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
248
+
249
+ // skipped specs UI
250
+ if (isUndefined(this.skippedAlert)) {
251
+ this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"});
252
+ }
253
+
254
+ this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
255
+
256
+ if (this.skippedCount === 1 && isDefined(dom.alert)) {
257
+ dom.alert.appendChild(this.skippedAlert);
258
+ }
259
+
260
+ // passing specs UI
261
+ if (isUndefined(this.passedAlert)) {
262
+ this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"});
263
+ }
264
+ this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
265
+
266
+ // failing specs UI
267
+ if (isUndefined(this.failedAlert)) {
268
+ this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
269
+ }
270
+ this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
271
+
272
+ if (this.failedCount === 1 && isDefined(dom.alert)) {
273
+ dom.alert.appendChild(this.failedAlert);
274
+ dom.alert.appendChild(this.resultsMenu);
275
+ }
276
+
277
+ // summary info
278
+ this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
279
+ this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
280
+ };
281
+
282
+ this.complete = function() {
283
+ dom.alert.removeChild(this.runningAlert);
284
+
285
+ this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
286
+
287
+ if (this.failedCount === 0) {
288
+ dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
289
+ } else {
290
+ showDetails();
291
+ }
292
+
293
+ dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
294
+ };
295
+
296
+ return this;
297
+
298
+ function showDetails() {
299
+ if (dom.reporter.className.search(/showDetails/) === -1) {
300
+ dom.reporter.className += " showDetails";
301
+ }
302
+ }
303
+
304
+ function isUndefined(obj) {
305
+ return typeof obj === 'undefined';
306
+ }
307
+
308
+ function isDefined(obj) {
309
+ return !isUndefined(obj);
310
+ }
311
+
312
+ function specPluralizedFor(count) {
313
+ var str = count + " spec";
314
+ if (count > 1) {
315
+ str += "s"
316
+ }
317
+ return str;
318
+ }
319
+
320
+ };
321
+
322
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
323
+
324
+
325
+ jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
326
+ this.spec = spec;
327
+ this.dom = dom;
328
+ this.views = views;
329
+
330
+ this.symbol = this.createDom('li', { className: 'pending' });
331
+ this.dom.symbolSummary.appendChild(this.symbol);
332
+
333
+ this.summary = this.createDom('div', { className: 'specSummary' },
334
+ this.createDom('a', {
335
+ className: 'description',
336
+ href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
337
+ title: this.spec.getFullName()
338
+ }, this.spec.description)
339
+ );
340
+
341
+ this.detail = this.createDom('div', { className: 'specDetail' },
342
+ this.createDom('a', {
343
+ className: 'description',
344
+ href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
345
+ title: this.spec.getFullName()
346
+ }, this.spec.getFullName())
347
+ );
348
+ };
349
+
350
+ jasmine.HtmlReporter.SpecView.prototype.status = function() {
351
+ return this.getSpecStatus(this.spec);
352
+ };
353
+
354
+ jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
355
+ this.symbol.className = this.status();
356
+
357
+ switch (this.status()) {
358
+ case 'skipped':
359
+ break;
360
+
361
+ case 'passed':
362
+ this.appendSummaryToSuiteDiv();
363
+ break;
364
+
365
+ case 'failed':
366
+ this.appendSummaryToSuiteDiv();
367
+ this.appendFailureDetail();
368
+ break;
369
+ }
370
+ };
371
+
372
+ jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
373
+ this.summary.className += ' ' + this.status();
374
+ this.appendToSummary(this.spec, this.summary);
375
+ };
376
+
377
+ jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
378
+ this.detail.className += ' ' + this.status();
379
+
380
+ var resultItems = this.spec.results().getItems();
381
+ var messagesDiv = this.createDom('div', { className: 'messages' });
382
+
383
+ for (var i = 0; i < resultItems.length; i++) {
384
+ var result = resultItems[i];
385
+
386
+ if (result.type == 'log') {
387
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
388
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
389
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
390
+
391
+ if (result.trace.stack) {
392
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
393
+ }
394
+ }
395
+ }
396
+
397
+ if (messagesDiv.childNodes.length > 0) {
398
+ this.detail.appendChild(messagesDiv);
399
+ this.dom.details.appendChild(this.detail);
400
+ }
401
+ };
402
+
403
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
404
+ this.suite = suite;
405
+ this.dom = dom;
406
+ this.views = views;
407
+
408
+ this.element = this.createDom('div', { className: 'suite' },
409
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(this.suite.getFullName()) }, this.suite.description)
410
+ );
411
+
412
+ this.appendToSummary(this.suite, this.element);
413
+ };
414
+
415
+ jasmine.HtmlReporter.SuiteView.prototype.status = function() {
416
+ return this.getSpecStatus(this.suite);
417
+ };
418
+
419
+ jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
420
+ this.element.className += " " + this.status();
421
+ };
422
+
423
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
424
+
425
+ /* @deprecated Use jasmine.HtmlReporter instead
426
+ */
427
+ jasmine.TrivialReporter = function(doc) {
428
+ this.document = doc || document;
429
+ this.suiteDivs = {};
430
+ this.logRunningSpecs = false;
431
+ };
432
+
433
+ jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
434
+ var el = document.createElement(type);
435
+
436
+ for (var i = 2; i < arguments.length; i++) {
437
+ var child = arguments[i];
438
+
439
+ if (typeof child === 'string') {
440
+ el.appendChild(document.createTextNode(child));
441
+ } else {
442
+ if (child) { el.appendChild(child); }
443
+ }
444
+ }
445
+
446
+ for (var attr in attrs) {
447
+ if (attr == "className") {
448
+ el[attr] = attrs[attr];
449
+ } else {
450
+ el.setAttribute(attr, attrs[attr]);
451
+ }
452
+ }
453
+
454
+ return el;
455
+ };
456
+
457
+ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
458
+ var showPassed, showSkipped;
459
+
460
+ this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
461
+ this.createDom('div', { className: 'banner' },
462
+ this.createDom('div', { className: 'logo' },
463
+ this.createDom('span', { className: 'title' }, "Jasmine"),
464
+ this.createDom('span', { className: 'version' }, runner.env.versionString())),
465
+ this.createDom('div', { className: 'options' },
466
+ "Show ",
467
+ showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
468
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
469
+ showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
470
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
471
+ )
472
+ ),
473
+
474
+ this.runnerDiv = this.createDom('div', { className: 'runner running' },
475
+ this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
476
+ this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
477
+ this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
478
+ );
479
+
480
+ this.document.body.appendChild(this.outerDiv);
481
+
482
+ var suites = runner.suites();
483
+ for (var i = 0; i < suites.length; i++) {
484
+ var suite = suites[i];
485
+ var suiteDiv = this.createDom('div', { className: 'suite' },
486
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
487
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
488
+ this.suiteDivs[suite.id] = suiteDiv;
489
+ var parentDiv = this.outerDiv;
490
+ if (suite.parentSuite) {
491
+ parentDiv = this.suiteDivs[suite.parentSuite.id];
492
+ }
493
+ parentDiv.appendChild(suiteDiv);
494
+ }
495
+
496
+ this.startedAt = new Date();
497
+
498
+ var self = this;
499
+ showPassed.onclick = function(evt) {
500
+ if (showPassed.checked) {
501
+ self.outerDiv.className += ' show-passed';
502
+ } else {
503
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
504
+ }
505
+ };
506
+
507
+ showSkipped.onclick = function(evt) {
508
+ if (showSkipped.checked) {
509
+ self.outerDiv.className += ' show-skipped';
510
+ } else {
511
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
512
+ }
513
+ };
514
+ };
515
+
516
+ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
517
+ var results = runner.results();
518
+ var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
519
+ this.runnerDiv.setAttribute("class", className);
520
+ //do it twice for IE
521
+ this.runnerDiv.setAttribute("className", className);
522
+ var specs = runner.specs();
523
+ var specCount = 0;
524
+ for (var i = 0; i < specs.length; i++) {
525
+ if (this.specFilter(specs[i])) {
526
+ specCount++;
527
+ }
528
+ }
529
+ var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
530
+ message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
531
+ this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
532
+
533
+ this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
534
+ };
535
+
536
+ jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
537
+ var results = suite.results();
538
+ var status = results.passed() ? 'passed' : 'failed';
539
+ if (results.totalCount === 0) { // todo: change this to check results.skipped
540
+ status = 'skipped';
541
+ }
542
+ this.suiteDivs[suite.id].className += " " + status;
543
+ };
544
+
545
+ jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
546
+ if (this.logRunningSpecs) {
547
+ this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
548
+ }
549
+ };
550
+
551
+ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
552
+ var results = spec.results();
553
+ var status = results.passed() ? 'passed' : 'failed';
554
+ if (results.skipped) {
555
+ status = 'skipped';
556
+ }
557
+ var specDiv = this.createDom('div', { className: 'spec ' + status },
558
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
559
+ this.createDom('a', {
560
+ className: 'description',
561
+ href: '?spec=' + encodeURIComponent(spec.getFullName()),
562
+ title: spec.getFullName()
563
+ }, spec.description));
564
+
565
+
566
+ var resultItems = results.getItems();
567
+ var messagesDiv = this.createDom('div', { className: 'messages' });
568
+ for (var i = 0; i < resultItems.length; i++) {
569
+ var result = resultItems[i];
570
+
571
+ if (result.type == 'log') {
572
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
573
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
574
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
575
+
576
+ if (result.trace.stack) {
577
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
578
+ }
579
+ }
580
+ }
581
+
582
+ if (messagesDiv.childNodes.length > 0) {
583
+ specDiv.appendChild(messagesDiv);
584
+ }
585
+
586
+ this.suiteDivs[spec.suite.id].appendChild(specDiv);
587
+ };
588
+
589
+ jasmine.TrivialReporter.prototype.log = function() {
590
+ var console = jasmine.getGlobal().console;
591
+ if (console && console.log) {
592
+ if (console.log.apply) {
593
+ console.log.apply(console, arguments);
594
+ } else {
595
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
596
+ }
597
+ }
598
+ };
599
+
600
+ jasmine.TrivialReporter.prototype.getLocation = function() {
601
+ return this.document.location;
602
+ };
603
+
604
+ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
605
+ var paramMap = {};
606
+ var params = this.getLocation().search.substring(1).split('&');
607
+ for (var i = 0; i < params.length; i++) {
608
+ var p = params[i].split('=');
609
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
610
+ }
611
+
612
+ if (!paramMap.spec) {
613
+ return true;
614
+ }
615
+ return spec.getFullName().indexOf(paramMap.spec) === 0;
616
+ };