jasmine-core 1.3.1 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/lib/jasmine-core.rb +14 -1
  2. data/lib/jasmine-core/boot.js +131 -0
  3. data/lib/jasmine-core/boot/boot.js +109 -0
  4. data/lib/jasmine-core/example/spec/PlayerSpec.js +2 -2
  5. data/lib/jasmine-core/example/spec/SpecHelper.js +14 -8
  6. data/lib/jasmine-core/jasmine-html.js +289 -616
  7. data/lib/jasmine-core/jasmine.css +52 -80
  8. data/lib/jasmine-core/jasmine.js +1972 -2211
  9. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +161 -386
  10. data/lib/jasmine-core/spec/core/AnySpec.js +45 -0
  11. data/lib/jasmine-core/spec/core/CallTrackerSpec.js +105 -0
  12. data/lib/jasmine-core/spec/core/ClockSpec.js +314 -0
  13. data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +96 -97
  14. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +179 -0
  15. data/lib/jasmine-core/spec/core/EnvSpec.js +454 -102
  16. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +56 -0
  17. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +15 -126
  18. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
  19. data/lib/jasmine-core/spec/core/ExpectationSpec.js +320 -0
  20. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +150 -38
  21. data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +64 -0
  22. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +43 -42
  23. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +147 -0
  24. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +40 -0
  25. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +92 -1075
  26. data/lib/jasmine-core/spec/core/SpecSpec.js +215 -95
  27. data/lib/jasmine-core/spec/core/SpySpec.js +28 -196
  28. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +101 -0
  29. data/lib/jasmine-core/spec/core/SuiteSpec.js +216 -106
  30. data/lib/jasmine-core/spec/core/TimerSpec.js +13 -0
  31. data/lib/jasmine-core/spec/core/UtilSpec.js +19 -30
  32. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +219 -0
  33. data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +51 -0
  34. data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
  35. data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
  36. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +19 -0
  37. data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
  38. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +36 -0
  39. data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
  40. data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
  41. data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
  42. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +17 -0
  43. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +24 -0
  44. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +28 -0
  45. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +46 -0
  46. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +57 -0
  47. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +34 -0
  48. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +280 -0
  49. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +98 -0
  50. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +19 -0
  51. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +494 -0
  52. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
  53. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +8 -8
  54. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +3 -3
  55. data/lib/jasmine-core/spec/html/QueryStringSpec.js +43 -0
  56. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
  57. data/lib/jasmine-core/spec/node_suite.js +137 -79
  58. data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
  59. data/lib/jasmine-core/spec/support/dev_boot.js +118 -0
  60. data/lib/jasmine-core/version.rb +5 -2
  61. metadata +47 -103
  62. data/lib/jasmine-core/example/SpecRunner.html +0 -54
  63. data/lib/jasmine-core/spec/core/BaseSpec.js +0 -27
  64. data/lib/jasmine-core/spec/core/MatchersSpec.js +0 -1157
  65. data/lib/jasmine-core/spec/core/MockClockSpec.js +0 -38
  66. data/lib/jasmine-core/spec/core/MultiReporterSpec.js +0 -45
  67. data/lib/jasmine-core/spec/core/NestedResultsSpec.js +0 -54
  68. data/lib/jasmine-core/spec/core/QueueSpec.js +0 -23
  69. data/lib/jasmine-core/spec/core/ReporterSpec.js +0 -56
  70. data/lib/jasmine-core/spec/core/RunnerSpec.js +0 -280
  71. data/lib/jasmine-core/spec/core/WaitsForBlockSpec.js +0 -118
  72. data/lib/jasmine-core/spec/html/HTMLReporterSpec.js +0 -209
  73. data/lib/jasmine-core/spec/html/TrivialReporterSpec.js +0 -239
