jasmine-core 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/lib/jasmine-core.rb +17 -0
  2. data/lib/jasmine-core/example/SpecRunner.html +54 -0
  3. data/lib/jasmine-core/example/spec/PlayerSpec.js +58 -0
  4. data/lib/jasmine-core/example/spec/SpecHelper.js +9 -0
  5. data/lib/jasmine-core/example/src/Player.js +22 -0
  6. data/lib/jasmine-core/example/src/Song.js +7 -0
  7. data/lib/jasmine-core/jasmine-html.js +190 -0
  8. data/lib/jasmine-core/jasmine.css +166 -0
  9. data/lib/jasmine-core/jasmine.js +2476 -0
  10. data/lib/jasmine-core/json2.js +478 -0
  11. data/lib/jasmine-core/version.rb +8 -0
  12. data/spec/console/ConsoleReporterSpec.js +451 -0
  13. data/spec/core/BaseSpec.js +27 -0
  14. data/spec/core/CustomMatchersSpec.js +97 -0
  15. data/spec/core/EnvSpec.js +159 -0
  16. data/spec/core/ExceptionsSpec.js +149 -0
  17. data/spec/core/JsApiReporterSpec.js +103 -0
  18. data/spec/core/MatchersSpec.js +838 -0
  19. data/spec/core/MockClockSpec.js +38 -0
  20. data/spec/core/MultiReporterSpec.js +45 -0
  21. data/spec/core/NestedResultsSpec.js +54 -0
  22. data/spec/core/PrettyPrintSpec.js +87 -0
  23. data/spec/core/QueueSpec.js +23 -0
  24. data/spec/core/ReporterSpec.js +56 -0
  25. data/spec/core/RunnerSpec.js +267 -0
  26. data/spec/core/SpecRunningSpec.js +1258 -0
  27. data/spec/core/SpecSpec.js +124 -0
  28. data/spec/core/SpySpec.js +201 -0
  29. data/spec/core/SuiteSpec.js +120 -0
  30. data/spec/core/UtilSpec.js +39 -0
  31. data/spec/core/WaitsForBlockSpec.js +118 -0
  32. data/spec/html/MatchersHtmlSpec.js +38 -0
  33. data/spec/html/PrettyPrintHtmlSpec.js +8 -0
  34. data/spec/html/TrivialReporterSpec.js +239 -0
  35. data/spec/node_suite.js +127 -0
  36. data/spec/runner.html +79 -0
  37. data/spec/templates/runner.html.erb +49 -0
  38. data/spec/templates/script_tag.html.erb +1 -0
  39. metadata +164 -0
