jaspec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +82 -0
  7. data/Rakefile +13 -0
  8. data/bin/jaspec +6 -0
  9. data/jaspec.gemspec +24 -0
  10. data/lib/jaspec.rb +9 -0
  11. data/lib/jaspec/cli.rb +20 -0
  12. data/lib/jaspec/runner.rb +35 -0
  13. data/lib/jaspec/runner/phantom.js +99 -0
  14. data/lib/jaspec/runner/runner.html +83 -0
  15. data/lib/jaspec/version.rb +3 -0
  16. data/spec/javascripts/barSpec.coffee +5 -0
  17. data/spec/javascripts/fooSpec.js +9 -0
  18. data/spec/javascripts/globalSpec.coffee +3 -0
  19. data/spec/javascripts/nonAmdSpec.coffee +4 -0
  20. data/spec/javascripts/stubbableSpec.coffee +7 -0
  21. data/spec/src/bar.coffee +2 -0
  22. data/spec/src/foo.js +5 -0
  23. data/spec/src/nonAmd.js +1 -0
  24. data/spec/src/stubbable.js +5 -0
  25. data/vendor/coffee-script-1.8.0.js +12 -0
  26. data/vendor/cs-0.5.0.js +317 -0
  27. data/vendor/jasmine-2.1.3/MIT.LICENSE +20 -0
  28. data/vendor/jasmine-2.1.3/SpecRunner.html +26 -0
  29. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/boot.js +120 -0
  30. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/console.js +190 -0
  31. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine-html.js +404 -0
  32. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine.css +62 -0
  33. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine.js +2908 -0
  34. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine_favicon.png +0 -0
  35. data/vendor/jasmine-2.1.3/spec/PlayerSpec.js +58 -0
  36. data/vendor/jasmine-2.1.3/spec/SpecHelper.js +15 -0
  37. data/vendor/jasmine-2.1.3/src/Player.js +22 -0
  38. data/vendor/jasmine-2.1.3/src/Song.js +7 -0
  39. data/vendor/requirejs-2.1.15.min.js +36 -0
  40. metadata +134 -0
