jasmine 1.0.2.0 → 1.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/HOW_TO_TEST.markdown +4 -6
  2. data/generators/jasmine/templates/lib/tasks/jasmine.rake +8 -2
  3. data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +1 -1
  4. data/jasmine.gemspec +4 -5
  5. data/jasmine/Gemfile +2 -2
  6. data/jasmine/HowToRelease.markdown +29 -0
  7. data/jasmine/MIT.LICENSE +1 -1
  8. data/jasmine/README.markdown +37 -15
  9. data/jasmine/Rakefile +42 -58
  10. data/jasmine/example/spec/SpecHelper.js +3 -3
  11. data/jasmine/images/jasmine_favicon.png +0 -0
  12. data/jasmine/jshint/jshint.js +5919 -0
  13. data/jasmine/jshint/run.js +98 -0
  14. data/jasmine/lib/jasmine-html.js +5 -3
  15. data/jasmine/lib/jasmine.js +56 -32
  16. data/jasmine/spec/node_suite.js +233 -0
  17. data/jasmine/spec/runner.html +4 -2
  18. data/jasmine/spec/suites/EnvSpec.js +1 -1
  19. data/jasmine/spec/suites/ExceptionsSpec.js +2 -2
  20. data/jasmine/spec/suites/JsApiReporterSpec.js +1 -1
  21. data/jasmine/spec/suites/MatchersSpec.js +9 -9
  22. data/jasmine/spec/suites/MultiReporterSpec.js +3 -3
  23. data/jasmine/spec/suites/SpecRunningSpec.js +1 -1
  24. data/jasmine/spec/suites/SpecSpec.js +1 -1
  25. data/jasmine/spec/suites/TrivialConsoleReporterSpec.js +431 -0
  26. data/jasmine/spec/suites/UtilSpec.js +0 -1
  27. data/jasmine/spec/suites/WaitsForBlockSpec.js +32 -1
  28. data/jasmine/src/Env.js +2 -2
  29. data/jasmine/src/Matchers.js +3 -3
  30. data/jasmine/src/PrettyPrinter.js +2 -1
  31. data/jasmine/src/WaitsBlock.js +3 -1
  32. data/jasmine/src/WaitsForBlock.js +4 -2
  33. data/jasmine/src/base.js +39 -20
  34. data/jasmine/src/console/TrivialConsoleReporter.js +144 -0
  35. data/jasmine/src/html/TrivialReporter.js +5 -3
  36. data/jasmine/src/util.js +1 -1
  37. data/jasmine/src/version.json +2 -2
  38. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +1 -1
  39. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +1 -1
  40. data/lib/jasmine.rb +1 -20
  41. data/lib/jasmine/railtie.rb +20 -0
  42. data/lib/jasmine/run.html.erb +2 -1
  43. data/lib/jasmine/version.rb +2 -2
  44. data/spec/spec_helper.rb +0 -2
  45. metadata +16 -58
  46. data/install.rb +0 -2
  47. data/jasmine/images/fail-16.png +0 -0
  48. data/jasmine/images/fail.png +0 -0
  49. data/jasmine/images/go-16.png +0 -0
  50. data/jasmine/images/go.png +0 -0
  51. data/jasmine/images/pending-16.png +0 -0
  52. data/jasmine/images/pending.png +0 -0
  53. data/jasmine/images/question-bk.png +0 -0
  54. data/jasmine/images/questionbk-16.png +0 -0
  55. data/jasmine/images/spinner.gif +0 -0
  56. data/lib/jasmine/generator.rb +0 -9