@@ -0,0 +1,118 @@
1
+ describe('WaitsForBlock', function () {
2
+ var env, suite, timeout, spec, message, onComplete, fakeTimer;
3
+ beforeEach(function() {
4
+ env = new jasmine.Env();
5
+ env.updateInterval = 0;
6
+ suite = new jasmine.Suite(env, 'suite 1');
7
+ timeout = 1000;
8
+ spec = new jasmine.Spec(env, suite);
9
+ message = "some error message";
10
+ onComplete = jasmine.createSpy("onComplete");
11
+ });
12
+
13
+ describe("jasmine.VERBOSE", function() {
14
+ var jasmineVerboseOriginal;
15
+ beforeEach(function() {
16
+ jasmineVerboseOriginal = jasmine.VERBOSE;
17
+ spyOn(env.reporter, 'log');
18
+
19
+ });
20
+ it('do not show information if jasmine.VERBOSE is set to false', function () {
21
+ jasmine.VERBOSE = false;
22
+ var latchFunction = function() {
23
+ return true;
24
+ };
25
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
26
+ expect(env.reporter.log).not.toHaveBeenCalled();
27
+ block.execute(onComplete);
28
+ expect(env.reporter.log).not.toHaveBeenCalled();
29
+ jasmine.VERBOSE = jasmineVerboseOriginal;
30
+ });
31
+ it('show information if jasmine.VERBOSE is set to true', function () {
32
+ jasmine.VERBOSE = true;
33
+ var latchFunction = function() {
34
+ return true;
35
+ };
36
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
37
+ expect(env.reporter.log).not.toHaveBeenCalled();
38
+ block.execute(onComplete);
39
+ expect(env.reporter.log).toHaveBeenCalled();
40
+ jasmine.VERBOSE = jasmineVerboseOriginal;
41
+ });
42
+ });
43
+
44
+ it('onComplete should be called if the latchFunction returns true', function () {
45
+ var latchFunction = function() {
46
+ return true;
47
+ };
48
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
49
+ expect(onComplete).not.toHaveBeenCalled();
50
+ block.execute(onComplete);
51
+ expect(onComplete).toHaveBeenCalled();
52
+ });
53
+
54
+ it('latchFunction should run in same scope as spec', function () {
55
+ var result;
56
+ var latchFunction = function() {
57
+ result = this.scopedValue;
58
+ };
59
+ spec.scopedValue = 'foo';
60
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
61
+ block.execute(onComplete);
62
+ expect(result).toEqual('foo');
63
+ });
64
+
65
+ it('should fail spec and call onComplete if there is an error in the latchFunction', function() {
66
+ var latchFunction = jasmine.createSpy('latchFunction').andThrow('some error');
67
+ spyOn(spec, 'fail');
68
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
69
+ block.execute(onComplete);
70
+ expect(spec.fail).toHaveBeenCalledWith('some error');
71
+ expect(onComplete).toHaveBeenCalled();
72
+ });
73
+
74
+ describe("if latchFunction returns false", function() {
75
+ var latchFunction, fakeTimer;
76
+ beforeEach(function() {
77
+ latchFunction = jasmine.createSpy('latchFunction').andReturn(false);
78
+ fakeTimer = new jasmine.FakeTimer();
79
+ env.setTimeout = fakeTimer.setTimeout;
80
+ env.clearTimeout = fakeTimer.clearTimeout;
81
+ env.setInterval = fakeTimer.setInterval;
82
+ env.clearInterval = fakeTimer.clearInterval;
83
+ });
84
+
85
+ it('latchFunction should be retried after 10 ms', function () {
86
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
87
+ expect(latchFunction).not.toHaveBeenCalled();
88
+ block.execute(onComplete);
89
+ expect(latchFunction.callCount).toEqual(1);
90
+ fakeTimer.tick(5);
91
+ expect(latchFunction.callCount).toEqual(1);
92
+ fakeTimer.tick(5);
93
+ expect(latchFunction.callCount).toEqual(2);
94
+ });
95
+
96
+ it('onComplete should be called if latchFunction returns true before timeout', function () {
97
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
98
+ expect(onComplete).not.toHaveBeenCalled();
99
+ block.execute(onComplete);
100
+ expect(onComplete).not.toHaveBeenCalled();
101
+ latchFunction.andReturn(true);
102
+ fakeTimer.tick(100);
103
+ expect(onComplete).toHaveBeenCalled();
104
+ });
105
+
106
+ it('spec should fail with the passed message if the timeout is reached (and not call onComplete)', function () {
107
+ spyOn(spec, 'fail');
108
+ var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
109
+ block.execute(onComplete);
110
+ expect(spec.fail).not.toHaveBeenCalled();
111
+ fakeTimer.tick(timeout);
112
+ expect(spec.fail).toHaveBeenCalled();
113
+ var failMessage = spec.fail.mostRecentCall.args[0].message;
114
+ expect(failMessage).toMatch(message);
115
+ expect(onComplete).toHaveBeenCalled();
116
+ });
117
+ });
118
+ });
@@ -0,0 +1,38 @@
1
+ describe("MatchersSpec - HTML Dependent", function () {
2
+ var env, spec;
3
+
4
+ beforeEach(function() {
5
+ env = new jasmine.Env();
6
+ env.updateInterval = 0;
7
+
8
+ var suite = env.describe("suite", function() {
9
+ spec = env.it("spec", function() {
10
+ });
11
+ });
12
+ spyOn(spec, 'addMatcherResult');
13
+
14
+ this.addMatchers({
15
+ toPass: function() {
16
+ return lastResult().passed();
17
+ },
18
+ toFail: function() {
19
+ return !lastResult().passed();
20
+ }
21
+ });
22
+ });
23
+
24
+ function match(value) {
25
+ return spec.expect(value);
26
+ }
27
+
28
+ function lastResult() {
29
+ return spec.addMatcherResult.mostRecentCall.args[0];
30
+ }
31
+
32
+ it("toEqual with DOM nodes", function() {
33
+ var nodeA = document.createElement('div');
34
+ var nodeB = document.createElement('div');
35
+ expect((match(nodeA).toEqual(nodeA))).toPass();
36
+ expect((match(nodeA).toEqual(nodeB))).toFail();
37
+ });
38
+ });
@@ -0,0 +1,8 @@
1
+ describe("jasmine.pp (HTML Dependent)", function () {
2
+ it("should stringify HTML nodes properly", function() {
3
+ var sampleNode = document.createElement('div');
4
+ sampleNode.innerHTML = 'foo<b>bar</b>';
5
+ expect(jasmine.pp(sampleNode)).toEqual("HTMLNode");
6
+ expect(jasmine.pp({foo: sampleNode})).toEqual("{ foo : HTMLNode }");
7
+ });
8
+ });
@@ -0,0 +1,239 @@
1
+ describe("TrivialReporter", function() {
2
+ var env;
3
+ var trivialReporter;
4
+ var body;
5
+ var fakeDocument;
6
+
7
+ beforeEach(function() {
8
+ env = new jasmine.Env();
9
+ env.updateInterval = 0;
10
+
11
+ body = document.createElement("body");
12
+ fakeDocument = { body: body, location: { search: "" } };
13
+ trivialReporter = new jasmine.TrivialReporter(fakeDocument);
14
+ });
15
+
16
+ function fakeSpec(name) {
17
+ return {
18
+ getFullName: function() {
19
+ return name;
20
+ }
21
+ };
22
+ }
23
+
24
+ function findElements(divs, withClass) {
25
+ var els = [];
26
+ for (var i = 0; i < divs.length; i++) {
27
+ if (divs[i].className == withClass) els.push(divs[i]);
28
+ }
29
+ return els;
30
+ }
31
+
32
+ function findElement(divs, withClass) {
33
+ var els = findElements(divs, withClass);
34
+ if (els.length > 0) {
35
+ return els[0];
36
+ }
37
+ throw new Error("couldn't find div with class " + withClass);
38
+ }
39
+
40
+ it("should run only specs beginning with spec parameter", function() {
41
+ fakeDocument.location.search = "?spec=run%20this";
42
+ expect(trivialReporter.specFilter(fakeSpec("run this"))).toBeTruthy();
43
+ expect(trivialReporter.specFilter(fakeSpec("not the right spec"))).toBeFalsy();
44
+ expect(trivialReporter.specFilter(fakeSpec("not run this"))).toBeFalsy();
45
+ });
46
+
47
+ it("should display empty divs for every suite when the runner is starting", function() {
48
+ trivialReporter.reportRunnerStarting({
49
+ env: env,
50
+ suites: function() {
51
+ return [ new jasmine.Suite({}, "suite 1", null, null) ];
52
+ }
53
+ });
54
+
55
+ var divs = findElements(body.getElementsByTagName("div"), "suite");
56
+ expect(divs.length).toEqual(1);
57
+ expect(divs[0].innerHTML).toContain("suite 1");
58
+ });
59
+
60
+ describe('Matcher reporting', function () {
61
+ var getResultMessageDiv = function (body) {
62
+ var divs = body.getElementsByTagName("div");
63
+ for (var i = 0; i < divs.length; i++) {
64
+ if (divs[i].className.match(/resultMessage/)) {
65
+ return divs[i];
66
+ }
67
+ }
68
+ };
69
+
70
+ var runner, spec, fakeTimer;
71
+ beforeEach(function () {
72
+ fakeTimer = new jasmine.FakeTimer();
73
+ env.setTimeout = fakeTimer.setTimeout;
74
+ env.clearTimeout = fakeTimer.clearTimeout;
75
+ env.setInterval = fakeTimer.setInterval;
76
+ env.clearInterval = fakeTimer.clearInterval;
77
+ runner = env.currentRunner();
78
+ var suite = new jasmine.Suite(env, 'some suite');
79
+ runner.add(suite);
80
+ spec = new jasmine.Spec(env, suite, 'some spec');
81
+ suite.add(spec);
82
+ fakeDocument.location.search = "?";
83
+ env.addReporter(trivialReporter);
84
+ });
85
+
86
+ describe('toContain', function () {
87
+ it('should show actual and expected', function () {
88
+ spec.runs(function () {
89
+ this.expect('foo').toContain('bar');
90
+ });
91
+ runner.execute();
92
+ fakeTimer.tick(0);
93
+
94
+ var resultEl = getResultMessageDiv(body);
95
+ expect(resultEl.innerHTML).toMatch(/foo/);
96
+ expect(resultEl.innerHTML).toMatch(/bar/);
97
+ });
98
+ });
99
+ });
100
+
101
+ describe("failure messages (integration)", function () {
102
+ var spec, results, expectationResult;
103
+
104
+ beforeEach(function() {
105
+ results = {
106
+ passed: function() {
107
+ return false;
108
+ },
109
+ getItems: function() {
110
+ }};
111
+
112
+ var suite1 = new jasmine.Suite(env, "suite 1", null, null);
113
+
114
+ spec = {
115
+ suite: suite1,
116
+ getFullName: function() {
117
+ return "foo";
118
+ },
119
+ results: function() {
120
+ return results;
121
+ }
122
+ };
123
+
124
+ trivialReporter.reportRunnerStarting({
125
+ env: env,
126
+ suites: function() {
127
+ return [ suite1 ];
128
+ }
129
+ });
130
+ });
131
+
132
+ it("should add the failure message to the DOM (non-toEquals matchers)", function() {
133
+ expectationResult = new jasmine.ExpectationResult({
134
+ matcherName: "toBeNull", passed: false, message: "Expected 'a' to be null, but it was not"
135
+ });
136
+
137
+ spyOn(results, 'getItems').andReturn([expectationResult]);
138
+
139
+ trivialReporter.reportSpecResults(spec);
140
+
141
+ var divs = body.getElementsByTagName("div");
142
+ var errorDiv = findElement(divs, 'resultMessage fail');
143
+ expect(errorDiv.innerHTML).toEqual("Expected 'a' to be null, but it was not");
144
+ });
145
+
146
+ it("should add the failure message to the DOM (non-toEquals matchers) html escaping", function() {
147
+ expectationResult = new jasmine.ExpectationResult({
148
+ matcherName: "toBeNull", passed: false, message: "Expected '1 < 2' to <b>e null, & it was not"
149
+ });
150
+
151
+ spyOn(results, 'getItems').andReturn([expectationResult]);
152
+
153
+ trivialReporter.reportSpecResults(spec);
154
+
155
+ var divs = body.getElementsByTagName("div");
156
+ var errorDiv = findElement(divs, 'resultMessage fail');
157
+ expect(errorDiv.innerHTML).toEqual("Expected '1 &lt; 2' to &lt;b&gt;e null, &amp; it was not");
158
+ });
159
+ });
160
+
161
+ describe("log messages", function() {
162
+ it("should appear in the report", function() {
163
+ env.describe("suite", function() {
164
+ env.it("will have log messages", function() {
165
+ this.log("this is a", "multipart log message");
166
+ });
167
+ });
168
+
169
+ env.addReporter(trivialReporter);
170
+ env.execute();
171
+
172
+ var divs = body.getElementsByTagName("div");
173
+ var errorDiv = findElement(divs, 'resultMessage log');
174
+ expect(errorDiv.innerHTML).toEqual("this is a multipart log message");
175
+ });
176
+
177
+ xit("should work on IE without console.log.apply", function() {
178
+ });
179
+ });
180
+
181
+ describe("duplicate example names", function() {
182
+ it("should report failures correctly", function() {
183
+ var suite1 = env.describe("suite", function() {
184
+ env.it("will have log messages", function() {
185
+ this.log("this one fails!");
186
+ this.expect(true).toBeFalsy();
187
+ });
188
+ });
189
+
190
+ var suite2 = env.describe("suite", function() {
191
+ env.it("will have log messages", function() {
192
+ this.log("this one passes!");
193
+ this.expect(true).toBeTruthy();
194
+ });
195
+ });
196
+
197
+ env.addReporter(trivialReporter);
198
+ env.execute();
199
+
200
+ var divs = body.getElementsByTagName("div");
201
+ var passedSpecDiv = findElement(divs, 'suite passed');
202
+ expect(passedSpecDiv.className).toEqual('suite passed');
203
+ expect(passedSpecDiv.innerHTML).toContain("this one passes!");
204
+ expect(passedSpecDiv.innerHTML).not.toContain("this one fails!");
205
+
206
+ var failedSpecDiv = findElement(divs, 'suite failed');
207
+ expect(failedSpecDiv.className).toEqual('suite failed');
208
+ expect(failedSpecDiv.innerHTML).toContain("this one fails!");
209
+ expect(failedSpecDiv.innerHTML).not.toContain("this one passes!");
210
+ });
211
+ });
212
+
213
+ describe('#reportSpecStarting', function() {
214
+ var spec1;
215
+ beforeEach(function () {
216
+ env.describe("suite 1", function() {
217
+ spec1 = env.it("spec 1", function() {
218
+ });
219
+ });
220
+ });
221
+
222
+ it('DOES NOT log running specs by default', function() {
223
+ spyOn(trivialReporter, 'log');
224
+
225
+ trivialReporter.reportSpecStarting(spec1);
226
+
227
+ expect(trivialReporter.log).not.toHaveBeenCalled();
228
+ });
229
+
230
+ it('logs running specs when log_running_specs is true', function() {
231
+ trivialReporter.logRunningSpecs = true;
232
+ spyOn(trivialReporter, 'log');
233
+
234
+ trivialReporter.reportSpecStarting(spec1);
235
+
236
+ expect(trivialReporter.log).toHaveBeenCalledWith('>> Jasmine Running suite 1 spec 1...');
237
+ });
238
+ });
239
+ });
@@ -0,0 +1,127 @@
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
+
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
26
+ };
27
+
28
+ delete global.window;
29
+
30
+ function noop() {
31
+ }
32
+
33
+ jasmine.executeSpecs = function(specs, done, isVerbose, showColors) {
34
+ for (var i = 0, len = specs.length; i < len; ++i) {
35
+ var filename = specs[i];
36
+ require(filename.replace(/\.\w+$/, ""));
37
+ }
38
+
39
+ var jasmineEnv = jasmine.getEnv();
40
+ var consoleReporter = new jasmine.ConsoleReporter(sys.print, done, showColors);
41
+
42
+ jasmineEnv.addReporter(consoleReporter);
43
+ jasmineEnv.execute();
44
+ };
45
+
46
+ jasmine.getAllSpecFiles = function(dir, matcher) {
47
+ var specs = [];
48
+
49
+ if (fs.statSync(dir).isFile() && dir.match(matcher)) {
50
+ specs.push(dir);
51
+ } else {
52
+ var files = fs.readdirSync(dir);
53
+ for (var i = 0, len = files.length; i < len; ++i) {
54
+ var filename = dir + '/' + files[i];
55
+ if (fs.statSync(filename).isFile() && filename.match(matcher)) {
56
+ specs.push(filename);
57
+ } else if (fs.statSync(filename).isDirectory()) {
58
+ var subfiles = this.getAllSpecFiles(filename, matcher);
59
+ subfiles.forEach(function(result) {
60
+ specs.push(result);
61
+ });
62
+ }
63
+ }
64
+ }
65
+
66
+ return specs;
67
+ };
68
+
69
+ function now() {
70
+ return new Date().getTime();
71
+ }
72
+
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
+ };
94
+
95
+ for (var key in jasmine) {
96
+ exports[key] = jasmine[key];
97
+ }
98
+
99
+ /*
100
+ End jasmine-node runner
101
+ */
102
+
103
+ var isVerbose = false;
104
+ var showColors = true;
105
+ process.argv.forEach(function(arg) {
106
+ switch (arg) {
107
+ case '--color': showColors = true; break;
108
+ case '--noColor': showColors = false; break;
109
+ case '--verbose': isVerbose = true; break;
110
+ }
111
+ });
112
+
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
+ }
119
+ }
120
+
121
+ jasmine.executeSpecs(domIndependentSpecs, function(runner, log) {
122
+ if (runner.results().failedCount === 0) {
123
+ process.exit(0);
124
+ } else {
125
+ process.exit(1);
126
+ }
127
+ }, isVerbose, showColors);