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,101 @@
1
+ describe("SpyStrategy", function() {
2
+
3
+ it("defaults its name to unknown", function() {
4
+ var spyStrategy = new j$.SpyStrategy();
5
+
6
+ expect(spyStrategy.identity()).toEqual("unknown");
7
+ });
8
+
9
+ it("takes a name", function() {
10
+ var spyStrategy = new j$.SpyStrategy({name: "foo"});
11
+
12
+ expect(spyStrategy.identity()).toEqual("foo");
13
+ });
14
+
15
+ it("stubs an original function, if provided", function() {
16
+ var originalFn = jasmine.createSpy("original"),
17
+ spyStrategy = new j$.SpyStrategy({fn: originalFn});
18
+
19
+ spyStrategy.exec();
20
+
21
+ expect(originalFn).not.toHaveBeenCalled();
22
+ });
23
+
24
+ it("allows an original function to be called, passed through the params and returns it's value", function() {
25
+ var originalFn = jasmine.createSpy("original").and.callReturn(42),
26
+ spyStrategy = new j$.SpyStrategy({fn: originalFn}),
27
+ returnValue;
28
+
29
+ spyStrategy.callThrough();
30
+ returnValue = spyStrategy.exec("foo");
31
+
32
+ expect(originalFn).toHaveBeenCalled();
33
+ expect(originalFn.calls.mostRecent().args).toEqual(["foo"]);
34
+ expect(returnValue).toEqual(42);
35
+ });
36
+
37
+ it("can return a specified value when executed", function() {
38
+ var originalFn = jasmine.createSpy("original"),
39
+ spyStrategy = new j$.SpyStrategy({fn: originalFn}),
40
+ returnValue;
41
+
42
+ spyStrategy.callReturn(17);
43
+ returnValue = spyStrategy.exec();
44
+
45
+ expect(originalFn).not.toHaveBeenCalled();
46
+ expect(returnValue).toEqual(17);
47
+ });
48
+
49
+ it("allows an exception to be thrown when executed", function() {
50
+ var originalFn = jasmine.createSpy("original"),
51
+ spyStrategy = new j$.SpyStrategy({fn: originalFn});
52
+
53
+ spyStrategy.callThrow("bar");
54
+
55
+ expect(function() { spyStrategy.exec(); }).toThrow("bar");
56
+ expect(originalFn).not.toHaveBeenCalled();
57
+ });
58
+
59
+ it("allows a fake function to be called instead", function() {
60
+ var originalFn = jasmine.createSpy("original"),
61
+ fakeFn = jasmine.createSpy("fake").and.callReturn(67),
62
+ spyStrategy = new j$.SpyStrategy({fn: originalFn}),
63
+ returnValue;
64
+
65
+ spyStrategy.callFake(fakeFn);
66
+ returnValue = spyStrategy.exec();
67
+
68
+ expect(originalFn).not.toHaveBeenCalled();
69
+ expect(returnValue).toEqual(67);
70
+ });
71
+
72
+ it("allows a return to plan stubbing after another strategy", function() {
73
+ var originalFn = jasmine.createSpy("original"),
74
+ fakeFn = jasmine.createSpy("fake").and.callReturn(67),
75
+ spyStrategy = new j$.SpyStrategy({fn: originalFn}),
76
+ returnValue;
77
+
78
+ spyStrategy.callFake(fakeFn);
79
+ returnValue = spyStrategy.exec();
80
+
81
+ expect(originalFn).not.toHaveBeenCalled();
82
+ expect(returnValue).toEqual(67);
83
+
84
+ spyStrategy.stub();
85
+ returnValue = spyStrategy.exec();
86
+
87
+ expect(returnValue).toEqual(void 0);
88
+ });
89
+
90
+ it("returns the spy after changing the strategy", function(){
91
+ var spy = {},
92
+ spyFn = jasmine.createSpy('spyFn').and.callReturn(spy),
93
+ spyStrategy = new j$.SpyStrategy({getSpy: spyFn});
94
+
95
+ expect(spyStrategy.callThrough()).toBe(spy);
96
+ expect(spyStrategy.callReturn()).toBe(spy);
97
+ expect(spyStrategy.callThrow()).toBe(spy);
98
+ expect(spyStrategy.callFake()).toBe(spy);
99
+ expect(spyStrategy.stub()).toBe(spy);
100
+ });
101
+ });
@@ -1,120 +1,230 @@
1
- describe('Suite', function() {
2
- var fakeTimer;
3
- var env;
4
-
5
- beforeEach(function() {
6
- env = new jasmine.Env();
7
- env.updateInterval = 0;
8
-
9
- fakeTimer = new jasmine.FakeTimer();
10
- env.setTimeout = fakeTimer.setTimeout;
11
- env.clearTimeout = fakeTimer.clearTimeout;
12
- env.setInterval = fakeTimer.setInterval;
13
- env.clearInterval = fakeTimer.clearInterval;
1
+ describe("Suite", function() {
2
+
3
+ it("keeps its id", function() {
4
+ var env = new j$.Env(),
5
+ suite = new j$.Suite({
6
+ env: env,
7
+ id: 456,
8
+ description: "I am a suite"
9
+ });
10
+
11
+ expect(suite.id).toEqual(456);
14
12
  });
15
13
 
16
- describe('Specs', function () {
17
- var suite;
18
-
19
- beforeEach(function() {
20
- suite = env.describe('Suite 1', function () {
21
- env.it('Spec 1', function() {
22
- this.runs(function () {
23
- this.expect(true).toEqual(true);
24
- });
25
- });
26
- env.it('Spec 2', function() {
27
- this.runs(function () {
28
- this.expect(true).toEqual(true);
29
- });
30
- });
31
- env.describe('Suite 2', function () {
32
- env.it('Spec 3', function() {
33
- this.runs(function () {
34
- this.expect(true).toEqual(true);
35
- });
36
- });
37
- });
38
- env.it('Spec 4', function() {
39
- this.runs(function () {
40
- this.expect(true).toEqual(true);
41
- });
42
- });
14
+ it("returns its full name", function() {
15
+ var env = new j$.Env(),
16
+ suite = new j$.Suite({
17
+ env: env,
18
+ description: "I am a suite"
43
19
  });
44
- });
45
-
46
- it('#specs should return all immediate children that are specs.', function () {
47
- var suiteSpecs = suite.specs();
48
- expect(suiteSpecs.length).toEqual(3);
49
- expect(suiteSpecs[0].description).toEqual('Spec 1');
50
- expect(suiteSpecs[1].description).toEqual('Spec 2');
51
- expect(suiteSpecs[2].description).toEqual('Spec 4');
52
- });
53
20
 
54
- it("#suites should return all immediate children that are suites.", function() {
55
- var nestedSuites = suite.suites();
56
- expect(nestedSuites.length).toEqual(1);
57
- expect(nestedSuites[0].description).toEqual('Suite 2');
58
- });
21
+ expect(suite.getFullName()).toEqual("I am a suite");
22
+ });
59
23
 
60
- it("#children should return all immediate children including suites and specs.", function() {
61
- var children = suite.children();
62
- expect(children.length).toEqual(4);
63
- expect(children[0].description).toEqual('Spec 1');
64
- expect(children[1].description).toEqual('Spec 2');
65
- expect(children[2].description).toEqual('Suite 2');
66
- expect(children[3].description).toEqual('Spec 4');
67
- });
24
+ it("returns its full name when it has parent suites", function() {
25
+ var env = new j$.Env(),
26
+ parentSuite = new j$.Suite({
27
+ env: env,
28
+ description: "I am a parent suite",
29
+ parentSuite: jasmine.createSpy('pretend top level suite')
30
+ }),
31
+ suite = new j$.Suite({
32
+ env: env,
33
+ description: "I am a suite",
34
+ parentSuite: parentSuite
35
+ });
36
+
37
+ expect(suite.getFullName()).toEqual("I am a parent suite I am a suite");
68
38
  });
69
39
 
70
- describe('SpecCount', function () {
71
-
72
- it('should keep a count of the number of specs that are run', function() {
73
- var suite = env.describe('one suite description', function () {
74
- env.it('should be a test', function() {
75
- this.runs(function () {
76
- this.expect(true).toEqual(true);
77
- });
78
- });
79
- env.it('should be another test', function() {
80
- this.runs(function () {
81
- this.expect(true).toEqual(true);
82
- });
83
- });
84
- env.it('should be a third test', function() {
85
- this.runs(function () {
86
- this.expect(true).toEqual(true);
87
- });
88
- });
40
+ it("adds before functions in order of needed execution", function() {
41
+ var env = new j$.Env(),
42
+ suite = new j$.Suite({
43
+ env: env,
44
+ description: "I am a suite"
45
+ }),
46
+ outerBefore = jasmine.createSpy('outerBeforeEach'),
47
+ innerBefore = jasmine.createSpy('insideBeforeEach');
48
+
49
+ suite.beforeEach(outerBefore);
50
+ suite.beforeEach(innerBefore);
51
+
52
+ expect(suite.beforeFns).toEqual([innerBefore, outerBefore]);
53
+ });
54
+
55
+ it("adds after functions in order of needed execution", function() {
56
+ var env = new j$.Env(),
57
+ suite = new j$.Suite({
58
+ env: env,
59
+ description: "I am a suite"
60
+ }),
61
+ outerAfter = jasmine.createSpy('outerAfterEach'),
62
+ innerAfter = jasmine.createSpy('insideAfterEach');
63
+
64
+ suite.afterEach(outerAfter);
65
+ suite.afterEach(innerAfter);
66
+
67
+ expect(suite.afterFns).toEqual([innerAfter, outerAfter]);
68
+ });
69
+
70
+ it("adds specs", function() {
71
+ var env = new j$.Env(),
72
+ fakeQueue = {
73
+ add: jasmine.createSpy()
74
+ },
75
+ suite = new j$.Suite({
76
+ env: env,
77
+ description: "I am a suite",
78
+ queueFactory: function() {
79
+ return fakeQueue
80
+ }
81
+ }),
82
+ fakeSpec = {};
83
+
84
+ expect(suite.specs.length).toEqual(0);
85
+
86
+ suite.addSpec(fakeSpec);
87
+
88
+ expect(suite.specs.length).toEqual(1);
89
+ });
90
+
91
+ it("adds suites", function() {
92
+ var env = new j$.Env(),
93
+ fakeQueue = {
94
+ add: jasmine.createSpy()
95
+ },
96
+ suite = new j$.Suite({
97
+ env: env,
98
+ description: "I am a suite",
99
+ queueFactory: function() {
100
+ return fakeQueue
101
+ }
102
+ }),
103
+ anotherSuite = new j$.Suite({
104
+ env: env,
105
+ description: "I am another suite",
106
+ queueFactory: function() {
107
+ return fakeQueue
108
+ }
89
109
  });
90
110
 
91
- expect(suite.specs().length).toEqual(3);
92
- });
111
+ expect(suite.suites.length).toEqual(0);
112
+
113
+ suite.addSuite(anotherSuite);
93
114
 
94
- it('specCount should be correct even with runs/waits blocks', function() {
95
- var suite = env.describe('one suite description', function () {
96
- env.it('should be a test', function() {
97
- this.runs(function () {
98
- this.expect(true).toEqual(true);
99
- });
100
- });
101
- env.it('should be another test', function() {
102
- this.runs(function () {
103
- this.expect(true).toEqual(true);
104
- });
105
- this.waits(10);
106
- this.runs(function () {
107
- this.expect(true).toEqual(true);
108
- });
109
- });
110
- env.it('should be a third test', function() {
111
- this.runs(function () {
112
- this.expect(true).toEqual(true);
113
- });
114
- });
115
+ expect(suite.suites.length).toEqual(1);
116
+ });
117
+
118
+ it("can be disabled", function() {
119
+ var env = new j$.Env(),
120
+ fakeQueueRunner = jasmine.createSpy('fake queue runner'),
121
+ suite = new j$.Suite({
122
+ env: env,
123
+ description: "with a child suite",
124
+ queueRunner: fakeQueueRunner
115
125
  });
116
126
 
117
- expect(suite.specs().length).toEqual(3);
127
+ suite.disable();
128
+
129
+ expect(suite.disabled).toBe(true);
130
+
131
+ suite.execute();
132
+
133
+ expect(fakeQueueRunner).not.toHaveBeenCalled();
134
+ });
135
+
136
+ it("delegates execution of its specs and suites", function() {
137
+ var env = new j$.Env(),
138
+ parentSuiteDone = jasmine.createSpy('parent suite done'),
139
+ fakeQueueRunnerForParent = jasmine.createSpy('fake parent queue runner'),
140
+ parentSuite = new j$.Suite({
141
+ env: env,
142
+ description: "I am a parent suite",
143
+ queueRunner: fakeQueueRunnerForParent
144
+ }),
145
+ fakeQueueRunner = jasmine.createSpy('fake queue runner'),
146
+ suite = new j$.Suite({
147
+ env: env,
148
+ description: "with a child suite",
149
+ queueRunner: fakeQueueRunner
150
+ }),
151
+ fakeSpec1 = {
152
+ execute: jasmine.createSpy('fakeSpec1')
153
+ };
154
+
155
+ spyOn(suite, "execute");
156
+
157
+ parentSuite.addSpec(fakeSpec1);
158
+ parentSuite.addSuite(suite);
159
+
160
+ parentSuite.execute(parentSuiteDone);
161
+
162
+ var parentSuiteFns = fakeQueueRunnerForParent.calls.mostRecent().args[0].fns;
163
+
164
+ parentSuiteFns[0]();
165
+ expect(fakeSpec1.execute).toHaveBeenCalled();
166
+ parentSuiteFns[1]();
167
+ expect(suite.execute).toHaveBeenCalled();
168
+ });
169
+
170
+ it("calls a provided onStart callback when starting", function() {
171
+ var env = new j$.Env(),
172
+ suiteStarted = jasmine.createSpy('suiteStarted'),
173
+ fakeQueueRunner = function(attrs) { attrs.onComplete(); },
174
+ suite = new j$.Suite({
175
+ env: env,
176
+ description: "with a child suite",
177
+ onStart: suiteStarted,
178
+ queueRunner: fakeQueueRunner
179
+ }),
180
+ fakeSpec1 = {
181
+ execute: jasmine.createSpy('fakeSpec1')
182
+ };
183
+
184
+ suite.execute();
185
+
186
+ expect(suiteStarted).toHaveBeenCalledWith(suite);
187
+ });
188
+
189
+ it("calls a provided onComplete callback when done", function() {
190
+ var env = new j$.Env(),
191
+ suiteCompleted = jasmine.createSpy('parent suite done'),
192
+ fakeQueueRunner = function(attrs) { attrs.onComplete(); },
193
+ suite = new j$.Suite({
194
+ env: env,
195
+ description: "with a child suite",
196
+ queueRunner: fakeQueueRunner
197
+ }),
198
+ fakeSpec1 = {
199
+ execute: jasmine.createSpy('fakeSpec1')
200
+ };
201
+
202
+ suite.execute(suiteCompleted);
203
+
204
+ expect(suiteCompleted).toHaveBeenCalled();
205
+ });
206
+
207
+ it("calls a provided result callback when done", function() {
208
+ var env = new j$.Env(),
209
+ suiteResultsCallback = jasmine.createSpy('suite result callback'),
210
+ fakeQueueRunner = function(attrs) { attrs.onComplete(); },
211
+ suite = new j$.Suite({
212
+ env: env,
213
+ description: "with a child suite",
214
+ queueRunner: fakeQueueRunner,
215
+ resultCallback: suiteResultsCallback
216
+ }),
217
+ fakeSpec1 = {
218
+ execute: jasmine.createSpy('fakeSpec1')
219
+ };
220
+
221
+ suite.execute();
222
+
223
+ expect(suiteResultsCallback).toHaveBeenCalledWith({
224
+ id: suite.id,
225
+ status: '',
226
+ description: "with a child suite",
227
+ fullName: "with a child suite"
118
228
  });
119
229
  });
120
- });
230
+ });
@@ -0,0 +1,13 @@
1
+ describe("Timer", function() {
2
+ it("reports the time elapsed", function() {
3
+ var fakeNow = jasmine.createSpy('fake Date.now'),
4
+ timer = new j$.Timer({now: fakeNow});
5
+
6
+ fakeNow.and.callReturn(100);
7
+ timer.start();
8
+
9
+ fakeNow.and.callReturn(200);
10
+
11
+ expect(timer.elapsed()).toEqual(100);
12
+ });
13
+ });