guard-jasmine 1.19.2 → 2.0.0beta1

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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -234
  3. data/lib/generators/guard_jasmine/install_generator.rb +17 -0
  4. data/lib/generators/guard_jasmine/templates/Guardfile +9 -0
  5. data/lib/guard/jasmine.rb +18 -15
  6. data/lib/guard/jasmine/cli.rb +5 -5
  7. data/lib/guard/jasmine/formatter.rb +10 -0
  8. data/lib/guard/jasmine/inspector.rb +1 -2
  9. data/lib/guard/jasmine/phantomjs/guard-jasmine.js +54 -180
  10. data/lib/guard/jasmine/phantomjs/guard-reporter.js +187 -0
  11. data/lib/guard/jasmine/phantomjs/src/guard-jasmine.coffee +101 -0
  12. data/lib/guard/jasmine/phantomjs/src/guard-reporter.coffee +109 -0
  13. data/lib/guard/jasmine/phantomjs/test/guard-reporter_spec.coffee +41 -0
  14. data/lib/guard/jasmine/runner.rb +178 -268
  15. data/lib/guard/jasmine/server.rb +17 -3
  16. data/lib/guard/jasmine/util.rb +1 -7
  17. data/lib/guard/jasmine/version.rb +1 -1
  18. metadata +135 -26
  19. data/lib/guard/jasmine/phantomjs/guard-jasmine.coffee +0 -193
  20. data/lib/guard/jasmine/phantomjs/lib/console.js +0 -188
  21. data/lib/guard/jasmine/phantomjs/lib/junit_reporter.js +0 -224
  22. data/lib/guard/jasmine/phantomjs/lib/reporter.js +0 -144
  23. data/lib/guard/jasmine/phantomjs/lib/result.js +0 -155
  24. data/lib/guard/jasmine/phantomjs/src/console.coffee +0 -149
  25. data/lib/guard/jasmine/phantomjs/src/reporter.coffee +0 -139
  26. data/lib/guard/jasmine/phantomjs/src/result.coffee +0 -95
  27. data/lib/guard/jasmine/phantomjs/test/console_spec.coffee +0 -125
  28. data/lib/guard/jasmine/phantomjs/test/reporter_spec.coffee +0 -0
  29. data/lib/guard/jasmine/phantomjs/test/result_spec.coffee +0 -311
