rally-jasmine-core 1.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/lib/jasmine-core.rb +36 -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 +681 -0
  8. data/lib/jasmine-core/jasmine.css +82 -0
  9. data/lib/jasmine-core/jasmine.js +2568 -0
  10. data/lib/jasmine-core/json2.js +478 -0
  11. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +451 -0
  12. data/lib/jasmine-core/spec/core/BaseSpec.js +27 -0
  13. data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +97 -0
  14. data/lib/jasmine-core/spec/core/EnvSpec.js +159 -0
  15. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +175 -0
  16. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +103 -0
  17. data/lib/jasmine-core/spec/core/MatchersSpec.js +1145 -0
  18. data/lib/jasmine-core/spec/core/MockClockSpec.js +38 -0
  19. data/lib/jasmine-core/spec/core/MultiReporterSpec.js +45 -0
  20. data/lib/jasmine-core/spec/core/NestedResultsSpec.js +54 -0
  21. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +94 -0
  22. data/lib/jasmine-core/spec/core/QueueSpec.js +23 -0
  23. data/lib/jasmine-core/spec/core/ReporterSpec.js +56 -0
  24. data/lib/jasmine-core/spec/core/RunnerSpec.js +280 -0
  25. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +1291 -0
  26. data/lib/jasmine-core/spec/core/SpecSpec.js +124 -0
  27. data/lib/jasmine-core/spec/core/SpySpec.js +216 -0
  28. data/lib/jasmine-core/spec/core/SuiteSpec.js +120 -0
  29. data/lib/jasmine-core/spec/core/UtilSpec.js +39 -0
  30. data/lib/jasmine-core/spec/core/WaitsForBlockSpec.js +118 -0
  31. data/lib/jasmine-core/spec/html/HTMLReporterSpec.js +209 -0
  32. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +38 -0
  33. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +8 -0
  34. data/lib/jasmine-core/spec/html/TrivialReporterSpec.js +239 -0
  35. data/lib/jasmine-core/spec/node_suite.js +127 -0
  36. data/lib/jasmine-core/version.rb +6 -0
  37. metadata +288 -0