@@ -0,0 +1,98 @@
1
+ var fs = require("fs");
2
+ var sys = require("sys");
3
+ var path = require("path");
4
+ var JSHINT = require("./jshint").JSHINT;
5
+
6
+ function isExcluded(fullPath) {
7
+ var fileName = path.basename(fullPath);
8
+ var excludeFiles = ["json2.js", "jshint.js", "publish.js", "node_suite.js", "jasmine.js", "jasmine-html.js"];
9
+ for (var i = 0; i < excludeFiles.length; i++) {
10
+ if (fileName == excludeFiles[i]) {
11
+ return true;
12
+ }
13
+ }
14
+ return false;
15
+ }
16
+
17
+ // DWF TODO: This function could/should be re-written
18
+ function allJasmineJsFiles(rootDir) {
19
+ var files = [];
20
+ fs.readdirSync(rootDir).filter(function(filename) {
21
+
22
+ var fullPath = rootDir + "/" + filename;
23
+ if (fs.statSync(fullPath).isDirectory() && !fullPath.match(/pages/)) {
24
+ var subDirFiles = allJasmineJsFiles(fullPath);
25
+ if (subDirFiles.length > 0) {
26
+ files = files.concat();
27
+ return true;
28
+ }
29
+ } else {
30
+ if (fullPath.match(/\.js$/) && !isExcluded(fullPath)) {
31
+ files.push(fullPath);
32
+ return true;
33
+ }
34
+ }
35
+ return false;
36
+ });
37
+
38
+ return files;
39
+ }
40
+
41
+ var jasmineJsFiles = allJasmineJsFiles(".");
42
+ jasmineJsFiles.reverse(); //cheap way to do the stuff in src stuff first
43
+
44
+ var jasmineJsHintConfig = {
45
+
46
+ forin:true, //while it's possible that we could be
47
+ //considering unwanted prototype methods, mostly
48
+ //we're doing this because the jsobjects are being
49
+ //used as maps.
50
+
51
+ loopfunc:true //we're fine with functions defined inside loops (setTimeout functions, etc)
52
+
53
+ };
54
+
55
+ var jasmineGlobals = {};
56
+
57
+
58
+ //jasmine.undefined is a jasmine-ism, let's let it go...
59
+ function removeJasmineUndefinedErrors(errors) {
60
+ var keepErrors = [];
61
+ for (var i = 0; i < errors.length; i++) {
62
+ if (!(errors[i] &&
63
+ errors[i].raw &&
64
+ errors[i].evidence &&
65
+ ( errors[i].evidence.match(/jasmine\.undefined/) ||
66
+ errors[i].evidence.match(/diz be undefined yo/) )
67
+ )) {
68
+ keepErrors.push(errors[i]);
69
+ }
70
+ }
71
+ return keepErrors;
72
+ }
73
+
74
+ (function() {
75
+ var ansi = {
76
+ green: '\033[32m',
77
+ red: '\033[31m',
78
+ yellow: '\033[33m',
79
+ none: '\033[0m'
80
+ };
81
+
82
+ for (var i = 0; i < jasmineJsFiles.length; i++) {
83
+ var file = jasmineJsFiles[i];
84
+ JSHINT(fs.readFileSync(file, "utf8"), jasmineJsHintConfig);
85
+ var errors = JSHINT.data().errors || [];
86
+ errors = removeJasmineUndefinedErrors(errors);
87
+
88
+ if (errors.length >= 1) {
89
+ console.log(ansi.red + "Jasmine JSHint failure: " + ansi.none);
90
+ console.log(file);
91
+ console.log(errors);
92
+ process.exit(1);
93
+ }
94
+ }
95
+
96
+ console.log(ansi.green + "Jasmine JSHint PASSED." + ansi.none);
97
+ })();
98
+
@@ -110,7 +110,7 @@ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
110
110
  jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
111
111
  var results = suite.results();
112
112
  var status = results.passed() ? 'passed' : 'failed';
113
- if (results.totalCount == 0) { // todo: change this to check results.skipped
113
+ if (results.totalCount === 0) { // todo: change this to check results.skipped
114
114
  status = 'skipped';
115
115
  }
116
116
  this.suiteDivs[suite.id].className += " " + status;
@@ -183,6 +183,8 @@ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
183
183
  paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
184
184
  }