@@ -0,0 +1,190 @@
1
+ /*
2
+ Copyright (c) 2008-2014 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
+ function getJasmineRequireObj() {
24
+ if (typeof module !== 'undefined' && module.exports) {
25
+ return exports;
26
+ } else {
27
+ window.jasmineRequire = window.jasmineRequire || {};
28
+ return window.jasmineRequire;
29
+ }
30
+ }
31
+
32
+ getJasmineRequireObj().console = function(jRequire, j$) {
33
+ j$.ConsoleReporter = jRequire.ConsoleReporter();
34
+ };
35
+
36
+ getJasmineRequireObj().ConsoleReporter = function() {
37
+
38
+ var noopTimer = {
39
+ start: function(){},
40
+ elapsed: function(){ return 0; }
41
+ };
42
+
43
+ function ConsoleReporter(options) {
44
+ var print = options.print,
45
+ showColors = options.showColors || false,
46
+ onComplete = options.onComplete || function() {},
47
+ timer = options.timer || noopTimer,
48
+ specCount,
49
+ failureCount,
50
+ failedSpecs = [],
51
+ pendingCount,
52
+ ansi = {
53
+ green: '\x1B[32m',
54
+ red: '\x1B[31m',
55
+ yellow: '\x1B[33m',
56
+ none: '\x1B[0m'
57
+ },
58
+ failedSuites = [];
59
+
60
+ print('ConsoleReporter is deprecated and will be removed in a future version.');
61
+
62
+ this.jasmineStarted = function() {
63
+ specCount = 0;
64
+ failureCount = 0;
65
+ pendingCount = 0;
66
+ print('Started');
67
+ printNewline();
68
+ timer.start();
69
+ };
70
+
71
+ this.jasmineDone = function() {
72
+ printNewline();
73
+ for (var i = 0; i < failedSpecs.length; i++) {
74
+ specFailureDetails(failedSpecs[i]);
75
+ }
76
+
77
+ if(specCount > 0) {
78
+ printNewline();
79
+
80
+ var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' +
81
+ failureCount + ' ' + plural('failure', failureCount);
82
+
83
+ if (pendingCount) {
84
+ specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount);
85
+ }
86
+
87
+ print(specCounts);
88
+ } else {
89
+ print('No specs found');
90
+ }
91
+
92
+ printNewline();
93
+ var seconds = timer.elapsed() / 1000;
94
+ print('Finished in ' + seconds + ' ' + plural('second', seconds));
95
+ printNewline();
96
+
97
+ for(i = 0; i < failedSuites.length; i++) {
98
+ suiteFailureDetails(failedSuites[i]);
99
+ }
100
+
101
+ onComplete(failureCount === 0);
102
+ };
103
+
104
+ this.specDone = function(result) {
105
+ specCount++;
106
+
107
+ if (result.status == 'pending') {
108
+ pendingCount++;
109
+ print(colored('yellow', '*'));
110
+ return;
111
+ }
112
+
113
+ if (result.status == 'passed') {
114
+ print(colored('green', '.'));
115
+ return;
116
+ }
117
+
118
+ if (result.status == 'failed') {
119
+ failureCount++;
120
+ failedSpecs.push(result);
121
+ print(colored('red', 'F'));
122
+ }
123
+ };
124
+
125
+ this.suiteDone = function(result) {
126
+ if (result.failedExpectations && result.failedExpectations.length > 0) {
127
+ failureCount++;
128
+ failedSuites.push(result);
129
+ }
130
+ };
131
+
132
+ return this;
133
+
134
+ function printNewline() {
135
+ print('\n');
136
+ }
137
+
138
+ function colored(color, str) {
139
+ return showColors ? (ansi[color] + str + ansi.none) : str;
140
+ }
141
+
142
+ function plural(str, count) {
143
+ return count == 1 ? str : str + 's';
144
+ }
145
+
146
+ function repeat(thing, times) {
147
+ var arr = [];
148
+ for (var i = 0; i < times; i++) {
149
+ arr.push(thing);
150
+ }
151
+ return arr;
152
+ }
153
+
154
+ function indent(str, spaces) {
155
+ var lines = (str || '').split('\n');
156
+ var newArr = [];
157
+ for (var i = 0; i < lines.length; i++) {
158
+ newArr.push(repeat(' ', spaces).join('') + lines[i]);
159
+ }
160
+ return newArr.join('\n');
161
+ }
162
+
163
+ function specFailureDetails(result) {
164
+ printNewline();
165
+ print(result.fullName);
166
+
167
+ for (var i = 0; i < result.failedExpectations.length; i++) {
168
+ var failedExpectation = result.failedExpectations[i];
169
+ printNewline();
170
+ print(indent(failedExpectation.message, 2));
171
+ print(indent(failedExpectation.stack, 2));
172
+ }
173
+
174
+ printNewline();
175
+ }
176
+
177
+ function suiteFailureDetails(result) {
178
+ for (var i = 0; i < result.failedExpectations.length; i++) {
179
+ printNewline();
180
+ print(colored('red', 'An error was thrown in an afterAll'));
181
+ printNewline();
182
+ print(colored('red', 'AfterAll ' + result.failedExpectations[i].message));
183
+
184
+ }
185
+ printNewline();
186
+ }
187
+ }
188
+
189
+ return ConsoleReporter;
190
+ };
@@ -0,0 +1,404 @@
1
+ /*
2
+ Copyright (c) 2008-2014 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(j$);
26
+ j$.QueryString = jasmineRequire.QueryString();
27
+ j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
28
+ };
29
+
30
+ jasmineRequire.HtmlReporter = function(j$) {
31
+
32
+ var noopTimer = {
33
+ start: function() {},
34
+ elapsed: function() { return 0; }
35
+ };
36
+
37
+ function HtmlReporter(options) {
38
+ var env = options.env || {},
39
+ getContainer = options.getContainer,
40
+ createElement = options.createElement,
41
+ createTextNode = options.createTextNode,
42
+ onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
43
+ timer = options.timer || noopTimer,
44
+ results = [],
45
+ specsExecuted = 0,
46
+ failureCount = 0,
47
+ pendingSpecCount = 0,
48
+ htmlReporterMain,
49
+ symbols,
50
+ failedSuites = [];
51
+
52
+ this.initialize = function() {
53
+ clearPrior();
54
+ htmlReporterMain = createDom('div', {className: 'jasmine_html-reporter'},
55
+ createDom('div', {className: 'banner'},
56
+ createDom('a', {className: 'title', href: 'http://jasmine.github.io/', target: '_blank'}),
57
+ createDom('span', {className: 'version'}, j$.version)
58
+ ),
59
+ createDom('ul', {className: 'symbol-summary'}),
60
+ createDom('div', {className: 'alert'}),
61
+ createDom('div', {className: 'results'},
62
+ createDom('div', {className: 'failures'})
63
+ )
64
+ );
65
+ getContainer().appendChild(htmlReporterMain);
66
+
67
+ symbols = find('.symbol-summary');
68
+ };
69
+
70
+ var totalSpecsDefined;
71
+ this.jasmineStarted = function(options) {
72
+ totalSpecsDefined = options.totalSpecsDefined || 0;
73
+ timer.start();
74
+ };
75
+
76
+ var summary = createDom('div', {className: 'summary'});
77
+
78
+ var topResults = new j$.ResultsNode({}, '', null),
79
+ currentParent = topResults;
80
+
81
+ this.suiteStarted = function(result) {
82
+ currentParent.addChild(result, 'suite');
83
+ currentParent = currentParent.last();
84
+ };
85
+
86
+ this.suiteDone = function(result) {
87
+ if (result.status == 'failed') {
88
+ failedSuites.push(result);
89
+ }
90
+
91
+ if (currentParent == topResults) {
92
+ return;
93
+ }
94
+
95
+ currentParent = currentParent.parent;
96
+ };
97
+
98
+ this.specStarted = function(result) {
99
+ currentParent.addChild(result, 'spec');
100
+ };
101
+
102
+ var failures = [];
103
+ this.specDone = function(result) {
104
+ if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
105
+ console.error('Spec \'' + result.fullName + '\' has no expectations.');
106
+ }
107
+
108
+ if (result.status != 'disabled') {
109
+ specsExecuted++;
110
+ }
111
+
112
+ symbols.appendChild(createDom('li', {
113
+ className: noExpectations(result) ? 'empty' : result.status,
114
+ id: 'spec_' + result.id,
115
+ title: result.fullName
116
+ }
117
+ ));
118
+
119
+ if (result.status == 'failed') {
120
+ failureCount++;
121
+
122
+ var failure =
123
+ createDom('div', {className: 'spec-detail failed'},
124
+ createDom('div', {className: 'description'},
125
+ createDom('a', {title: result.fullName, href: specHref(result)}, result.fullName)
126
+ ),
127
+ createDom('div', {className: 'messages'})
128
+ );
129
+ var messages = failure.childNodes[1];
130
+
131
+ for (var i = 0; i < result.failedExpectations.length; i++) {
132
+ var expectation = result.failedExpectations[i];
133
+ messages.appendChild(createDom('div', {className: 'result-message'}, expectation.message));
134
+ messages.appendChild(createDom('div', {className: 'stack-trace'}, expectation.stack));
135
+ }
136
+
137
+ failures.push(failure);
138
+ }
139
+
140
+ if (result.status == 'pending') {
141
+ pendingSpecCount++;
142
+ }
143
+ };
144
+
145
+ this.jasmineDone = function() {
146
+ var banner = find('.banner');
147
+ banner.appendChild(createDom('span', {className: 'duration'}, 'finished in ' + timer.elapsed() / 1000 + 's'));
148
+
149
+ var alert = find('.alert');
150
+
151
+ alert.appendChild(createDom('span', { className: 'exceptions' },
152
+ createDom('label', { className: 'label', 'for': 'raise-exceptions' }, 'raise exceptions'),
153
+ createDom('input', {
154
+ className: 'raise',
155
+ id: 'raise-exceptions',
156
+ type: 'checkbox'
157
+ })
158
+ ));
159
+ var checkbox = find('#raise-exceptions');
160
+
161
+ checkbox.checked = !env.catchingExceptions();
162
+ checkbox.onclick = onRaiseExceptionsClick;
163
+
164
+ if (specsExecuted < totalSpecsDefined) {
165
+ var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
166
+ alert.appendChild(
167
+ createDom('span', {className: 'bar skipped'},
168
+ createDom('a', {href: '?', title: 'Run all specs'}, skippedMessage)
169
+ )
170
+ );
171
+ }
172
+ var statusBarMessage = '';
173
+ var statusBarClassName = 'bar ';
174
+
175
+ if (totalSpecsDefined > 0) {
176
+ statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
177
+ if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
178
+ statusBarClassName += (failureCount > 0) ? 'failed' : 'passed';
179
+ } else {
180
+ statusBarClassName += 'skipped';
181
+ statusBarMessage += 'No specs found';
182
+ }
183
+
184
+ alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage));
185
+
186
+ for(i = 0; i < failedSuites.length; i++) {
187
+ var failedSuite = failedSuites[i];
188
+ for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
189
+ var errorBarMessage = 'AfterAll ' + failedSuite.failedExpectations[j].message;
190
+ var errorBarClassName = 'bar errored';
191
+ alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage));
192
+ }
193
+ }
194
+
195
+ var results = find('.results');
196
+ results.appendChild(summary);
197
+
198
+ summaryList(topResults, summary);
199
+
200
+ function summaryList(resultsTree, domParent) {
201
+ var specListNode;
202
+ for (var i = 0; i < resultsTree.children.length; i++) {
203
+ var resultNode = resultsTree.children[i];
204
+ if (resultNode.type == 'suite') {
205
+ var suiteListNode = createDom('ul', {className: 'suite', id: 'suite-' + resultNode.result.id},
206
+ createDom('li', {className: 'suite-detail'},
207
+ createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description)
208
+ )
209
+ );
210
+
211
+ summaryList(resultNode, suiteListNode);
212
+ domParent.appendChild(suiteListNode);
213
+ }
214
+ if (resultNode.type == 'spec') {
215
+ if (domParent.getAttribute('class') != 'specs') {
216
+ specListNode = createDom('ul', {className: 'specs'});
217
+ domParent.appendChild(specListNode);
218
+ }
219
+ var specDescription = resultNode.result.description;
220
+ if(noExpectations(resultNode.result)) {
221
+ specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
222
+ }
223
+ specListNode.appendChild(
224
+ createDom('li', {
225
+ className: resultNode.result.status,
226
+ id: 'spec-' + resultNode.result.id
227
+ },
228
+ createDom('a', {href: specHref(resultNode.result)}, specDescription)
229
+ )
230
+ );
231
+ }
232
+ }
233
+ }
234
+
235
+ if (failures.length) {
236
+ alert.appendChild(
237
+ createDom('span', {className: 'menu bar spec-list'},
238
+ createDom('span', {}, 'Spec List | '),
239
+ createDom('a', {className: 'failures-menu', href: '#'}, 'Failures')));
240
+ alert.appendChild(
241
+ createDom('span', {className: 'menu bar failure-list'},
242
+ createDom('a', {className: 'spec-list-menu', href: '#'}, 'Spec List'),
243
+ createDom('span', {}, ' | Failures ')));
244
+
245
+ find('.failures-menu').onclick = function() {
246
+ setMenuModeTo('failure-list');
247
+ };
248
+ find('.spec-list-menu').onclick = function() {
249
+ setMenuModeTo('spec-list');
250
+ };
251
+
252
+ setMenuModeTo('failure-list');
253
+
254
+ var failureNode = find('.failures');
255
+ for (var i = 0; i < failures.length; i++) {
256
+ failureNode.appendChild(failures[i]);
257
+ }
258
+ }
259
+ };
260
+
261
+ return this;
262
+
263
+ function find(selector) {
264
+ return getContainer().querySelector('.jasmine_html-reporter ' + selector);
265
+ }
266
+
267
+ function clearPrior() {
268
+ // return the reporter
269
+ var oldReporter = find('');
270
+
271
+ if(oldReporter) {
272
+ getContainer().removeChild(oldReporter);
273
+ }
274
+ }
275
+
276
+ function createDom(type, attrs, childrenVarArgs) {
277
+ var el = createElement(type);
278
+
279
+ for (var i = 2; i < arguments.length; i++) {
280
+ var child = arguments[i];
281
+
282
+ if (typeof child === 'string') {
283
+ el.appendChild(createTextNode(child));
284
+ } else {
285
+ if (child) {
286
+ el.appendChild(child);
287
+ }
288
+ }
289
+ }
290
+
291
+ for (var attr in attrs) {
292
+ if (attr == 'className') {
293
+ el[attr] = attrs[attr];
294
+ } else {
295
+ el.setAttribute(attr, attrs[attr]);
296
+ }
297
+ }
298
+
299
+ return el;
300
+ }
301
+
302
+ function pluralize(singular, count) {
303
+ var word = (count == 1 ? singular : singular + 's');
304
+
305
+ return '' + count + ' ' + word;
306
+ }
307
+
308
+ function specHref(result) {
309
+ return '?spec=' + encodeURIComponent(result.fullName);
310
+ }
311
+
312
+ function setMenuModeTo(mode) {
313
+ htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode);
314
+ }
315
+
316
+ function noExpectations(result) {
317
+ return (result.failedExpectations.length + result.passedExpectations.length) === 0 &&
318
+ result.status === 'passed';
319
+ }
320
+ }
321
+
322
+ return HtmlReporter;
323
+ };
324
+
325
+ jasmineRequire.HtmlSpecFilter = function() {
326
+ function HtmlSpecFilter(options) {
327
+ var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
328
+ var filterPattern = new RegExp(filterString);
329
+
330
+ this.matches = function(specName) {
331
+ return filterPattern.test(specName);
332
+ };
333
+ }
334
+
335
+ return HtmlSpecFilter;
336
+ };
337
+
338
+ jasmineRequire.ResultsNode = function() {
339
+ function ResultsNode(result, type, parent) {
340
+ this.result = result;
341
+ this.type = type;
342
+ this.parent = parent;
343
+
344
+ this.children = [];
345
+
346
+ this.addChild = function(result, type) {
347
+ this.children.push(new ResultsNode(result, type, this));
348
+ };
349
+
350
+ this.last = function() {
351
+ return this.children[this.children.length - 1];
352
+ };
353
+ }
354
+
355
+ return ResultsNode;
356
+ };
357
+
358
+ jasmineRequire.QueryString = function() {
359
+ function QueryString(options) {
360
+
361
+ this.setParam = function(key, value) {
362
+ var paramMap = queryStringToParamMap();
363
+ paramMap[key] = value;
364
+ options.getWindowLocation().search = toQueryString(paramMap);
365
+ };
366
+
367
+ this.getParam = function(key) {
368
+ return queryStringToParamMap()[key];
369
+ };
370
+
371
+ return this;
372
+
373
+ function toQueryString(paramMap) {
374
+ var qStrPairs = [];
375
+ for (var prop in paramMap) {
376
+ qStrPairs.push(encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop]));
377
+ }
378
+ return '?' + qStrPairs.join('&');
379
+ }
380
+
381
+ function queryStringToParamMap() {
382
+ var paramStr = options.getWindowLocation().search.substring(1),
383
+ params = [],
384
+ paramMap = {};
385
+
386
+ if (paramStr.length > 0) {
387
+ params = paramStr.split('&');
388
+ for (var i = 0; i < params.length; i++) {
389
+ var p = params[i].split('=');
390
+ var value = decodeURIComponent(p[1]);
391
+ if (value === 'true' || value === 'false') {
392
+ value = JSON.parse(value);
393
+ }
394
+ paramMap[decodeURIComponent(p[0])] = value;
395
+ }
396
+ }
397
+
398
+ return paramMap;
399
+ }
400
+
401
+ }
402
+
403
+ return QueryString;
404
+ };