@@ -0,0 +1,97 @@
1
+ describe("Custom Matchers", function() {
2
+ var env;
3
+ var fakeTimer;
4
+
5
+ beforeEach(function() {
6
+ env = new jasmine.Env();
7
+ env.updateInterval = 0;
8
+ });
9
+
10
+ it("should be easy to add more matchers local to a spec, suite, etc.", function() {
11
+ var spec1, spec2, spec1Matcher, spec2Matcher;
12
+ var suite = env.describe('some suite', function() {
13
+ env.beforeEach(function() {
14
+ this.addMatchers({
15
+ matcherForSuite: function(expected) {
16
+ this.message = "matcherForSuite: actual: " + this.actual + "; expected: " + expected;
17
+ return true;
18
+ }
19
+ });
20
+ });
21
+
22
+ spec1 = env.it('spec with an expectation').runs(function () {
23
+ this.addMatchers({
24
+ matcherForSpec: function(expected) {
25
+ this.message = "matcherForSpec: actual: " + this.actual + "; expected: " + expected;
26
+ return true;
27
+ }
28
+ });
29
+ spec1Matcher = this.expect("xxx");
30
+ });
31
+
32
+ spec2 = env.it('spec with failing expectation').runs(function () {
33
+ spec2Matcher = this.expect("yyy");
34
+ });
35
+ });
36
+
37
+ suite.execute();
38
+
39
+ spec1Matcher.matcherForSuite("expected");
40
+ expect(spec1Matcher.message).toEqual("matcherForSuite: actual: xxx; expected: expected");
41
+ spec1Matcher.matcherForSpec("expected");
42
+ expect(spec1Matcher.message).toEqual("matcherForSpec: actual: xxx; expected: expected");
43
+
44
+ spec2Matcher.matcherForSuite("expected");
45
+ expect(spec2Matcher.message).toEqual("matcherForSuite: actual: yyy; expected: expected");
46
+ expect(spec2Matcher.matcherForSpec).toBe(jasmine.undefined);
47
+ });
48
+
49
+ it("should generate messages with the same rules as for regular matchers when this.report() is not called", function() {
50
+ var spec;
51
+ var suite = env.describe('some suite', function() {
52
+ spec = env.it('spec with an expectation').runs(function () {
53
+ this.addMatchers({
54
+ toBeTrue: function() {
55
+ return this.actual === true;
56
+ }
57
+ });
58
+ this.expect(true).toBeTrue();
59
+ this.expect(false).toBeTrue();
60
+ });
61
+ });
62
+
63
+ suite.execute();
64
+ var passResult = new jasmine.ExpectationResult({passed: true, matcherName: 'toBeTrue',
65
+ actual: true, expected: jasmine.undefined, message: "Passed." });
66
+ var failResult = new jasmine.ExpectationResult({passed: false, matcherName: 'toBeTrue',
67
+ actual: false, expected: jasmine.undefined, message: "Expected false to be true." });
68
+ failResult.trace = jasmine.any(Object);
69
+ expect(spec.results().getItems()).toEqual([passResult, failResult]);
70
+ });
71
+
72
+ it("should pass args", function() {
73
+ var matcherCallArgs = [];
74
+ var spec;
75
+ var suite = env.describe('some suite', function() {
76
+ spec = env.it('spec with an expectation').runs(function () {
77
+ this.addMatchers({
78
+ toBeTrue: function() {
79
+ matcherCallArgs.push(jasmine.util.argsToArray(arguments));
80
+ return this.actual === true;
81
+ }
82
+ });
83
+ this.expect(true).toBeTrue();
84
+ this.expect(false).toBeTrue('arg');
85
+ this.expect(true).toBeTrue('arg1', 'arg2');
86
+ });
87
+ });
88
+
89
+ suite.execute();
90
+ var results = spec.results().getItems();
91
+ expect(results[0].expected).toEqual(jasmine.undefined);
92
+ expect(results[1].expected).toEqual('arg');
93
+ expect(results[2].expected).toEqual(['arg1', 'arg2']);
94
+
95
+ expect(matcherCallArgs).toEqual([[], ['arg'], ['arg1', 'arg2']]);
96
+ });
97
+ });
@@ -0,0 +1,159 @@
1
+ describe("jasmine.Env", function() {
2
+ var env;
3
+ beforeEach(function() {
4
+ env = new jasmine.Env();
5
+ env.updateInterval = 0;
6
+ });
7
+
8
+ describe('ids', function () {
9
+ it('nextSpecId should return consecutive integers, starting at 0', function () {
10
+ expect(env.nextSpecId()).toEqual(0);
11
+ expect(env.nextSpecId()).toEqual(1);
12
+ expect(env.nextSpecId()).toEqual(2);
13
+ });
14
+ });
15
+
16
+ describe("reporting", function() {
17
+ var fakeReporter;
18
+
19
+ beforeEach(function() {
20
+ fakeReporter = jasmine.createSpyObj("fakeReporter", ["log"]);
21
+ });
22
+
23
+ describe('version', function () {
24
+ var oldVersion;
25
+
26
+ beforeEach(function () {
27
+ oldVersion = jasmine.version_;
28
+ });
29
+
30
+ afterEach(function () {
31
+ jasmine.version_ = oldVersion;
32
+ });
33
+
34
+ it('should raise an error if version is not set', function () {
35
+ jasmine.version_ = null;
36
+ var exception;
37
+ try {
38
+ env.version();
39
+ }
40
+ catch (e) {
41
+ exception = e;
42
+ }
43
+ expect(exception.message).toEqual('Version not set');
44
+ });
45
+
46
+ it("version should return the current version as an int", function() {
47
+ jasmine.version_ = {
48
+ "major": 1,
49
+ "minor": 9,
50
+ "build": 7,
51
+ "revision": 8
52
+ };
53
+ expect(env.version()).toEqual({
54
+ "major": 1,
55
+ "minor": 9,
56
+ "build": 7,
57
+ "revision": 8
58
+ });
59
+ });
60
+
61
+ describe("versionString", function() {
62
+ it("should return a stringified version number", function() {
63
+ jasmine.version_ = {
64
+ "major": 1,
65
+ "minor": 9,
66
+ "build": 7,
67
+ "release_candidate": "1",
68
+ "revision": 8
69
+ };
70
+ expect(env.versionString()).toEqual("1.9.7.rc1 revision 8");
71
+ });
72
+
73
+ it("should return a nice string when version is unknown", function() {
74
+ jasmine.version_ = null;
75
+ expect(env.versionString()).toEqual("version unknown");
76
+ });
77
+ });
78
+ });
79
+
80
+ it("should allow reporters to be registered", function() {
81
+ env.addReporter(fakeReporter);
82
+ env.reporter.log("message");
83
+ expect(fakeReporter.log).toHaveBeenCalledWith("message");
84
+ });
85
+ });
86
+
87
+ describe("equality testing", function() {
88
+ describe("with custom equality testers", function() {
89
+ var aObj, bObj, isEqual;
90
+
91
+ beforeEach(function() {
92
+ env.addEqualityTester(function(a, b) {
93
+ aObj = a;
94
+ bObj = b;
95
+ return isEqual;
96
+ });
97
+ });
98
+
99
+ it("should call the custom equality tester with two objects for comparison", function() {
100
+ env.equals_("1", "2");
101
+ expect(aObj).toEqual("1");
102
+ expect(bObj).toEqual("2");
103
+ });
104
+
105
+ describe("when the custom equality tester returns false", function() {
106
+ beforeEach(function() {
107
+ isEqual = false;
108
+ });
109
+
110
+ it("should give custom equality testers precedence", function() {
111
+ expect(env.equals_('abc', 'abc')).toBeFalsy();
112
+ var o = {};
113
+ expect(env.equals_(o, o)).toBeFalsy();
114
+ });
115
+ });
116
+
117
+
118
+ describe("when the custom equality tester returns true", function() {
119
+ beforeEach(function() {
120
+ isEqual = true;
121
+ });
122
+
123
+ it("should give custom equality testers precedence", function() {
124
+ expect(env.equals_('abc', 'def')).toBeTruthy();
125
+ expect(env.equals_(true, false)).toBeTruthy();
126
+ });
127
+ });
128
+
129
+ describe("when the custom equality tester returns undefined", function() {
130
+ beforeEach(function() {
131
+ isEqual = jasmine.undefined;
132
+ });
133
+
134
+ it("should use normal equality rules", function() {
135
+ expect(env.equals_('abc', 'abc')).toBeTruthy();
136
+ expect(env.equals_('abc', 'def')).toBeFalsy();
137
+ });
138
+
139
+ describe("even if there are several", function() {
140
+ beforeEach(function() {
141
+ env.addEqualityTester(function(a, b) { return jasmine.undefined; });
142
+ env.addEqualityTester(function(a, b) { return jasmine.undefined; });
143
+ });
144
+
145
+ it("should use normal equality rules", function() {
146
+ expect(env.equals_('abc', 'abc')).toBeTruthy();
147
+ expect(env.equals_('abc', 'def')).toBeFalsy();
148
+ });
149
+ });
150
+ });
151
+
152
+ it("should evaluate custom equality testers in the order they are declared", function() {
153
+ isEqual = false;
154
+ env.addEqualityTester(function(a, b) { return true; });
155
+ expect(env.equals_('abc', 'abc')).toBeFalsy();
156
+ });
157
+ });
158
+ });
159
+ });
@@ -0,0 +1,175 @@
1
+ describe('Exceptions:', function() {
2
+ var env;
3
+
4
+ beforeEach(function() {
5
+ env = new jasmine.Env();
6
+ env.updateInterval = 0;
7
+ });
8
+
9
+ it('jasmine.formatException formats Firefox exception messages as expected', function() {
10
+ var sampleFirefoxException = {
11
+ fileName: 'foo.js',
12
+ line: '1978',
13
+ message: 'you got your foo in my bar',
14
+ name: 'A Classic Mistake'
15
+ };
16
+
17
+ var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)';
18
+
19
+ expect(jasmine.util.formatException(sampleFirefoxException)).toEqual(expected);
20
+ });
21
+
22
+ it('jasmine.formatException formats Webkit exception messages as expected', function() {
23
+ var sampleWebkitException = {
24
+ sourceURL: 'foo.js',
25
+ lineNumber: '1978',
26
+ message: 'you got your foo in my bar',
27
+ name: 'A Classic Mistake'
28
+ };
29
+
30
+ var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)';
31
+
32
+ expect(jasmine.util.formatException(sampleWebkitException)).toEqual(expected);
33
+ });
34
+
35
+ describe('with break on exception', function() {
36
+ it('should not catch the exception', function() {
37
+ var suite = env.describe('suite for break on exceptions', function() {
38
+ env.it('should break when an exception is thrown', function() {
39
+ throw new Error('I should hit a breakpoint!');
40
+ });
41
+ });
42
+ var runner = env.currentRunner();
43
+ var dont_change = 'I will never change!';
44
+
45
+ var oldCatch = jasmine.CATCH_EXCEPTIONS;
46
+ jasmine.CATCH_EXCEPTIONS = false;
47
+ try {
48
+ suite.execute();
49
+ dont_change = 'oops I changed';
50
+ }
51
+ catch (e) {}
52
+ finally {
53
+ jasmine.CATCH_EXCEPTIONS = oldCatch;
54
+ }
55
+
56
+ expect(dont_change).toEqual('I will never change!');
57
+ });
58
+ });
59
+
60
+ describe("with catch on exception", function() {
61
+ it('should handle exceptions thrown, but continue', function() {
62
+ var fakeTimer = new jasmine.FakeTimer();
63
+ env.setTimeout = fakeTimer.setTimeout;
64
+ env.clearTimeout = fakeTimer.clearTimeout;
65
+ env.setInterval = fakeTimer.setInterval;
66
+ env.clearInterval = fakeTimer.clearInterval;
67
+
68
+ //we run two exception tests to make sure we continue after throwing an exception
69
+ var suite = env.describe('Suite for handles exceptions', function () {
70
+ env.it('should be a test that fails because it throws an exception', function() {
71
+ throw new Error('fake error 1');
72
+ });
73
+
74
+ env.it('should be another test that fails because it throws an exception', function() {
75
+ this.runs(function () {
76
+ throw new Error('fake error 2');
77
+ });
78
+ this.runs(function () {
79
+ this.expect(true).toEqual(true);
80
+ });
81
+ });
82
+
83
+ env.it('should be a passing test that runs after exceptions are thrown', function() {
84
+ this.expect(true).toEqual(true);
85
+ });
86
+
87
+ env.it('should be another test that fails because it throws an exception after a wait', function() {
88
+ this.runs(function () {
89
+ var foo = 'foo';
90
+ });
91
+ this.waits(250);
92
+ this.runs(function () {
93
+ throw new Error('fake error 3');
94
+ });
95
+ });
96
+
97
+ env.it('should be a passing test that runs after exceptions are thrown from a async test', function() {
98
+ this.expect(true).toEqual(true);
99
+ });
100
+ });
101
+
102
+ var runner = env.currentRunner();
103
+ suite.execute();
104
+ fakeTimer.tick(2500);
105
+
106
+ var suiteResults = suite.results();
107
+ var specResults = suiteResults.getItems();
108
+
109
+ expect(suiteResults.passed()).toEqual(false);
110
+ //
111
+ expect(specResults.length).toEqual(5);
112
+ expect(specResults[0].passed()).toMatch(false);
113
+ var blockResults = specResults[0].getItems();
114
+ expect(blockResults[0].passed()).toEqual(false);
115
+ expect(blockResults[0].message).toMatch(/fake error 1/);
116
+
117
+ expect(specResults[1].passed()).toEqual(false);
118
+ blockResults = specResults[1].getItems();
119
+ expect(blockResults[0].passed()).toEqual(false);
120
+ expect(blockResults[0].message).toMatch(/fake error 2/);
121
+ expect(blockResults[1].passed()).toEqual(true);
122
+
123
+ expect(specResults[2].passed()).toEqual(true);
124
+
125
+ expect(specResults[3].passed()).toEqual(false);
126
+ blockResults = specResults[3].getItems();
127
+ expect(blockResults[0].message).toMatch(/fake error 3/);
128
+
129
+ expect(specResults[4].passed()).toEqual(true);
130
+ });
131
+
132
+ it("should handle exceptions thrown directly in top-level describe blocks and continue", function () {
133
+ var suite = env.describe("a top level describe block that throws an exception", function () {
134
+ env.it("is a test that should pass", function () {
135
+ this.expect(true).toEqual(true);
136
+ });
137
+
138
+ throw new Error("top level error");
139
+ });
140
+
141
+ suite.execute();
142
+ var suiteResults = suite.results();
143
+ var specResults = suiteResults.getItems();
144
+
145
+ expect(suiteResults.passed()).toEqual(false);
146
+ expect(specResults.length).toEqual(2);
147
+
148
+ expect(specResults[1].description).toMatch(/encountered a declaration exception/);
149
+ });
150
+
151
+ it("should handle exceptions thrown directly in nested describe blocks and continue", function () {
152
+ var suite = env.describe("a top level describe", function () {
153
+ env.describe("a mid-level describe that throws an exception", function () {
154
+ env.it("is a test that should pass", function () {
155
+ this.expect(true).toEqual(true);
156
+ });
157
+
158
+ throw new Error("a mid-level error");
159
+ });
160
+ });
161
+
162
+ suite.execute();
163
+ var suiteResults = suite.results();
164
+ var specResults = suiteResults.getItems();
165
+
166
+ expect(suiteResults.passed()).toEqual(false);
167
+ expect(specResults.length).toEqual(1);
168
+
169
+ var nestedSpecResults = specResults[0].getItems();
170
+
171
+ expect(nestedSpecResults.length).toEqual(2);
172
+ expect(nestedSpecResults[1].description).toMatch(/encountered a declaration exception/);
173
+ });
174
+ });
175
+ });
@@ -0,0 +1,103 @@
1
+ describe('jasmine.jsApiReporter', function() {
2
+ describe('results', function () {
3
+ var reporter, spec1, spec2, spec3, expectedSpec1Results, expectedSpec2Results;
4
+ var env;
5
+ var suite, nestedSuite, nestedSpec;
6
+
7
+ beforeEach(function() {
8
+ env = new jasmine.Env();
9
+ env.updateInterval = 0;
10
+
11
+ suite = env.describe("top-level suite", function() {
12
+ spec1 = env.it("spec 1", function() {
13
+ this.expect(true).toEqual(true);
14
+
15
+ });
16
+
17
+ spec2 = env.it("spec 2", function() {
18
+ this.expect(true).toEqual(false);
19
+ });
20
+
21
+ nestedSuite = env.describe("nested suite", function() {
22
+ nestedSpec = env.it("nested spec", function() {
23
+ expect(true).toEqual(true);
24
+ });
25
+ });
26
+
27
+ spec3 = env.it("spec 3", function() {
28
+ this.log('some debug message');
29
+ });
30
+ });
31
+
32
+ reporter = new jasmine.JsApiReporter();
33
+ env.addReporter(reporter);
34
+
35
+ env.execute();
36
+
37
+ expectedSpec1Results = {
38
+ messages: spec1.results().getItems(),
39
+ result: "passed"
40
+ };
41
+ expectedSpec2Results = {
42
+ messages: spec2.results().getItems(),
43
+ result: "failed"
44
+ };
45
+ });
46
+
47
+ it('resultForSpec() should return the result for the given spec', function () {
48
+ expect(reporter.resultsForSpec(spec1.id)).toEqual(expectedSpec1Results);
49
+ expect(reporter.resultsForSpec(spec2.id)).toEqual(expectedSpec2Results);
50
+ });
51
+
52
+ it('results() should return a hash of all results, indexed by spec id', function () {
53
+ expect(reporter.results()[spec1.id]).toEqual(expectedSpec1Results);
54
+ expect(reporter.results()[spec2.id]).toEqual(expectedSpec2Results);
55
+ });
56
+
57
+ it("should return nested suites as children of their parents", function() {
58
+ expect(reporter.suites()).toEqual([
59
+ { id: 0, name: 'top-level suite', type: 'suite',
60
+ children: [
61
+ { id: 0, name: 'spec 1', type: 'spec', children: [ ] },
62
+ { id: 1, name: 'spec 2', type: 'spec', children: [ ] },
63
+ { id: 1, name: 'nested suite', type: 'suite',
64
+ children: [
65
+ { id: 2, name: 'nested spec', type: 'spec', children: [ ] }
66
+ ]
67
+ },
68
+ { id: 3, name: 'spec 3', type: 'spec', children: [ ] }
69
+ ]
70
+ }
71
+ ]);
72
+ });
73
+
74
+ describe("#summarizeResult_", function() {
75
+ it("should summarize a passing result", function() {
76
+ var result = reporter.results()[spec1.id];
77
+ var summarizedResult = reporter.summarizeResult_(result);
78
+ expect(summarizedResult.result).toEqual('passed');
79
+ expect(summarizedResult.messages.length).toEqual(1);
80
+ expect(summarizedResult.messages[0].message).toEqual(result.messages[0].message);
81
+ expect(summarizedResult.messages[0].passed).toBeTruthy();
82
+ expect(summarizedResult.messages[0].type).toEqual('expect');
83
+ expect(summarizedResult.messages[0].text).toBeUndefined();
84
+ expect(summarizedResult.messages[0].trace.stack).toBeUndefined();
85
+ });
86
+
87
+ it("should have a stack trace for failing specs", function() {
88
+ var result = reporter.results()[spec2.id];
89
+ var summarizedResult = reporter.summarizeResult_(result);
90
+ expect(summarizedResult.result).toEqual('failed');
91
+ expect(summarizedResult.messages[0].trace.stack).toEqual(result.messages[0].trace.stack);
92
+ });
93
+
94
+ it("should have messages for specs with messages", function() {
95
+ var result = reporter.results()[spec3.id];
96
+ var summarizedResult = reporter.summarizeResult_(result);
97
+ expect(summarizedResult.result).toEqual('passed');
98
+ expect(summarizedResult.messages[0].type).toEqual('log');
99
+ expect(summarizedResult.messages[0].text).toEqual('some debug message');
100
+ });
101
+ });
102
+ });
103
+ });