185
185
 
186
- if (!paramMap["spec"]) return true;
187
- return spec.getFullName().indexOf(paramMap["spec"]) == 0;
186
+ if (!paramMap.spec) {
187
+ return true;
188
+ }
189
+ return spec.getFullName().indexOf(paramMap.spec) === 0;
188
190
  };
@@ -1,10 +1,12 @@
1
+ var isCommonJS = typeof window == "undefined";
2
+
1
3
  /**
2
4
  * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
3
5
  *
4
6
  * @namespace
5
7
  */
6
8
  var jasmine = {};
7
-
9
+ if (isCommonJS) exports.jasmine = jasmine;
8
10
  /**
9
11
  * @private
10
12
  */
@@ -20,6 +22,12 @@ jasmine.unimplementedMethod_ = function() {
20
22
  */
21
23
  jasmine.undefined = jasmine.___undefined___;
22
24
 
25
+ /**
26
+ * Show diagnostic messages in the console if set to true
27
+ *
28
+ */
29
+ jasmine.VERBOSE = false;
30
+
23
31
  /**
24
32
  * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
25
33
  *
@@ -106,7 +114,8 @@ jasmine.ExpectationResult.prototype.passed = function () {
106
114
  * Getter for the Jasmine environment. Ensures one gets created
107
115
  */
108
116
  jasmine.getEnv = function() {
109
- return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
117
+ var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
118
+ return env;
110
119
  };
111
120
 
112
121
  /**
@@ -169,7 +178,7 @@ jasmine.pp = function(value) {
169
178
  * @returns {Boolean}
170
179
  */
171
180
  jasmine.isDomNode = function(obj) {
172
- return obj['nodeType'] > 0;
181
+ return obj.nodeType > 0;
173
182
  };
174
183
 
175
184
  /**
@@ -405,7 +414,7 @@ jasmine.isSpy = function(putativeSpy) {
405
414
  * @param {Array} methodNames array of names of methods to make spies
406
415
  */
407
416
  jasmine.createSpyObj = function(baseName, methodNames) {
408
- if (!jasmine.isArray_(methodNames) || methodNames.length == 0) {
417
+ if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
409
418
  throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
410
419
  }
411
420
  var obj = {};
@@ -443,6 +452,7 @@ jasmine.log = function() {
443
452
  var spyOn = function(obj, methodName) {
444
453
  return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
445
454
  };
455
+ if (isCommonJS) exports.spyOn = spyOn;
446
456
 
447
457
  /**
448
458
  * Creates a Jasmine spec that will be added to the current suite.
@@ -460,6 +470,7 @@ var spyOn = function(obj, methodName) {
460
470
  var it = function(desc, func) {
461
471
  return jasmine.getEnv().it(desc, func);
462
472
  };
473
+ if (isCommonJS) exports.it = it;
463
474
 
464
475
  /**
465
476
  * Creates a <em>disabled</em> Jasmine spec.
@@ -472,6 +483,7 @@ var it = function(desc, func) {
472
483
  var xit = function(desc, func) {
473
484
  return jasmine.getEnv().xit(desc, func);
474
485
  };
486
+ if (isCommonJS) exports.xit = xit;
475
487
 
476
488
  /**
477
489
  * Starts a chain for a Jasmine expectation.
@@ -484,6 +496,7 @@ var xit = function(desc, func) {
484
496
  var expect = function(actual) {
485
497
  return jasmine.getEnv().currentSpec.expect(actual);
486
498
  };
499
+ if (isCommonJS) exports.expect = expect;
487
500
 
488
501
  /**
489
502
  * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
@@ -493,6 +506,7 @@ var expect = function(actual) {
493
506
  var runs = function(func) {
494
507
  jasmine.getEnv().currentSpec.runs(func);
495
508
  };
509
+ if (isCommonJS) exports.runs = runs;
496
510
 
497
511
  /**
498
512
  * Waits a fixed time period before moving to the next block.
@@ -503,6 +517,7 @@ var runs = function(func) {
503
517
  var waits = function(timeout) {
504
518
  jasmine.getEnv().currentSpec.waits(timeout);
505
519
  };
520
+ if (isCommonJS) exports.waits = waits;
506
521
 
507
522
  /**
508
523
  * Waits for the latchFunction to return true before proceeding to the next block.
@@ -514,6 +529,7 @@ var waits = function(timeout) {
514
529
  var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
515
530
  jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
516
531
  };
532
+ if (isCommonJS) exports.waitsFor = waitsFor;
517
533
 
518
534
  /**
519
535
  * A function that is called before each spec in a suite.
@@ -525,6 +541,7 @@ var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout
525
541
  var beforeEach = function(beforeEachFunction) {
526
542
  jasmine.getEnv().beforeEach(beforeEachFunction);
527
543
  };
544
+ if (isCommonJS) exports.beforeEach = beforeEach;
528
545
 
529
546
  /**
530
547
  * A function that is called after each spec in a suite.
@@ -536,6 +553,7 @@ var beforeEach = function(beforeEachFunction) {
536
553
  var afterEach = function(afterEachFunction) {
537
554
  jasmine.getEnv().afterEach(afterEachFunction);
538
555
  };
556
+ if (isCommonJS) exports.afterEach = afterEach;
539
557
 
540
558
  /**
541
559
  * Defines a suite of specifications.
@@ -555,6 +573,7 @@ var afterEach = function(afterEachFunction) {
555
573
  var describe = function(description, specDefinitions) {
556
574
  return jasmine.getEnv().describe(description, specDefinitions);
557
575
  };
576
+ if (isCommonJS) exports.describe = describe;
558
577
 
559
578
  /**
560
579
  * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
@@ -565,27 +584,27 @@ var describe = function(description, specDefinitions) {
565
584
  var xdescribe = function(description, specDefinitions) {
566
585
  return jasmine.getEnv().xdescribe(description, specDefinitions);
567
586
  };
587
+ if (isCommonJS) exports.xdescribe = xdescribe;
568
588
 
569
589
 
570
590
  // Provide the XMLHttpRequest class for IE 5.x-6.x:
571
591
  jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
572
- try {
573
- return new ActiveXObject("Msxml2.XMLHTTP.6.0");
574
- } catch(e) {
575
- }
576
- try {
577
- return new ActiveXObject("Msxml2.XMLHTTP.3.0");
578
- } catch(e) {
592
+ function tryIt(f) {
593
+ try {
594
+ return f();
595
+ } catch(e) {
596
+ }
597
+ return null;
579
598
  }
580
- try {
581
- return new ActiveXObject("Msxml2.XMLHTTP");
582
- } catch(e) {
583
- }
584
- try {
585
- return new ActiveXObject("Microsoft.XMLHTTP");
586
- } catch(e) {
587
- }
588
- throw new Error("This browser does not support XMLHttpRequest.");
599
+
600
+ var xhr = tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.6.0");}) ||
601
+ tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0");}) ||
602
+ tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP");}) ||
603
+ tryIt(function(){return new ActiveXObject("Microsoft.XMLHTTP");});
604
+
605
+ if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
606
+
607
+ return xhr;
589
608
  } : XMLHttpRequest;
590
609
  /**
591
610
  * @namespace
@@ -606,7 +625,7 @@ jasmine.util.inherit = function(childClass, parentClass) {
606
625
  var subclass = function() {
607
626
  };
608
627
  subclass.prototype = parentClass.prototype;
609
- childClass.prototype = new subclass;
628
+ childClass.prototype = new subclass();
610
629
  };
611
630
 
612
631
  jasmine.util.formatException = function(e) {
@@ -828,7 +847,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
828
847
  b.__Jasmine_been_here_before__ = a;
829
848
 
830
849
  var hasKey = function(obj, keyName) {
831
- return obj != null && obj[keyName] !== jasmine.undefined;
850
+ return obj !== null && obj[keyName] !== jasmine.undefined;
832
851
  };
833
852
 
834
853
  for (var property in b) {
@@ -854,7 +873,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
854
873
 
855
874
  delete a.__Jasmine_been_here_before__;
856
875
  delete b.__Jasmine_been_here_before__;
857
- return (mismatchKeys.length == 0 && mismatchValues.length == 0);
876
+ return (mismatchKeys.length === 0 && mismatchValues.length === 0);
858
877
  };
859
878
 
860
879
  jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
@@ -1302,7 +1321,7 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
1302
1321
  throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1303
1322
  }
1304
1323
  this.message = function() {
1305
- if (this.actual.callCount == 0) {
1324
+ if (this.actual.callCount === 0) {
1306
1325
  // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
1307
1326
  return [
1308
1327
  "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
@@ -1333,7 +1352,7 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() {
1333
1352
  return [
1334
1353
  "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
1335
1354
  "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
1336
- ]
1355
+ ];
1337
1356
  };
1338
1357
 
1339
1358
  return !this.env.contains_(this.actual.argsForCall, expectedArgs);
@@ -1390,7 +1409,7 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
1390
1409
 
1391
1410
  this.message = function() {
1392
1411
  if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
1393
- return ["Expected function " + not + "to throw", expected ? expected.message || expected : " an exception", ", but it threw", exception.message || exception].join(' ');
1412
+ return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
1394
1413
  } else {
1395
1414
  return "Expected function to throw an exception.";
1396
1415
  }
@@ -1602,7 +1621,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
1602
1621
  jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
1603
1622
  for (var property in obj) {
1604
1623
  if (property == '__Jasmine_been_here_before__') continue;
1605
- fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false);
1624
+ fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
1625
+ obj.__lookupGetter__(property) !== null) : false);
1606
1626
  }
1607
1627
  };
1608
1628
 
@@ -2172,7 +2192,9 @@ jasmine.WaitsBlock = function(env, timeout, spec) {
2172
2192
  jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
2173
2193
 
2174
2194
  jasmine.WaitsBlock.prototype.execute = function (onComplete) {
2175
- this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
2195
+ if (jasmine.VERBOSE) {
2196
+ this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
2197
+ }
2176
2198
  this.env.setTimeout(function () {
2177
2199
  onComplete();
2178
2200
  }, this.timeout);
@@ -2200,7 +2222,9 @@ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
2200
2222
  jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
2201
2223
 
2202
2224
  jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
2203
- this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
2225
+ if (jasmine.VERBOSE) {
2226
+ this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
2227
+ }
2204
2228
  var latchFunctionResult;
2205
2229
  try {
2206
2230
  latchFunctionResult = this.latchFunction.apply(this.spec);
@@ -2415,7 +2439,7 @@ jasmine.getGlobal().clearInterval = function(timeoutKey) {
2415
2439
 
2416
2440
  jasmine.version_= {
2417
2441
  "major": 1,
2418
- "minor": 0,
2419
- "build": 1,
2420
- "revision": 1286311016
2442
+ "minor": 1,
2443
+ "build": 0,
2444
+ "revision": 1304737707
2421
2445
  };
@@ -0,0 +1,233 @@
1
+ var fs = require('fs');
2
+ var sys = require('sys');
3
+ var path = require('path');
4
+
5
+ // yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
6
+ // undefined = "diz be undefined yo";
7
+
8
+ var jasmineGlobals = require("../src/base");
9
+ for(var k in jasmineGlobals) {global[k] = jasmineGlobals[k];}
10
+
11
+ //load jasmine src files based on the order in runner.html
12
+ var srcFilesInProperRequireOrder = [];
13
+ var runnerHtmlLines = fs.readFileSync("spec/runner.html", "utf8").split("\n");
14
+ var srcFileLines = [];
15
+ for (var i=0; i<runnerHtmlLines.length; i++)
16
+ if (runnerHtmlLines[i].match(/script(.*?)\/src\//))
17
+ srcFileLines.push(runnerHtmlLines[i]);
18
+ for (i=0; i<srcFileLines.length; i++) srcFilesInProperRequireOrder.push(srcFileLines[i].match(/src=\"(.*?)\"/)[1]);
19
+ for (i=0; i<srcFilesInProperRequireOrder.length; i++) require(srcFilesInProperRequireOrder[i]);
20
+
21
+
22
+ /*
23
+ Pulling in code from jasmine-node.
24
+
25
+ We can't just depend on jasmine-node because it has its own jasmine that it uses.
26
+ */
27
+
28
+ global.window = {
29
+ setTimeout: setTimeout,
30
+ clearTimeout: clearTimeout,
31
+ setInterval: setInterval,
32
+ clearInterval: clearInterval
33
+ };
34
+
35
+ delete global.window;
36
+
37
+ function noop(){}
38
+
39
+ jasmine.executeSpecs = function(specs, done, isVerbose, showColors){
40
+ var log = [];
41
+ var columnCounter = 0;
42
+ var start = 0;
43
+ var elapsed = 0;
44
+ var verbose = isVerbose || false;
45
+ var colors = showColors || false;
46
+
47
+ var ansi = {
48
+ green: '\033[32m',
49
+ red: '\033[31m',
50
+ yellow: '\033[33m',
51
+ none: '\033[0m'
52
+ };
53
+
54
+ for (var i = 0, len = specs.length; i < len; ++i){
55
+ var filename = specs[i];
56
+ require(filename.replace(/\.\w+$/, ""));
57
+ }
58
+
59
+ var jasmineEnv = jasmine.getEnv();
60
+ jasmineEnv.reporter = {
61
+ log: function(str){
62
+ },
63
+
64
+ reportSpecStarting: function(runner) {
65
+ },
66
+
67
+ reportRunnerStarting: function(runner) {
68
+ sys.puts('Started');
69
+ start = new Date().getTime();
70
+ },
71
+
72
+ reportSuiteResults: function(suite) {
73
+ var specResults = suite.results();
74
+ var path = [];
75
+ while(suite) {
76
+ path.unshift(suite.description);
77
+ suite = suite.parentSuite;
78
+ }
79
+ var description = path.join(' ');
80
+
81
+ if (verbose)
82
+ log.push('Spec ' + description);
83
+
84
+ specResults.items_.forEach(function(spec){
85
+ if (spec.failedCount > 0 && spec.description) {
86
+ if (!verbose)
87
+ log.push(description);
88
+ log.push(' it ' + spec.description);
89
+ spec.items_.forEach(function(result){
90
+ log.push(' ' + result.trace.stack + '\n');
91
+ });
92
+ }
93
+ });
94
+ },
95
+
96
+ reportSpecResults: function(spec) {
97
+ var result = spec.results();
98
+ var msg = '';
99
+ if (result.passed())
100
+ {
101
+ msg = (colors) ? (ansi.green + '.' + ansi.none) : '.';
102
+ // } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec?
103
+ // msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*';
104
+ } else {
105
+ msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F';
106
+ }
107
+ sys.print(msg);
108
+ if (columnCounter++ < 50) return;
109
+ columnCounter = 0;
110
+ sys.print('\n');
111
+ },
112
+
113
+
114
+ reportRunnerResults: function(runner) {
115
+ elapsed = (new Date().getTime() - start) / 1000;
116
+ sys.puts('\n');
117
+ log.forEach(function(log){
118
+ sys.puts(log);
119
+ });
120
+ sys.puts('Finished in ' + elapsed + ' seconds');
121
+
122
+ var summary = jasmine.printRunnerResults(runner);
123
+ if(colors)
124
+ {
125
+ if(runner.results().failedCount === 0 )
126
+ sys.puts(ansi.green + summary + ansi.none);
127
+ else
128
+ sys.puts(ansi.red + summary + ansi.none);
129
+ } else {
130
+ sys.puts(summary);
131
+ }
132
+ (done||noop)(runner, log);
133
+ }
134
+ };
135
+ jasmineEnv.execute();
136
+ };
137
+
138
+ jasmine.getAllSpecFiles = function(dir, matcher){
139
+ var specs = [];
140
+
141
+ if (fs.statSync(dir).isFile() && dir.match(matcher)) {
142
+ specs.push(dir);
143
+ } else {
144
+ var files = fs.readdirSync(dir);
145
+ for (var i = 0, len = files.length; i < len; ++i){
146
+ var filename = dir + '/' + files[i];
147
+ if (fs.statSync(filename).isFile() && filename.match(matcher)){
148
+ specs.push(filename);
149
+ }else if (fs.statSync(filename).isDirectory()){
150
+ var subfiles = this.getAllSpecFiles(filename, matcher);
151
+ subfiles.forEach(function(result){
152
+ specs.push(result);
153
+ });
154
+ }
155
+ }
156
+ }
157
+
158
+ return specs;
159
+ };
160
+
161
+ jasmine.printRunnerResults = function(runner){
162
+ var results = runner.results();
163
+ var suites = runner.suites();
164
+ var msg = '';
165
+ msg += suites.length + ' spec' + ((suites.length === 1) ? '' : 's') + ', ';
166
+ msg += results.totalCount + ' expectation' + ((results.totalCount === 1) ? '' : 's') + ', ';
167
+ msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n';
168
+ return msg;
169
+ };
170
+
171
+ function now(){
172
+ return new Date().getTime();
173
+ }
174
+
175
+ jasmine.asyncSpecWait = function(){
176
+ var wait = jasmine.asyncSpecWait;
177
+ wait.start = now();
178
+ wait.done = false;
179
+ (function innerWait(){
180
+ waits(10);
181
+ runs(function() {
182
+ if (wait.start + wait.timeout < now()) {
183
+ expect('timeout waiting for spec').toBeNull();
184
+ } else if (wait.done) {
185
+ wait.done = false;
186
+ } else {
187
+ innerWait();
188
+ }
189
+ });
190
+ })();
191
+ };
192
+ jasmine.asyncSpecWait.timeout = 4 * 1000;
193
+ jasmine.asyncSpecDone = function(){
194
+ jasmine.asyncSpecWait.done = true;
195
+ };
196
+
197
+ for ( var key in jasmine) {
198
+ exports[key] = jasmine[key];
199
+ }
200
+
201
+ /*
202
+ End jasmine-node runner
203
+ */
204
+
205
+
206
+
207
+
208
+
209
+ var isVerbose = false;
210
+ var showColors = true;
211
+ process.argv.forEach(function(arg){
212
+ switch(arg) {
213
+ case '--color': showColors = true; break;
214
+ case '--noColor': showColors = false; break;
215
+ case '--verbose': isVerbose = true; break;
216
+ }
217
+ });
218
+
219
+ var specs = jasmine.getAllSpecFiles(__dirname + '/suites', new RegExp(".js$"));
220
+ var domIndependentSpecs = [];
221
+ for(var i=0; i<specs.length; i++) {
222
+ if (fs.readFileSync(specs[i], "utf8").indexOf("document.createElement")<0) {
223
+ domIndependentSpecs.push(specs[i]);
224
+ }
225
+ }
226
+
227
+ jasmine.executeSpecs(domIndependentSpecs, function(runner, log){
228
+ if (runner.results().failedCount === 0) {
229
+ process.exit(0);
230
+ } else {
231
+ process.exit(1);
232
+ }
233
+ }, isVerbose, showColors);