@@ -0,0 +1,18 @@
1
+ describe("j$.HtmlSpecFilter", function() {
2
+
3
+ it("should match when no string is provided", function() {
4
+ var specFilter = new j$.HtmlSpecFilter();
5
+
6
+ expect(specFilter.matches("foo")).toBe(true);
7
+ expect(specFilter.matches("*bar")).toBe(true);
8
+ });
9
+
10
+ it("should only match the provided string", function() {
11
+ var specFilter = new j$.HtmlSpecFilter({
12
+ filterString: function() { return "foo"; }
13
+ });
14
+
15
+ expect(specFilter.matches("foo")).toBe(true);
16
+ expect(specFilter.matches("bar")).toBe(false);
17
+ });
18
+ });
@@ -2,21 +2,21 @@ describe("MatchersSpec - HTML Dependent", function () {
2
2
  var env, spec;
3
3
 
4
4
  beforeEach(function() {
5
- env = new jasmine.Env();
5
+ env = new j$.Env();
6
6
  env.updateInterval = 0;
7
7
 
8
8
  var suite = env.describe("suite", function() {
9
9
  spec = env.it("spec", function() {
10
10
  });
11
11
  });
12
- spyOn(spec, 'addMatcherResult');
12
+ spyOn(spec, 'addExpectationResult');
13
13
 
14
- this.addMatchers({
14
+ addMatchers({
15
15
  toPass: function() {
16
- return lastResult().passed();
16
+ return lastResult().passed;
17
17
  },
18
18
  toFail: function() {
19
- return !lastResult().passed();
19
+ return !lastResult().passed;
20
20
  }
21
21
  });
22
22
  });
@@ -26,13 +26,13 @@ describe("MatchersSpec - HTML Dependent", function () {
26
26
  }
27
27
 
28
28
  function lastResult() {
29
- return spec.addMatcherResult.mostRecentCall.args[0];
29
+ return spec.addExpectationResult.mostRecentCall.args[1];
30
30
  }
31
31
 
32
- it("toEqual with DOM nodes", function() {
32
+ xit("toEqual with DOM nodes", function() {
33
33
  var nodeA = document.createElement('div');
34
34
  var nodeB = document.createElement('div');
35
35
  expect((match(nodeA).toEqual(nodeA))).toPass();
36
36
  expect((match(nodeA).toEqual(nodeB))).toFail();
37
37
  });
38
- });
38
+ });
@@ -1,8 +1,8 @@
1
- describe("jasmine.pp (HTML Dependent)", function () {
1
+ describe("j$.pp (HTML Dependent)", function () {
2
2
  it("should stringify HTML nodes properly", function() {
3
3
  var sampleNode = document.createElement('div');
4
4
  sampleNode.innerHTML = 'foo<b>bar</b>';
5
- expect(jasmine.pp(sampleNode)).toEqual("HTMLNode");
6
- expect(jasmine.pp({foo: sampleNode})).toEqual("{ foo : HTMLNode }");
5
+ expect(j$.pp(sampleNode)).toEqual("HTMLNode");
6
+ expect(j$.pp({foo: sampleNode})).toEqual("{ foo : HTMLNode }");
7
7
  });
8
8
  });
@@ -0,0 +1,43 @@
1
+ describe("QueryString", function() {
2
+
3
+ describe("#setParam", function() {
4
+
5
+ it("sets the query string to include the given key/value pair", function() {
6
+ var windowLocation = {
7
+ search: ""
8
+ },
9
+ queryString = new j$.QueryString({
10
+ getWindowLocation: function() { return windowLocation }
11
+ });
12
+
13
+ queryString.setParam("foo", "bar baz");
14
+
15
+ expect(windowLocation.search).toMatch(/foo=bar%20baz/);
16
+ });
17
+ });
18
+
19
+ describe("#getParam", function() {
20
+
21
+ it("returns the value of the requested key", function() {
22
+ var windowLocation = {
23
+ search: "?baz=quux%20corge"
24
+ },
25
+ queryString = new j$.QueryString({
26
+ getWindowLocation: function() { return windowLocation }
27
+ });
28
+
29
+ expect(queryString.getParam("baz")).toEqual("quux corge");
30
+ });
31
+
32
+ it("returns null if the key is not present", function() {
33
+ var windowLocation = {
34
+ search: ""
35
+ },
36
+ queryString = new j$.QueryString({
37
+ getWindowLocation: function() { return windowLocation }
38
+ });
39
+
40
+ expect(queryString.getParam("baz")).toBeFalsy();
41
+ });
42
+ });
43
+ });
@@ -0,0 +1,62 @@
1
+ describe("ResultsNode", function() {
2
+ it("wraps a result", function() {
3
+ var fakeResult = {
4
+ id: 123,
5
+ message: "foo"
6
+ },
7
+ node = new j$.ResultsNode(fakeResult, "suite", null);
8
+
9
+ expect(node.result).toBe(fakeResult);
10
+ expect(node.type).toEqual("suite");
11
+ });
12
+
13
+ it("can add children with a type", function() {
14
+ var fakeResult = {
15
+ id: 123,
16
+ message: "foo"
17
+ },
18
+ fakeChildResult = {
19
+ id: 456,
20
+ message: "bar"
21
+ },
22
+ node = new j$.ResultsNode(fakeResult, "suite", null);
23
+
24
+ node.addChild(fakeChildResult, "spec");
25
+
26
+ expect(node.children.length).toEqual(1);
27
+ expect(node.children[0].result).toEqual(fakeChildResult);
28
+ expect(node.children[0].type).toEqual("spec");
29
+ });
30
+
31
+ it("has a pointer back to its parent ResultNode", function() {
32
+ var fakeResult = {
33
+ id: 123,
34
+ message: "foo"
35
+ },
36
+ fakeChildResult = {
37
+ id: 456,
38
+ message: "bar"
39
+ },
40
+ node = new j$.ResultsNode(fakeResult, "suite", null);
41
+
42
+ node.addChild(fakeChildResult, "spec");
43
+
44
+ expect(node.children[0].parent).toBe(node);
45
+ });
46
+
47
+ it("can provide the most recent child", function() {
48
+ var fakeResult = {
49
+ id: 123,
50
+ message: "foo"
51
+ },
52
+ fakeChildResult = {
53
+ id: 456,
54
+ message: "bar"
55
+ },
56
+ node = new j$.ResultsNode(fakeResult, "suite", null);
57
+
58
+ node.addChild(fakeChildResult, "spec");
59
+
60
+ expect(node.last()).toBe(node.children[node.children.length - 1]);
61
+ });
62
+ });
@@ -2,124 +2,182 @@ var fs = require('fs');
2
2
  var util = require('util');
3
3
  var path = require('path');
4
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
-
9
- var jasmineGlobals = require('../lib/jasmine-core/jasmine.js');
10
- for (var k in jasmineGlobals) {
11
- global[k] = jasmineGlobals[k];
12
- }
13
- require('../src/console/ConsoleReporter.js');
14
-
15
- /*
16
- Pulling in code from jasmine-node.
17
-
18
- We can't just depend on jasmine-node because it has its own jasmine that it uses.
19
- */
20
-
21
- global.window = {
22
- setTimeout: setTimeout,
23
- clearTimeout: clearTimeout,
24
- setInterval: setInterval,
25
- clearInterval: clearInterval
5
+ // boot code for jasmine
6
+ var jasmineRequire = require('../lib/jasmine-core/jasmine.js');
7
+ var jasmine = jasmineRequire.core(jasmineRequire);
8
+
9
+ var consoleFns = require('../src/console/console.js');
10
+ extend(jasmineRequire, consoleFns);
11
+ jasmineRequire.console(jasmineRequire, jasmine);
12
+
13
+ var env = jasmine.getEnv();
14
+
15
+ var jasmineInterface = {
16
+ describe: function(description, specDefinitions) {
17
+ return env.describe(description, specDefinitions);
18
+ },
19
+
20
+ xdescribe: function(description, specDefinitions) {
21
+ return env.xdescribe(description, specDefinitions);
22
+ },
23
+
24
+ it: function(desc, func) {
25
+ return env.it(desc, func);
26
+ },
27
+
28
+ xit: function(desc, func) {
29
+ return env.xit(desc, func);
30
+ },
31
+
32
+ beforeEach: function(beforeEachFunction) {
33
+ return env.beforeEach(beforeEachFunction);
34
+ },
35
+
36
+ afterEach: function(afterEachFunction) {
37
+ return env.afterEach(afterEachFunction);
38
+ },
39
+
40
+ expect: function(actual) {
41
+ return env.expect(actual);
42
+ },
43
+
44
+ addMatchers: function(matchers) {
45
+ return env.addMatchers(matchers);
46
+ },
47
+
48
+ spyOn: function(obj, methodName) {
49
+ return env.spyOn(obj, methodName);
50
+ },
51
+
52
+ clock: env.clock,
53
+ setTimeout: env.clock.setTimeout,
54
+ clearTimeout: env.clock.clearTimeout,
55
+ setInterval: env.clock.setInterval,
56
+ clearInterval: env.clock.clearInterval,
57
+
58
+ jsApiReporter: new jasmine.JsApiReporter({
59
+ timer: new jasmine.Timer()
60
+ })
26
61
  };
27
62
 
28
- delete global.window;
63
+ extend(global, jasmineInterface);
29
64
 
30
- function noop() {
65
+ function extend(destination, source) {
66
+ for (var property in source) destination[property] = source[property];
67
+ return destination;
31
68
  }
32
69
 
33
- jasmine.executeSpecs = function(specs, done, isVerbose, showColors) {
34
- for (var i = 0, len = specs.length; i < len; ++i) {
70
+ // Jasmine "runner"
71
+ function executeSpecs(specs, done, isVerbose, showColors) {
72
+ global.jasmine = jasmine;
73
+
74
+ for (var i = 0; i < specs.length; i++) {
35
75
  var filename = specs[i];
36
76
  require(filename.replace(/\.\w+$/, ""));
37
77
  }
38
78
 
39
- var jasmineEnv = jasmine.getEnv();
40
- var consoleReporter = new jasmine.ConsoleReporter(util.print, done, showColors);
79
+ var env = jasmine.getEnv();
80
+ var consoleReporter = new jasmine.ConsoleReporter({
81
+ print: util.print,
82
+ onComplete: done,
83
+ showColors: showColors,
84
+ timer: new jasmine.Timer()
85
+ });
41
86
 
42
- jasmineEnv.addReporter(consoleReporter);
43
- jasmineEnv.execute();
44
- };
87
+ env.addReporter(consoleReporter);
88
+ env.execute();
89
+ }
45
90
 
46
- jasmine.getAllSpecFiles = function(dir, matcher) {
47
- var specs = [];
91
+ function getFiles(dir, matcher) {
92
+ var allFiles = [];
48
93
 
49
94
  if (fs.statSync(dir).isFile() && dir.match(matcher)) {
50
- specs.push(dir);
95
+ allFiles.push(dir);
51
96
  } else {
52
97
  var files = fs.readdirSync(dir);
53
98
  for (var i = 0, len = files.length; i < len; ++i) {
54
99
  var filename = dir + '/' + files[i];
55
100
  if (fs.statSync(filename).isFile() && filename.match(matcher)) {
56
- specs.push(filename);
101
+ allFiles.push(filename);
57
102
  } else if (fs.statSync(filename).isDirectory()) {
58
- var subfiles = this.getAllSpecFiles(filename, matcher);
103
+ var subfiles = getFiles(filename);
59
104
  subfiles.forEach(function(result) {
60
- specs.push(result);
105
+ allFiles.push(result);
61
106
  });
62
107
  }
63
108
  }
64
109
  }
110
+ return allFiles;
111
+ }
65
112
 
66
- return specs;
67
- };
68
-
69
- function now() {
70
- return new Date().getTime();
113
+ function getSpecFiles(dir) {
114
+ return getFiles(dir, new RegExp("Spec.js$"));
71
115
  }
72
116
 
73
- jasmine.asyncSpecWait = function() {
74
- var wait = jasmine.asyncSpecWait;
75
- wait.start = now();
76
- wait.done = false;
77
- (function innerWait() {
78
- waits(10);
79
- runs(function() {
80
- if (wait.start + wait.timeout < now()) {
81
- expect('timeout waiting for spec').toBeNull();
82
- } else if (wait.done) {
83
- wait.done = false;
84
- } else {
85
- innerWait();
86
- }
87
- });
88
- })();
89
- };
90
- jasmine.asyncSpecWait.timeout = 4 * 1000;
91
- jasmine.asyncSpecDone = function() {
92
- jasmine.asyncSpecWait.done = true;
93
- };
117
+ var j$require = (function() {
118
+ var exported = {},
119
+ j$req;
94
120
 
95
- for (var key in jasmine) {
96
- exports[key] = jasmine[key];
97
- }
121
+ global.getJasmineRequireObj = getJasmineRequireObj;
122
+
123
+ j$req = require(__dirname + "/../src/core/requireCore.js");
124
+ extend(j$req, require(__dirname + "/../src/console/requireConsole.js"));
125
+
126
+ var srcFiles = getFiles(__dirname + "/../src/core");
127
+ srcFiles.push(__dirname + "/../src/version.js");
128
+ srcFiles.push(__dirname + "/../src/console/ConsoleReporter.js");
129
+
130
+ for (var i = 0; i < srcFiles.length; i++) {
131
+ require(srcFiles[i]);
132
+ }
133
+ extend(j$req, exported);
134
+
135
+ delete global.getJasmineRequireObj;
98
136
 
99
- /*
100
- End jasmine-node runner
101
- */
137
+ return j$req;
102
138
 
139
+ function getJasmineRequireObj() {
140
+ return exported;
141
+ }
142
+ }());
143
+
144
+ var j$ = j$require.core(j$require);
145
+ j$require.console(j$require, j$);
146
+
147
+ // options from command line
103
148
  var isVerbose = false;
104
149
  var showColors = true;
150
+ var perfSuite = false;
151
+
105
152
  process.argv.forEach(function(arg) {
106
153
  switch (arg) {
107
- case '--color': showColors = true; break;
108
- case '--noColor': showColors = false; break;
109
- case '--verbose': isVerbose = true; break;
154
+ case '--color':
155
+ showColors = true;
156
+ break;
157
+ case '--noColor':
158
+ showColors = false;
159
+ break;
160
+ case '--verbose':
161
+ isVerbose = true;
162
+ break;
163
+ case '--perf':
164
+ perfSuite = true;
165
+ break;
110
166
  }
111
167
  });
112
168
 
113
- var specs = jasmine.getAllSpecFiles(__dirname, new RegExp(".js$"));
114
- var domIndependentSpecs = [];
115
- for (var i = 0; i < specs.length; i++) {
116
- if (fs.readFileSync(specs[i], "utf8").indexOf("document.createElement") < 0) {
117
- domIndependentSpecs.push(specs[i]);
118
- }
169
+ specs = [];
170
+
171
+ if (perfSuite) {
172
+ specs = getFiles(__dirname + '/performance', new RegExp("test.js$"));
173
+ } else {
174
+ var consoleSpecs = getSpecFiles(__dirname + "/console"),
175
+ coreSpecs = getSpecFiles(__dirname + "/core"),
176
+ specs = consoleSpecs.concat(coreSpecs);
119
177
  }
120
178
 
121
- jasmine.executeSpecs(domIndependentSpecs, function(runner, log) {
122
- if (runner.results().failedCount === 0) {
179
+ executeSpecs(specs, function(passed) {
180
+ if (passed) {
123
181
  process.exit(0);
124
182
  } else {
125
183
  process.exit(1);
@@ -0,0 +1,10 @@
1
+ describe("performance", function() {
2
+ for (var i = 0; i < 10000; i++) {
3
+ it("should pass", function() {
4
+ expect(true).toBe(true);
5
+ });
6
+ it("should fail", function() {
7
+ expect(true).toBe(false);
8
+ });
9
+ }
10
+ });