@@ -1,188 +0,0 @@
1
- (function() {
2
- var Console,
3
- __slice = [].slice;
4
-
5
- Console = (function() {
6
- function Console(console) {
7
- var log;
8
-
9
- log = console.log;
10
- console.log = function() {
11
- var args;
12
-
13
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
14
- return log.call(console, Console.format.apply(Console, args));
15
- };
16
- console.info = function() {
17
- var args;
18
-
19
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
20
- return log.call(console, "INFO: " + (Console.format.apply(Console, args)));
21
- };
22
- console.warn = function() {
23
- var args;
24
-
25
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
26
- return log.call(console, "WARN: " + (Console.format.apply(Console, args)));
27
- };
28
- console.error = function() {
29
- var args;
30
-
31
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
32
- return log.call(console, "ERROR: " + (Console.format.apply(Console, args)));
33
- };
34
- console.debug = function() {
35
- var args;
36
-
37
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
38
- return log.call(console, "DEBUG: " + (Console.format.apply(Console, args)));
39
- };
40
- }
41
-
42
- Console.MAX_OBJECT_DEPTH = 2;
43
-
44
- Console.format = function() {
45
- var arg, args, result, _i, _len,
46
- _this = this;
47
-
48
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
49
- result = [];
50
- if (typeof args[0] === 'string' && /%[sdifo]/gi.test(args[0])) {
51
- arg = args.shift();
52
- result.push(arg.replace(/%[sdifo]/gi, function(str) {
53
- return Console.inspect(args.shift(), str);
54
- }));
55
- }
56
- for (_i = 0, _len = args.length; _i < _len; _i++) {
57
- arg = args[_i];
58
- result.push(Console.inspect(arg));
59
- }
60
- return result.join(' ');
61
- };
62
-
63
- Console.inspect = function(object, type) {
64
- var match, result;
65
-
66
- switch (type) {
67
- case '%s':
68
- result = String(object);
69
- if (match = /'(.*)'/.exec(result)) {
70
- result = match[1];
71
- }
72
- break;
73
- case '%d':
74
- case '%i':
75
- result = parseInt(object);
76
- break;
77
- case '%f':
78
- result = parseFloat(object);
79
- break;
80
- default:
81
- type = Object.prototype.toString.call(object).slice(8, -1);
82
- if (type === 'Object' && object.toJSON) {
83
- result = Console.pp(object.toJSON());
84
- } else if (type === 'Object' && object.toString && object.toString() !== '[object Object]') {
85
- result = Console.pp(object.toString());
86
- if (match = /'(.*)'/.exec(result)) {
87
- result = match[1];
88
- }
89
- } else if (type === 'String') {
90
- result = String(object);
91
- if (match = /'(.*)'/.exec(result)) {
92
- result = match[1];
93
- }
94
- } else {
95
- result = Console.pp(object);
96
- }
97
- }
98
- return result;
99
- };
100
-
101
- Console.pp = function(object, depth) {
102
- var key, result, type, value, _i, _len;
103
-
104
- if (depth == null) {
105
- depth = 0;
106
- }
107
- type = Object.prototype.toString.call(object).slice(8, -1);
108
- result = '';
109
- switch (type) {
110
- case 'Undefined':
111
- case 'Null':
112
- result += type.toLowerCase();
113
- break;
114
- case 'Boolean':
115
- case 'Number':
116
- case 'Date':
117
- result += object.toString();
118
- break;
119
- case 'String':
120
- result += "'" + (object.toString()) + "'";
121
- break;
122
- case 'Array':
123
- if (object.length > 0) {
124
- result += '[';
125
- for (_i = 0, _len = object.length; _i < _len; _i++) {
126
- value = object[_i];
127
- if (depth < Console.MAX_OBJECT_DEPTH || Object.prototype.toString.call(value).slice(8, -1) !== 'Object') {
128
- result += "" + (Console.pp(value, depth + 1)) + ", ";
129
- } else {
130
- result += "[Object], ";
131
- }
132
- }
133
- result = result.slice(0, -2);
134
- result += ']';
135
- } else {
136
- result += '[]';
137
- }
138
- break;
139
- case 'Object':
140
- if (object.jquery) {
141
- if (object.length > 0) {
142
- result += '[';
143
- object.each(function() {
144
- return result += jQuery(this).html();
145
- });
146
- result += ']';
147
- } else {
148
- result += '[]';
149
- }
150
- } else if (Object.keys(object).length > 0) {
151
- result += '{ ';
152
- for (key in object) {
153
- value = object[key];
154
- if (depth < Console.MAX_OBJECT_DEPTH || Object.prototype.toString.call(value).slice(8, -1) !== 'Object') {
155
- if (object.hasOwnProperty(key)) {
156
- result += "" + key + ": " + (Console.pp(value, depth + 1)) + ", ";
157
- }
158
- } else {
159
- result += "" + key + ": [Object], ";
160
- }
161
- }
162
- result = result.slice(0, -2);
163
- result += ' }';
164
- } else {
165
- result += '{}';
166
- }
167
- break;
168
- case 'Function':
169
- result += '[Function]';
170
- }
171
- return result;
172
- };
173
-
174
- return Console;
175
-
176
- })();
177
-
178
- if (typeof module !== 'undefined' && module.exports) {
179
- if (module) {
180
- module.exports = Console;
181
- }
182
- } else {
183
- if (window) {
184
- new Console(window.console);
185
- }
186
- }
187
-
188
- }).call(this);
@@ -1,224 +0,0 @@
1
- (function() {
2
- function elapsed(startTime, endTime) {
3
- return (endTime - startTime)/1000;
4
- }
5
-
6
- function ISODateString(d) {
7
- function pad(n) { return n < 10 ? '0'+n : n; }
8
-
9
- return d.getFullYear() + '-' +
10
- pad(d.getMonth()+1) + '-' +
11
- pad(d.getDate()) + 'T' +
12
- pad(d.getHours()) + ':' +
13
- pad(d.getMinutes()) + ':' +
14
- pad(d.getSeconds());
15
- }
16
-
17
- function trim(str) {
18
- return str.replace(/^\s+/, "" ).replace(/\s+$/, "" );
19
- }
20
-
21
- function escapeInvalidXmlChars(str) {
22
- return str.replace(/\&/g, "&amp;")
23
- .replace(/</g, "&lt;")
24
- .replace(/\>/g, "&gt;")
25
- .replace(/\"/g, "&quot;")
26
- .replace(/\'/g, "&apos;");
27
- }
28
-
29
- /**
30
- * Generates JUnit XML for the given spec run.
31
- * Allows the test results to be used in java based CI
32
- * systems like CruiseControl and Hudson.
33
- *
34
- * @param {string} savePath where to save the files
35
- * @param {boolean} consolidate whether to save nested describes within the
36
- * same file as their parent; default: true
37
- * @param {boolean} useDotNotation whether to separate suite names with
38
- * dots rather than spaces (ie "Class.init" not
39
- * "Class init"); default: true
40
- */
41
- var JUnitXmlReporter = function(savePath, consolidate, useDotNotation) {
42
- this.savePath = savePath || '';
43
- this.consolidate = consolidate === jasmine.undefined ? true : consolidate;
44
- this.useDotNotation = useDotNotation === jasmine.undefined ? true : useDotNotation;
45
- };
46
- JUnitXmlReporter.finished_at = null; // will be updated after all files have been written
47
-
48
- JUnitXmlReporter.prototype = {
49
- reportSpecStarting: function(spec) {
50
- spec.startTime = new Date();
51
-
52
- if (!spec.suite.startTime) {
53
- spec.suite.startTime = spec.startTime;
54
- }
55
- },
56
-
57
- reportSpecResults: function(spec) {
58
- var results = spec.results();
59
- spec.didFail = !results.passed();
60
- spec.duration = elapsed(spec.startTime, new Date());
61
- spec.output = '<testcase classname="' + this.getFullName(spec.suite) +
62
- '" name="' + escapeInvalidXmlChars(spec.description) + '" time="' + spec.duration + '">';
63
- if(results.skipped) {
64
- spec.output = spec.output + "<skipped />";
65
- }
66
-
67
- var failure = "";
68
- var failures = 0;
69
- var resultItems = results.getItems();
70
- for (var i = 0; i < resultItems.length; i++) {
71
- var result = resultItems[i];
72
-
73
- if (result.type == 'expect' && result.passed && !result.passed()) {
74
- failures += 1;
75
- failure += '<failure type="' + result.type + '" message="' + trim(escapeInvalidXmlChars(result.message)) + '">';
76
- failure += escapeInvalidXmlChars(result.trace.stack || result.message);
77
- failure += "</failure>";
78
- }
79
- }
80
- if (failure) {
81
- spec.output += failure;
82
- }
83
- spec.output += "</testcase>";
84
- },
85
-
86
- reportSuiteResults: function(suite) {
87
- var results = suite.results();
88
- var specs = suite.specs();
89
- var specOutput = "";
90
- // for JUnit results, let's only include directly failed tests (not nested suites')
91
- var failedCount = 0;
92
-
93
- suite.status = results.passed() ? 'Passed.' : 'Failed.';
94
- if (results.totalCount === 0) { // todo: change this to check results.skipped
95
- suite.status = 'Skipped.';
96
- }
97
-
98
- // if a suite has no (active?) specs, reportSpecStarting is never called
99
- // and thus the suite has no startTime -- account for that here
100
- suite.startTime = suite.startTime || new Date();
101
- suite.duration = elapsed(suite.startTime, new Date());
102
-
103
- for (var i = 0; i < specs.length; i++) {
104
- failedCount += specs[i].didFail ? 1 : 0;
105
- specOutput += "\n " + specs[i].output;
106
- }
107
- suite.output = '\n<testsuite name="' + this.getFullName(suite) +
108
- '" errors="0" tests="' + specs.length + '" failures="' + failedCount +
109
- '" time="' + suite.duration + '" timestamp="' + ISODateString(suite.startTime) + '">';
110
- suite.output += specOutput;
111
- suite.output += "\n</testsuite>";
112
- },
113
-
114
- reportRunnerResults: function(runner) {
115
- var suites = runner.suites();
116
- for (var i = 0; i < suites.length; i++) {
117
- var suite = suites[i];
118
- var fileName = 'TEST-' + this.getFullName(suite, true) + '.xml';
119
- var output = '<?xml version="1.0" encoding="UTF-8" ?>';
120
- // if we are consolidating, only write out top-level suites
121
- if (this.consolidate && suite.parentSuite) {
122
- continue;
123
- }
124
- else if (this.consolidate) {
125
- output += "\n<testsuites>";
126
- output += this.getNestedOutput(suite);
127
- output += "\n</testsuites>";
128
- this.writeFile(this.savePath, fileName, output);
129
- }
130
- else {
131
- output += suite.output;
132
- this.writeFile(this.savePath, fileName, output);
133
- }
134
- }
135
- // When all done, make it known on JUnitXmlReporter
136
- JUnitXmlReporter.finished_at = (new Date()).getTime();
137
- },
138
-
139
- getNestedOutput: function(suite) {
140
- var output = suite.output;
141
- for (var i = 0; i < suite.suites().length; i++) {
142
- output += this.getNestedOutput(suite.suites()[i]);
143
- }
144
- return output;
145
- },
146
-
147
- writeFile: function(path, filename, text) {
148
- function getQualifiedFilename(separator) {
149
- if (path && path.substr(-1) !== separator && filename.substr(0) !== separator) {
150
- path += separator;
151
- }
152
- return path + filename;
153
- }
154
-
155
- // Rhino
156
- try {
157
- // turn filename into a qualified path
158
- if (path) {
159
- filename = getQualifiedFilename(java.lang.System.getProperty("file.separator"));
160
- // create parent dir and ancestors if necessary
161
- var file = java.io.File(filename);
162
- var parentDir = file.getParentFile();
163
- if (!parentDir.exists()) {
164
- parentDir.mkdirs();
165
- }
166
- }
167
- // finally write the file
168
- var out = new java.io.BufferedWriter(new java.io.FileWriter(filename));
169
- out.write(text);
170
- out.close();
171
- return;
172
- } catch (e) {}
173
- // PhantomJS, via a method injected by phantomjs-testrunner.js
174
- try {
175
- // turn filename into a qualified path
176
- filename = getQualifiedFilename(window.fs_path_separator);
177
- __phantom_writeFile(filename, text);
178
- return;
179
- } catch (f) {}
180
- // Node.js
181
- try {
182
- var fs = require("fs");
183
- var nodejs_path = require("path");
184
- var fd = fs.openSync(nodejs_path.join(path, filename), "w");
185
- fs.writeSync(fd, text, 0);
186
- fs.closeSync(fd);
187
- return;
188
- } catch (g) {}
189
- },
190
-
191
- getFullName: function(suite, isFilename) {
192
- var fullName;
193
- if (this.useDotNotation) {
194
- fullName = suite.description;
195
- for (var parentSuite = suite.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
196
- fullName = parentSuite.description + '.' + fullName;
197
- }
198
- }
199
- else {
200
- fullName = suite.getFullName();
201
- }
202
-
203
- // Either remove or escape invalid XML characters
204
- if (isFilename) {
205
- return fullName.replace(/[^\w]/g, "");
206
- }
207
- return escapeInvalidXmlChars(fullName);
208
- },
209
-
210
- log: function(str) {
211
- var console = jasmine.getGlobal().console;
212
-
213
- if (console && console.log) {
214
- console.log(str);
215
- }
216
- }
217
- };
218
-
219
- if (typeof module !== 'undefined' && module.exports) {
220
- module.exports = JUnitXmlReporter;
221
- } else {
222
- window.JUnitXmlReporter = JUnitXmlReporter;
223
- }
224
- }).call(this);
@@ -1,144 +0,0 @@
1
- (function() {
2
- var ConsoleReporter;
3
-
4
- ConsoleReporter = (function() {
5
- function ConsoleReporter() {}
6
-
7
- ConsoleReporter.prototype.runnerResult = {
8
- passed: false,
9
- stats: {
10
- specs: 0,
11
- failures: 0,
12
- time: 0.0
13
- },
14
- suites: []
15
- };
16
-
17
- ConsoleReporter.prototype.specCount = 0;
18
-
19
- ConsoleReporter.prototype.currentSpecs = {};
20
-
21
- ConsoleReporter.prototype.nestedSuiteResults = {};
22
-
23
- ConsoleReporter.prototype.reportSpecStarting = function(spec) {
24
- return console.log("SPEC_START: " + spec.id);
25
- };
26
-
27
- ConsoleReporter.prototype.reportSpecResults = function(spec) {
28
- var messages, result, specResult, _base, _i, _len, _name, _ref;
29
-
30
- if (!spec.results().skipped) {
31
- specResult = {
32
- id: spec.id,
33
- description: '' + spec.description,
34
- passed: spec.results().failedCount === 0
35
- };
36
- if (spec.results().failedCount !== 0) {
37
- messages = [];
38
- _ref = spec.results().getItems();
39
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
40
- result = _ref[_i];
41
- messages.push(result.message);
42
- }
43
- if (messages.length !== 0) {
44
- specResult['messages'] = messages;
45
- }
46
- }
47
- this.specCount += 1;
48
- (_base = this.currentSpecs)[_name = spec.suite.id] || (_base[_name] = []);
49
- return this.currentSpecs[spec.suite.id].push(specResult);
50
- }
51
- };
52
-
53
- ConsoleReporter.prototype.reportSuiteResults = function(suite) {
54
- var parent, suiteResult, _base, _ref;
55
-
56
- if (!suite.results().skipped) {
57
- suiteResult = {
58
- id: suite.id,
59
- parent: (_ref = suite.parentSuite) != null ? _ref.id : void 0,
60
- description: '' + suite.description,
61
- passed: suite.results().failedCount === 0,
62
- specs: this.currentSpecs[suite.id] || [],
63
- suites: []
64
- };
65
- if (suite.parentSuite != null) {
66
- parent = suite.parentSuite.id;
67
- (_base = this.nestedSuiteResults)[parent] || (_base[parent] = []);
68
- return this.nestedSuiteResults[parent].push(suiteResult);
69
- } else {
70
- this.addNestedSuites(suiteResult);
71
- this.removeEmptySuites(suiteResult);
72
- if (suiteResult.specs.length !== 0 || suiteResult.suites.length !== 0) {
73
- return this.runnerResult.suites.push(suiteResult);
74
- }
75
- }
76
- }
77
- };
78
-
79
- ConsoleReporter.prototype.reportRunnerResults = function(runner) {
80
- var end, runtime;
81
-
82
- runtime = (new Date().getTime() - this.startTime) / 1000;
83
- this.runnerResult['passed'] = runner.results().failedCount === 0;
84
- this.runnerResult['stats'] = {
85
- specs: this.specCount,
86
- failures: runner.results().failedCount,
87
- time: runtime
88
- };
89
- if (window.__coverage__) {
90
- this.runnerResult['coverage'] = window.__coverage__;
91
- }
92
- end = function() {
93
- return console.log("RUNNER_END");
94
- };
95
- return setTimeout(end, 10);
96
- };
97
-
98
- ConsoleReporter.prototype.reportRunnerStarting = function(runner) {
99
- return this.startTime = new Date().getTime();
100
- };
101
-
102
- ConsoleReporter.prototype.addNestedSuites = function(suiteResult) {
103
- var suite, _i, _len, _ref, _results;
104
-
105
- if (this.nestedSuiteResults[suiteResult.id]) {
106
- _ref = this.nestedSuiteResults[suiteResult.id];
107
- _results = [];
108
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
109
- suite = _ref[_i];
110
- this.addNestedSuites(suite);
111
- _results.push(suiteResult.suites.push(suite));
112
- }
113
- return _results;
114
- }
115
- };
116
-
117
- ConsoleReporter.prototype.removeEmptySuites = function(suiteResult) {
118
- var suite, suites, _i, _len, _ref;
119
-
120
- suites = [];
121
- _ref = suiteResult.suites;
122
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
123
- suite = _ref[_i];
124
- this.removeEmptySuites(suite);
125
- if (suite.suites.length !== 0 || suite.specs.length !== 0) {
126
- suites.push(suite);
127
- }
128
- }
129
- return suiteResult.suites = suites;
130
- };
131
-
132
- ConsoleReporter.prototype.log = function(message) {};
133
-
134
- return ConsoleReporter;
135
-
136
- })();
137
-
138
- if (typeof module !== 'undefined' && module.exports) {
139
- module.exports = ConsoleReporter;
140
- } else {
141
- window.ConsoleReporter = ConsoleReporter;
142
- }
143
-
144
- }).call(this);