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,118 @@
1
+ // Jasmine boot.js for browser runners - exposes external/global interface, builds the Jasmine environment and executes it.
2
+ (function() {
3
+
4
+ window.jasmine = jasmineRequire.core(jasmineRequire);
5
+ jasmineRequire.html(jasmine);
6
+
7
+ var env = jasmine.getEnv();
8
+
9
+ var jasmineInterface = {
10
+ describe: function(description, specDefinitions) {
11
+ return env.describe(description, specDefinitions);
12
+ },
13
+
14
+ xdescribe: function(description, specDefinitions) {
15
+ return env.xdescribe(description, specDefinitions);
16
+ },
17
+
18
+ it: function(desc, func) {
19
+ return env.it(desc, func);
20
+ },
21
+
22
+ xit: function(desc, func) {
23
+ return env.xit(desc, func);
24
+ },
25
+
26
+ beforeEach: function(beforeEachFunction) {
27
+ return env.beforeEach(beforeEachFunction);
28
+ },
29
+
30
+ afterEach: function(afterEachFunction) {
31
+ return env.afterEach(afterEachFunction);
32
+ },
33
+
34
+ expect: function(actual) {
35
+ return env.expect(actual);
36
+ },
37
+
38
+ pending: function() {
39
+ return env.pending();
40
+ },
41
+
42
+ addMatchers: function(matchers) {
43
+ return env.addMatchers(matchers);
44
+ },
45
+
46
+ spyOn: function(obj, methodName) {
47
+ return env.spyOn(obj, methodName);
48
+ },
49
+
50
+ clock: env.clock,
51
+ setTimeout: env.clock.setTimeout,
52
+ clearTimeout: env.clock.clearTimeout,
53
+ setInterval: env.clock.setInterval,
54
+ clearInterval: env.clock.clearInterval,
55
+
56
+ jsApiReporter: new jasmine.JsApiReporter({
57
+ timer: new jasmine.Timer()
58
+ })
59
+ };
60
+
61
+ if (typeof window == "undefined" && typeof exports == "object") {
62
+ extend(exports, jasmineInterface);
63
+ } else {
64
+ extend(window, jasmineInterface);
65
+ }
66
+
67
+ var queryString = new jasmine.QueryString({
68
+ getWindowLocation: function() { return window.location; }
69
+ });
70
+
71
+ // TODO: move all of catching to raise so we don't break our brains
72
+ var catchingExceptions = queryString.getParam("catch");
73
+ env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
74
+
75
+ var htmlReporter = new jasmine.HtmlReporter({
76
+ env: env,
77
+ queryString: queryString,
78
+ onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
79
+ getContainer: function() { return document.body; },
80
+ createElement: function() { return document.createElement.apply(document, arguments); },
81
+ createTextNode: function() { return document.createTextNode.apply(document, arguments); },
82
+ timer: new jasmine.Timer()
83
+ });
84
+
85
+ env.addReporter(jasmineInterface.jsApiReporter);
86
+ env.addReporter(htmlReporter);
87
+
88
+ var specFilter = new jasmine.HtmlSpecFilter({
89
+ filterString: function() { return queryString.getParam("spec"); }
90
+ });
91
+
92
+ env.specFilter = function(spec) {
93
+ return specFilter.matches(spec.getFullName());
94
+ };
95
+
96
+ var currentWindowOnload = window.onload;
97
+
98
+ window.onload = function() {
99
+ if (currentWindowOnload) {
100
+ currentWindowOnload();
101
+ }
102
+ htmlReporter.initialize();
103
+
104
+ // By the time onload is called, jasmineRequire will be redefined to point
105
+ // to the Jasmine source files (and not jasmine.js). So re-require
106
+ window.j$ = jasmineRequire.core(jasmineRequire);
107
+ jasmineRequire.html(j$);
108
+ jasmineRequire.console(jasmineRequire, j$);
109
+
110
+ env.execute();
111
+ };
112
+
113
+ function extend(destination, source) {
114
+ for (var property in source) destination[property] = source[property];
115
+ return destination;
116
+ }
117
+
118
+ }());
@@ -1,6 +1,9 @@
1
+ #
2
+ # DO NOT Edit this file. Canonical version of Jasmine lives in the repo's package.json. This file is generated
3
+ # by a grunt task when the standalone release is built.
4
+ #
1
5
  module Jasmine
2
6
  module Core
3
- VERSION = "1.3.1"
7
+ VERSION = "2.0.0.rc2"
4
8
  end
5
9
  end
6
-
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
5
- prerelease:
4
+ version: 2.0.0.rc2
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rajan Agaskar
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-12-03 00:00:00.000000000 Z
14
+ date: 2013-07-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json_pure
@@ -29,22 +29,6 @@ dependencies:
29
29
  - - ! '>='
30
30
  - !ruby/object:Gem::Version
31
31
  version: 1.4.3
32
- - !ruby/object:Gem::Dependency
33
- name: tilt
34
- requirement: !ruby/object:Gem::Requirement
35
- none: false
36
- requirements:
37
- - - ! '>='
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
- type: :development
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
32
  - !ruby/object:Gem::Dependency
49
33
  name: sass
50
34
  requirement: !ruby/object:Gem::Requirement
@@ -77,22 +61,6 @@ dependencies:
77
61
  - - ! '>='
78
62
  - !ruby/object:Gem::Version
79
63
  version: '0'
80
- - !ruby/object:Gem::Dependency
81
- name: ragaskar-jsdoc_helper
82
- requirement: !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- type: :development
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
93
- - - ! '>='
94
- - !ruby/object:Gem::Version
95
- version: '0'
96
64
  - !ruby/object:Gem::Dependency
97
65
  name: rspec
98
66
  requirement: !ruby/object:Gem::Requirement
@@ -141,22 +109,6 @@ dependencies:
141
109
  - - ! '>='
142
110
  - !ruby/object:Gem::Version
143
111
  version: '0'
144
- - !ruby/object:Gem::Dependency
145
- name: thor
146
- requirement: !ruby/object:Gem::Requirement
147
- none: false
148
- requirements:
149
- - - ! '>='
150
- - !ruby/object:Gem::Version
151
- version: '0'
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- none: false
156
- requirements:
157
- - - ! '>='
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
112
  - !ruby/object:Gem::Dependency
161
113
  name: nokogiri
162
114
  requirement: !ruby/object:Gem::Requirement
@@ -174,39 +126,7 @@ dependencies:
174
126
  - !ruby/object:Gem::Version
175
127
  version: '0'
176
128
  - !ruby/object:Gem::Dependency
177
- name: redcarpet
178
- requirement: !ruby/object:Gem::Requirement
179
- none: false
180
- requirements:
181
- - - '='
182
- - !ruby/object:Gem::Version
183
- version: '1.7'
184
- type: :development
185
- prerelease: false
186
- version_requirements: !ruby/object:Gem::Requirement
187
- none: false
188
- requirements:
189
- - - '='
190
- - !ruby/object:Gem::Version
191
- version: '1.7'
192
- - !ruby/object:Gem::Dependency
193
- name: rocco
194
- requirement: !ruby/object:Gem::Requirement
195
- none: false
196
- requirements:
197
- - - ! '>='
198
- - !ruby/object:Gem::Version
199
- version: '0'
200
- type: :development
201
- prerelease: false
202
- version_requirements: !ruby/object:Gem::Requirement
203
- none: false
204
- requirements:
205
- - - ! '>='
206
- - !ruby/object:Gem::Version
207
- version: '0'
208
- - !ruby/object:Gem::Dependency
209
- name: rdiscount
129
+ name: sauce-connect
210
130
  requirement: !ruby/object:Gem::Requirement
211
131
  none: false
212
132
  requirements:
@@ -228,9 +148,10 @@ executables: []
228
148
  extensions: []
229
149
  extra_rdoc_files: []
230
150
  files:
151
+ - ./lib/jasmine-core/boot/boot.js
152
+ - ./lib/jasmine-core/boot.js
231
153
  - ./lib/jasmine-core/example/spec/PlayerSpec.js
232
154
  - ./lib/jasmine-core/example/spec/SpecHelper.js
233
- - ./lib/jasmine-core/example/SpecRunner.html
234
155
  - ./lib/jasmine-core/example/src/Player.js
235
156
  - ./lib/jasmine-core/example/src/Song.js
236
157
  - ./lib/jasmine-core/jasmine-html.js
@@ -240,30 +161,56 @@ files:
240
161
  - ./lib/jasmine-core/version.rb
241
162
  - ./lib/jasmine-core.rb
242
163
  - ./lib/jasmine-core/spec/console/ConsoleReporterSpec.js
243
- - ./lib/jasmine-core/spec/core/BaseSpec.js
164
+ - ./lib/jasmine-core/spec/core/AnySpec.js
165
+ - ./lib/jasmine-core/spec/core/CallTrackerSpec.js
166
+ - ./lib/jasmine-core/spec/core/ClockSpec.js
244
167
  - ./lib/jasmine-core/spec/core/CustomMatchersSpec.js
168
+ - ./lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js
245
169
  - ./lib/jasmine-core/spec/core/EnvSpec.js
170
+ - ./lib/jasmine-core/spec/core/ExceptionFormatterSpec.js
246
171
  - ./lib/jasmine-core/spec/core/ExceptionsSpec.js
172
+ - ./lib/jasmine-core/spec/core/ExpectationResultSpec.js
173
+ - ./lib/jasmine-core/spec/core/ExpectationSpec.js
247
174
  - ./lib/jasmine-core/spec/core/JsApiReporterSpec.js
248
- - ./lib/jasmine-core/spec/core/MatchersSpec.js
249
- - ./lib/jasmine-core/spec/core/MockClockSpec.js
250
- - ./lib/jasmine-core/spec/core/MultiReporterSpec.js
251
- - ./lib/jasmine-core/spec/core/NestedResultsSpec.js
175
+ - ./lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js
176
+ - ./lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js
177
+ - ./lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js
178
+ - ./lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js
179
+ - ./lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js
180
+ - ./lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js
181
+ - ./lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js
182
+ - ./lib/jasmine-core/spec/core/matchers/toBeNullSpec.js
183
+ - ./lib/jasmine-core/spec/core/matchers/toBeSpec.js
184
+ - ./lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js
185
+ - ./lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js
186
+ - ./lib/jasmine-core/spec/core/matchers/toContainSpec.js
187
+ - ./lib/jasmine-core/spec/core/matchers/toEqualSpec.js
188
+ - ./lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js
189
+ - ./lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js
190
+ - ./lib/jasmine-core/spec/core/matchers/toMatchSpec.js
191
+ - ./lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js
192
+ - ./lib/jasmine-core/spec/core/matchers/toThrowSpec.js
193
+ - ./lib/jasmine-core/spec/core/ObjectContainingSpec.js
252
194
  - ./lib/jasmine-core/spec/core/PrettyPrintSpec.js
253
- - ./lib/jasmine-core/spec/core/QueueSpec.js
254
- - ./lib/jasmine-core/spec/core/ReporterSpec.js
255
- - ./lib/jasmine-core/spec/core/RunnerSpec.js
195
+ - ./lib/jasmine-core/spec/core/QueueRunnerSpec.js
196
+ - ./lib/jasmine-core/spec/core/ReportDispatcherSpec.js
256
197
  - ./lib/jasmine-core/spec/core/SpecRunningSpec.js
257
198
  - ./lib/jasmine-core/spec/core/SpecSpec.js
258
199
  - ./lib/jasmine-core/spec/core/SpySpec.js
200
+ - ./lib/jasmine-core/spec/core/SpyStrategySpec.js
259
201
  - ./lib/jasmine-core/spec/core/SuiteSpec.js
202
+ - ./lib/jasmine-core/spec/core/TimerSpec.js
260
203
  - ./lib/jasmine-core/spec/core/UtilSpec.js
261
- - ./lib/jasmine-core/spec/core/WaitsForBlockSpec.js
262
- - ./lib/jasmine-core/spec/html/HTMLReporterSpec.js
204
+ - ./lib/jasmine-core/spec/helpers/BrowserFlags.js
205
+ - ./lib/jasmine-core/spec/html/HtmlReporterSpec.js
206
+ - ./lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js
263
207
  - ./lib/jasmine-core/spec/html/MatchersHtmlSpec.js
264
208
  - ./lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js
265
- - ./lib/jasmine-core/spec/html/TrivialReporterSpec.js
209
+ - ./lib/jasmine-core/spec/html/QueryStringSpec.js
210
+ - ./lib/jasmine-core/spec/html/ResultsNodeSpec.js
266
211
  - ./lib/jasmine-core/spec/node_suite.js
212
+ - ./lib/jasmine-core/spec/performance/performance_test.js
213
+ - ./lib/jasmine-core/spec/support/dev_boot.js
267
214
  homepage: http://pivotal.github.com/jasmine
268
215
  licenses:
269
216
  - MIT
@@ -279,19 +226,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
279
226
  version: '0'
280
227
  segments:
281
228
  - 0
282
- hash: -2880110052648878798
229
+ hash: 1155836624161041639
283
230
  required_rubygems_version: !ruby/object:Gem::Requirement
284
231
  none: false
285
232
  requirements:
286
- - - ! '>='
233
+ - - ! '>'
287
234
  - !ruby/object:Gem::Version
288
- version: '0'
289
- segments:
290
- - 0
291
- hash: -2880110052648878798
235
+ version: 1.3.1
292
236
  requirements: []
293
237
  rubyforge_project: jasmine-core
294
- rubygems_version: 1.8.24
238
+ rubygems_version: 1.8.25
295
239
  signing_key:
296
240
  specification_version: 3
297
241
  summary: JavaScript BDD framework
@@ -1,54 +0,0 @@
1
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
- "http://www.w3.org/TR/html4/loose.dtd">
3
- <html>
4
- <head>
5
- <title>Jasmine Spec Runner</title>
6
-
7
- <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.1.0.rc1/jasmine_favicon.png">
8
-
9
- <link rel="stylesheet" type="text/css" href="lib/jasmine-1.1.0.rc1/jasmine.css">
10
- <script type="text/javascript" src="lib/jasmine-1.1.0.rc1/jasmine.js"></script>
11
- <script type="text/javascript" src="lib/jasmine-1.1.0.rc1/jasmine-html.js"></script>
12
-
13
- <!-- include spec files here... -->
14
- <script type="text/javascript" src="spec/SpecHelper.js"></script>
15
- <script type="text/javascript" src="spec/PlayerSpec.js"></script>
16
-
17
- <!-- include source files here... -->
18
- <script type="text/javascript" src="src/Player.js"></script>
19
- <script type="text/javascript" src="src/Song.js"></script>
20
-
21
- <script type="text/javascript">
22
- (function() {
23
- var jasmineEnv = jasmine.getEnv();
24
- jasmineEnv.updateInterval = 1000;
25
-
26
- var trivialReporter = new jasmine.TrivialReporter();
27
-
28
- jasmineEnv.addReporter(trivialReporter);
29
-
30
- jasmineEnv.specFilter = function(spec) {
31
- return trivialReporter.specFilter(spec);
32
- };
33
-
34
- var currentWindowOnload = window.onload;
35
-
36
- window.onload = function() {
37
- if (currentWindowOnload) {
38
- currentWindowOnload();
39
- }
40
- execJasmine();
41
- };
42
-
43
- function execJasmine() {
44
- jasmineEnv.execute();
45
- }
46
-
47
- })();
48
- </script>
49
-
50
- </head>
51
-
52
- <body>
53
- </body>
54
- </html>
@@ -1,27 +0,0 @@
1
- describe("base.js", function() {
2
- describe("jasmine.MessageResult", function() {
3
- it("#toString should pretty-print and concatenate each part of the message", function() {
4
- var values = ["log", "message", 123, {key: "value"}, "FTW!"];
5
- var messageResult = new jasmine.MessageResult(values);
6
- expect(messageResult.toString()).toEqual("log message 123 { key : 'value' } FTW!");
7
- });
8
- });
9
-
10
- describe("jasmine.log", function() {
11
- it("should accept n arguments", function() {
12
- spyOn(jasmine.getEnv().currentSpec, 'log');
13
- jasmine.log(1, 2, 3);
14
- expect(jasmine.getEnv().currentSpec.log).toHaveBeenCalledWith(1, 2, 3);
15
- });
16
- });
17
-
18
- describe("jasmine.getGlobal", function() {
19
- it("should return the global object", function() {
20
- var globalObject = (function() {
21
- return this;
22
- })();
23
-
24
- expect(jasmine.getGlobal()).toBe(globalObject);
25
- });
26
- });
27
- });
@@ -1,1157 +0,0 @@
1
- describe("jasmine.Matchers", 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
- function catchException(fn) {
33
- try {
34
- fn.call();
35
- } catch (e) {
36
- return e;
37
- }
38
- throw new Error("expected function to throw an exception");
39
- }
40
-
41
- it("toEqual with primitives, objects, dates, etc.", function() {
42
- expect(match(true).toEqual(true)).toPass();
43
-
44
- expect(match({foo:'bar'}).toEqual(null)).toFail();
45
-
46
- var functionA = function() {
47
- return 'hi';
48
- };
49
- var functionB = function() {
50
- return 'hi';
51
- };
52
- expect(match({foo:functionA}).toEqual({foo:functionB})).toFail();
53
- expect(match({foo:functionA}).toEqual({foo:functionA})).toPass();
54
-
55
- expect((match(false).toEqual(true))).toFail();
56
-
57
- var circularGraph = {};
58
- circularGraph.referenceToSelf = circularGraph;
59
- expect((match(circularGraph).toEqual(circularGraph))).toPass();
60
-
61
- expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2009, 1, 3, 15, 17, 19, 1234)))).toFail();
62
- expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2008, 1, 3, 15, 17, 19, 1234)))).toPass();
63
-
64
-
65
- expect(match(true).toNotEqual(false)).toPass();
66
- expect((match(true).toNotEqual(true))).toFail();
67
-
68
- expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toFail();
69
- expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toFail();
70
-
71
- expect((match("cat").toEqual("cat"))).toPass();
72
- expect((match("cat").toNotEqual("cat"))).toFail();
73
-
74
- expect((match(5).toEqual(5))).toPass();
75
- expect((match(parseInt('5', 10)).toEqual(5))).toPass();
76
- expect((match(5).toNotEqual(5))).toFail();
77
- expect((match(parseInt('5', 10)).toNotEqual(5))).toFail();
78
-
79
- expect((match(/1/i).toEqual(/1/i))).toPass();
80
- expect((match(/1/i).toNotEqual(/1/i))).toFail();
81
- expect((match(/[abc]/gm).toEqual(/1/i))).toFail();
82
- expect((match(/[abc]/gm).toNotEqual(/1/i))).toPass();
83
-
84
- // only test if the browser supports the sticky option on a regExp see pull #234
85
- if (RegExp.prototype.sticky !== undefined) {
86
- var sticky_regexp = new RegExp("[abc]", "y");
87
- expect((match(sticky_regexp).toEqual(/1/i))).toFail();
88
- expect((match(sticky_regexp).toNotEqual(/1/i))).toPass();
89
- }
90
- });
91
-
92
- it("toEqual to build an Expectation Result", function() {
93
- var actual = 'a';
94
- var matcher = match(actual);
95
- var expected = 'b';
96
- matcher.toEqual(expected);
97
-
98
- var result = lastResult();
99
-
100
- expect(result.matcherName).toEqual("toEqual");
101
- expect(result.passed()).toFail();
102
- expect(result.message).toMatch(jasmine.pp(actual));
103
- expect(result.message).toMatch(jasmine.pp(expected));
104
- expect(result.expected).toEqual(expected);
105
- expect(result.actual).toEqual(actual);
106
- });
107
-
108
- it("toNotEqual to build an Expectation Result", function() {
109
- var str = 'a';
110
- var matcher = match(str);
111
- matcher.toNotEqual(str);
112
-
113
- var result = lastResult();
114
-
115
- expect(result.matcherName).toEqual("toNotEqual");
116
- expect(result.passed()).toFail();
117
- expect(result.message).toMatch(jasmine.pp(str));
118
- expect(result.message).toMatch('not');
119
- expect(result.expected).toEqual(str);
120
- expect(result.actual).toEqual(str);
121
- });
122
-
123
- it('toBe should return true only if the expected and actual items === each other', function() {
124
- var a = {};
125
- var b = {};
126
- //noinspection UnnecessaryLocalVariableJS
127
- var c = a;
128
- expect((match(a).toBe(b))).toFail();
129
- expect((match(a).toBe(a))).toPass();
130
- expect((match(a).toBe(c))).toPass();
131
- expect((match(a).toNotBe(b))).toPass();
132
- expect((match(a).toNotBe(a))).toFail();
133
- expect((match(a).toNotBe(c))).toFail();
134
- });
135
-
136
- it("toBe to build an ExpectationResult", function() {
137
- var expected = 'b';
138
- var actual = 'a';
139
- var matcher = match(actual);
140
- matcher.toBe(expected);
141
-
142
- var result = lastResult();
143
-
144
- expect(result.matcherName).toEqual("toBe");
145
- expect(result.passed()).toFail();
146
- expect(result.message).toMatch(jasmine.pp(actual));
147
- expect(result.message).toMatch(jasmine.pp(expected));
148
- expect(result.expected).toEqual(expected);
149
- expect(result.actual).toEqual(actual);
150
- });
151
-
152
- it("toNotBe to build an ExpectationResult", function() {
153
- var str = 'a';
154
- var matcher = match(str);
155
- matcher.toNotBe(str);
156
-
157
- var result = lastResult();
158
-
159
- expect(result.matcherName).toEqual("toNotBe");
160
- expect(result.passed()).toFail();
161
- expect(result.message).toMatch(str);
162
- expect(result.expected).toEqual(str);
163
- expect(result.actual).toEqual(str);
164
- });
165
-
166
- it("toMatch and #toNotMatch should perform regular expression matching on strings", function() {
167
- expect((match('foobarbel').toMatch(/bar/))).toPass();
168
- expect((match('foobazbel').toMatch(/bar/))).toFail();
169
-
170
- expect((match('foobarbel').toMatch("bar"))).toPass();
171
- expect((match('foobazbel').toMatch("bar"))).toFail();
172
-
173
- expect((match('foobarbel').toNotMatch(/bar/))).toFail();
174
- expect((match('foobazbel').toNotMatch(/bar/))).toPass();
175
-
176
- expect((match('foobarbel').toNotMatch("bar"))).toFail();
177
- expect((match('foobazbel').toNotMatch("bar"))).toPass();
178
- });
179
-
180
- it("toMatch w/ RegExp to build an ExpectationResult", function() {
181
- var actual = 'a';
182
- var matcher = match(actual);
183
- var expected = /b/;
184
- matcher.toMatch(expected);
185
-
186
- var result = lastResult();
187
-
188
- expect(result.matcherName).toEqual("toMatch");
189
- expect(result.passed()).toFail();
190
- expect(result.message).toMatch(jasmine.pp(actual));
191
- expect(result.message).toMatch(expected.toString());
192
- expect(result.expected).toEqual(expected);
193
- expect(result.actual).toEqual(actual);
194
- });
195
-
196
- it("toMatch w/ String to build an ExpectationResult", function() {
197
- var actual = 'a';
198
- var matcher = match(actual);
199
- var expected = 'b';
200
- matcher.toMatch(expected);
201
-
202
- var result = lastResult();
203
-
204
- expect(result.matcherName).toEqual("toMatch");
205
- expect(result.passed()).toFail();
206
- expect(result.message).toEqual("Expected 'a' to match 'b'.");
207
- expect(result.expected).toEqual(expected);
208
- expect(result.actual).toEqual(actual);
209
- });
210
-
211
- it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
212
- var actual = 'a';
213
- var matcher = match(actual);
214
- var expected = /a/;
215
- matcher.toNotMatch(expected);
216
-
217
- var result = lastResult();
218
-
219
- expect(result.matcherName).toEqual("toNotMatch");
220
- expect(result.passed()).toFail();
221
- expect(result.message).toEqual("Expected 'a' to not match /a/.");
222
- expect(result.expected).toEqual(expected);
223
- expect(result.actual).toEqual(actual);
224
- });
225
-
226
- it("toNotMatch w/ String to build an ExpectationResult", function() {
227
- var str = 'a';
228
- var matcher = match(str);
229
- matcher.toNotMatch(str);
230
-
231
- var result = lastResult();
232
-
233
- expect(result.matcherName).toEqual("toNotMatch");
234
- expect(result.passed()).toFail();
235
- expect(result.message).toEqual("Expected 'a' to not match 'a'.");
236
- expect(result.expected).toEqual(str);
237
- expect(result.actual).toEqual(str);
238
- });
239
-
240
- it("toBeDefined", function() {
241
- expect(match('foo').toBeDefined()).toPass();
242
- expect(match(jasmine.undefined).toBeDefined()).toFail();
243
- });
244
-
245
- it("toBeDefined to build an ExpectationResult", function() {
246
- var matcher = match(jasmine.undefined);
247
- matcher.toBeDefined();
248
-
249
- var result = lastResult();
250
-
251
- expect(result.matcherName).toEqual("toBeDefined");
252
- expect(result.passed()).toFail();
253
- expect(result.message).toEqual('Expected undefined to be defined.');
254
- expect(result.actual).toEqual(jasmine.undefined);
255
- });
256
-
257
- it("toBeUndefined", function() {
258
- expect(match('foo').toBeUndefined()).toFail();
259
- expect(match(jasmine.undefined).toBeUndefined()).toPass();
260
- });
261
-
262
- it("toBeNull", function() {
263
- expect(match(null).toBeNull()).toPass();
264
- expect(match(jasmine.undefined).toBeNull()).toFail();
265
- expect(match("foo").toBeNull()).toFail();
266
- });
267
-
268
- it("toBeNull w/ String to build an ExpectationResult", function() {
269
- var actual = 'a';
270
- var matcher = match(actual);
271
- matcher.toBeNull();
272
-
273
- var result = lastResult();
274
-
275
- expect(result.matcherName).toEqual("toBeNull");
276
- expect(result.passed()).toFail();
277
- expect(result.message).toMatch(jasmine.pp(actual));
278
- expect(result.message).toMatch('null');
279
- expect(result.actual).toEqual(actual);
280
- });
281
-
282
- it("toBeNull w/ Object to build an ExpectationResult", function() {
283
- var actual = {a: 'b'};
284
- var matcher = match(actual);
285
- matcher.toBeNull();
286
-
287
- var result = lastResult();
288
-
289
- expect(result.matcherName).toEqual("toBeNull");
290
- expect(result.passed()).toFail();
291
- expect(result.message).toMatch(jasmine.pp(actual));
292
- expect(result.message).toMatch('null');
293
- expect(result.actual).toEqual(actual);
294
- });
295
-
296
- it("toBeNaN", function() {
297
- expect(match(Number.NaN).toBeNaN()).toPass();
298
- expect(match(0).toBeNaN()).toFail();
299
- expect(match(1).toBeNaN()).toFail();
300
- expect(match(null).toBeNaN()).toFail();
301
- expect(match(Number.POSITIVE_INFINITY).toBeNaN()).toFail();
302
- expect(match(Number.NEGATIVE_INFINITY).toBeNaN()).toFail();
303
- expect(match('NaN').toBeNaN()).toFail();
304
- });
305
-
306
- it("toBeNaN to build an ExpectationResult", function() {
307
- var actual = 'a';
308
- var matcher = match(actual);
309
- matcher.toBeNaN();
310
-
311
- var result = lastResult();
312
-
313
- expect(result.matcherName).toEqual("toBeNaN");
314
- expect(result.passed()).toFail();
315
- expect(result.message).toMatch("Expected 'a' to be NaN.");
316
- expect(result.actual).toMatch(actual);
317
- });
318
-
319
- it("toBeFalsy", function() {
320
- expect(match(false).toBeFalsy()).toPass();
321
- expect(match(true).toBeFalsy()).toFail();
322
- expect(match(jasmine.undefined).toBeFalsy()).toPass();
323
- expect(match(0).toBeFalsy()).toPass();
324
- expect(match("").toBeFalsy()).toPass();
325
- });
326
-
327
- it("toBeFalsy to build an ExpectationResult", function() {
328
- var actual = 'a';
329
- var matcher = match(actual);
330
- matcher.toBeFalsy();
331
-
332
- var result = lastResult();
333
-
334
- expect(result.matcherName).toEqual("toBeFalsy");
335
- expect(result.passed()).toFail();
336
- expect(result.message).toMatch(jasmine.pp(actual));
337
- expect(result.message).toMatch('falsy');
338
- expect(result.actual).toEqual(actual);
339
- });
340
-
341
- it("toBeTruthy", function() {
342
- expect(match(false).toBeTruthy()).toFail();
343
- expect(match(true).toBeTruthy()).toPass();
344
- expect(match(jasmine.undefined).toBeTruthy()).toFail();
345
- expect(match(0).toBeTruthy()).toFail();
346
- expect(match("").toBeTruthy()).toFail();
347
- expect(match("hi").toBeTruthy()).toPass();
348
- expect(match(5).toBeTruthy()).toPass();
349
- expect(match({foo: 1}).toBeTruthy()).toPass();
350
- });
351
-
352
- it("toBeTruthy to build an ExpectationResult", function() {
353
- var matcher = match(false);
354
- matcher.toBeTruthy();
355
-
356
- var result = lastResult();
357
-
358
- expect(result.matcherName).toEqual("toBeTruthy");
359
- expect(result.passed()).toFail();
360
- expect(result.message).toEqual("Expected false to be truthy.");
361
- expect(result.actual).toFail();
362
- });
363
-
364
- it("toEqual", function() {
365
- expect(match(jasmine.undefined).toEqual(jasmine.undefined)).toPass();
366
- expect(match({foo:'bar'}).toEqual({foo:'bar'})).toPass();
367
- expect(match("foo").toEqual({bar: jasmine.undefined})).toFail();
368
- expect(match({foo: jasmine.undefined}).toEqual("goo")).toFail();
369
- expect(match({foo: {bar :jasmine.undefined}}).toEqual("goo")).toFail();
370
- });
371
-
372
- it("toEqual with jasmine.any()", function() {
373
- expect(match("foo").toEqual(jasmine.any(String))).toPass();
374
- expect(match(3).toEqual(jasmine.any(Number))).toPass();
375
- expect(match("foo").toEqual(jasmine.any(Function))).toFail();
376
- expect(match("foo").toEqual(jasmine.any(Object))).toFail();
377
- expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toPass();
378
- expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toFail();
379
- expect(match(
380
- function() {
381
- }).toEqual(jasmine.any(Object))).toFail();
382
- expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toPass();
383
- expect(match(
384
- function() {
385
- }).toEqual(jasmine.any(Function))).toPass();
386
- expect(match(["a", function() {
387
- }]).toEqual(["a", jasmine.any(Function)])).toPass();
388
- });
389
-
390
- describe("toEqual with an object implementing jasmineMatches", function () {
391
- var matcher;
392
- beforeEach(function () {
393
- matcher = {
394
- jasmineMatches: jasmine.createSpy("jasmineMatches")
395
- };
396
- });
397
-
398
- describe("on the left side", function () {
399
- it("uses the jasmineMatches function", function () {
400
- matcher.jasmineMatches.andReturn(false);
401
- expect(match(matcher).toEqual("foo")).toFail();
402
- matcher.jasmineMatches.andReturn(true);
403
- expect(match(matcher).toEqual("foo")).toPass();
404
- });
405
- });
406
-
407
- describe("on the right side", function () {
408
- it("uses the jasmineMatches function", function () {
409
- matcher.jasmineMatches.andReturn(false);
410
- expect(match("foo").toEqual(matcher)).toFail();
411
- matcher.jasmineMatches.andReturn(true);
412
- expect(match("foo").toEqual(matcher)).toPass();
413
- });
414
- });
415
- });
416
-
417
- it("toEqual handles circular objects ok", function() {
418
- expect(match({foo: "bar", baz: jasmine.undefined}).toEqual({foo: "bar", baz: jasmine.undefined})).toPass();
419
- expect(match({foo:['bar','baz','quux']}).toEqual({foo:['bar','baz','quux']})).toPass();
420
- expect(match({foo: {bar:'baz'}, quux:'corge'}).toEqual({foo:{bar:'baz'}, quux:'corge'})).toPass();
421
-
422
- var circularObject = {};
423
- var secondCircularObject = {};
424
- circularObject.field = circularObject;
425
- secondCircularObject.field = secondCircularObject;
426
- expect(match(circularObject).toEqual(secondCircularObject)).toPass();
427
- });
428
-
429
- it("toNotEqual as slightly surprising behavior, but is it intentional?", function() {
430
- expect(match({x:"x", y:"y", z:"w"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
431
- expect(match({x:"x", y:"y", w:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
432
- expect(match({x:"x", y:"y", z:"z"}).toNotEqual({w: "w", x:"x", y:"y", z:"z"})).toPass();
433
- expect(match({w: "w", x:"x", y:"y", z:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
434
- });
435
-
436
- it("toEqual handles arrays", function() {
437
- expect(match([1, "A"]).toEqual([1, "A"])).toPass();
438
- });
439
-
440
- it("toContain and toNotContain", function() {
441
- expect(match('ABC').toContain('A')).toPass();
442
- expect(match('ABC').toContain('X')).toFail();
443
-
444
- expect(match(['A', 'B', 'C']).toContain('A')).toPass();
445
- expect(match(['A', 'B', 'C']).toContain('F')).toFail();
446
- expect(match(['A', 'B', 'C']).toNotContain('F')).toPass();
447
- expect(match(['A', 'B', 'C']).toNotContain('A')).toFail();
448
-
449
- expect(match(['A', {some:'object'}, 'C']).toContain({some:'object'})).toPass();
450
- expect(match(['A', {some:'object'}, 'C']).toContain({some:'other object'})).toFail();
451
- });
452
-
453
- it("toContain to build an ExpectationResult", function() {
454
- var actual = ['a','b','c'];
455
- var matcher = match(actual);
456
- var expected = 'x';
457
- matcher.toContain(expected);
458
-
459
- var result = lastResult();
460
-
461
- expect(result.matcherName).toEqual("toContain");
462
- expect(result.passed()).toFail();
463
- expect(result.message).toMatch(jasmine.pp(actual));
464
- expect(result.message).toMatch('contain');
465
- expect(result.message).toMatch(jasmine.pp(expected));
466
- expect(result.actual).toEqual(actual);
467
- expect(result.expected).toEqual(expected);
468
- });
469
-
470
- it("toNotContain to build an ExpectationResult", function() {
471
- var actual = ['a','b','c'];
472
- var matcher = match(actual);
473
- var expected = 'b';
474
- matcher.toNotContain(expected);
475
-
476
- var result = lastResult();
477
-
478
- expect(result.matcherName).toEqual("toNotContain");
479
- expect(result.passed()).toFail();
480
- expect(result.message).toMatch(jasmine.pp(actual));
481
- expect(result.message).toMatch('not contain');
482
- expect(result.message).toMatch(jasmine.pp(expected));
483
- expect(result.actual).toEqual(actual);
484
- expect(result.expected).toEqual(expected);
485
- });
486
-
487
- it("toBeLessThan should pass if actual is less than expected", function() {
488
- expect(match(37).toBeLessThan(42)).toPass();
489
- expect(match(37).toBeLessThan(-42)).toFail();
490
- expect(match(37).toBeLessThan(37)).toFail();
491
- });
492
-
493
- it("toBeLessThan to build an ExpectationResult", function() {
494
- var actual = 3;
495
- var matcher = match(actual);
496
- var expected = 1;
497
- matcher.toBeLessThan(expected);
498
-
499
- var result = lastResult();
500
-
501
- expect(result.matcherName).toEqual("toBeLessThan");
502
- expect(result.passed()).toFail();
503
- expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
504
- expect(result.message).toMatch(jasmine.pp(expected));
505
- expect(result.actual).toEqual(actual);
506
- expect(result.expected).toEqual(expected);
507
- });
508
-
509
- it("toBeGreaterThan should pass if actual is greater than expected", function() {
510
- expect(match(37).toBeGreaterThan(42)).toFail();
511
- expect(match(37).toBeGreaterThan(-42)).toPass();
512
- expect(match(37).toBeGreaterThan(37)).toFail();
513
- });
514
-
515
- it("toBeGreaterThan to build an ExpectationResult", function() {
516
- var actual = 1;
517
- var matcher = match(actual);
518
- var expected = 3;
519
- matcher.toBeGreaterThan(expected);
520
-
521
- var result = lastResult();
522
-
523
- expect(result.matcherName).toEqual("toBeGreaterThan");
524
- expect(result.passed()).toFail();
525
- expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
526
- expect(result.message).toMatch(jasmine.pp(expected));
527
- expect(result.actual).toEqual(actual);
528
- expect(result.expected).toEqual(expected);
529
- });
530
-
531
- describe("toBeCloseTo", function() {
532
- it("returns 'true' iff actual and expected are equal within 2 decimal points of precision", function() {
533
- expect(0).toBeCloseTo(0);
534
- expect(1).toBeCloseTo(1);
535
- expect(1).not.toBeCloseTo(1.1);
536
- expect(1).not.toBeCloseTo(1.01);
537
- expect(1).toBeCloseTo(1.001);
538
-
539
- expect(1.23).toBeCloseTo(1.234);
540
- expect(1.23).toBeCloseTo(1.233);
541
- expect(1.23).toBeCloseTo(1.232);
542
- expect(1.23).not.toBeCloseTo(1.24);
543
-
544
- expect(-1.23).toBeCloseTo(-1.234);
545
- expect(-1.23).not.toBeCloseTo(-1.24);
546
- });
547
-
548
- it("expects close numbers to 'be close' and further numbers not to", function() {
549
- expect(1.225).not.toBeCloseTo(1.234); // difference is 0.009
550
- expect(1.225).toBeCloseTo(1.224); // difference is 0.001
551
- });
552
-
553
- it("accepts an optional precision argument", function() {
554
- expect(1).toBeCloseTo(1.1, 0);
555
- expect(1.2).toBeCloseTo(1.23, 1);
556
-
557
- expect(1.234).toBeCloseTo(1.2343, 3);
558
- expect(1.234).not.toBeCloseTo(1.233, 3);
559
- });
560
-
561
- it("rounds", function() {
562
- expect(1.23).toBeCloseTo(1.229);
563
- expect(1.23).toBeCloseTo(1.226);
564
- expect(1.23).toBeCloseTo(1.225);
565
- expect(1.23).not.toBeCloseTo(1.2249999);
566
-
567
- expect(1.23).toBeCloseTo(1.234);
568
- expect(1.23).toBeCloseTo(1.2349999);
569
- expect(1.23).not.toBeCloseTo(1.235);
570
-
571
- expect(-1.23).toBeCloseTo(-1.234);
572
- expect(-1.23).not.toBeCloseTo(-1.235);
573
- expect(-1.23).not.toBeCloseTo(-1.236);
574
- });
575
- });
576
-
577
- describe("toThrow", function() {
578
- describe("when code block throws an exception", function() {
579
- var throwingFn;
580
-
581
- beforeEach(function() {
582
- throwingFn = function() {
583
- throw new Error("Fake Error");
584
- };
585
- });
586
-
587
- it("should match any exception", function() {
588
- expect(match(throwingFn).toThrow()).toPass();
589
- });
590
-
591
- it("should match exceptions specified by message", function() {
592
- expect(match(throwingFn).toThrow("Fake Error")).toPass();
593
- expect(match(throwingFn).toThrow("Other Error")).toFail();
594
- expect(lastResult().message).toMatch("Other Error");
595
- });
596
-
597
- it("should match exceptions specified by Error", function() {
598
- expect(match(throwingFn).toThrow(new Error("Fake Error"))).toPass();
599
- expect(match(throwingFn).toThrow(new Error("Other Error"))).toFail();
600
- expect(lastResult().message).toMatch("Other Error");
601
- });
602
-
603
- describe("and matcher is inverted with .not", function() {
604
- it("should match any exception", function() {
605
- expect(match(throwingFn).not.toThrow()).toFail();
606
- expect(lastResult().message).toMatch(/Expected function not to throw an exception/);
607
- });
608
-
609
- it("should match exceptions specified by message", function() {
610
- expect(match(throwingFn).not.toThrow("Fake Error")).toFail();
611
- // expect(lastResult().message).toMatch(/Expected function not to throw Fake Error./);
612
- expect(match(throwingFn).not.toThrow("Other Error")).toPass();
613
- });
614
-
615
- it("should match exceptions specified by Error", function() {
616
- expect(match(throwingFn).not.toThrow(new Error("Fake Error"))).toFail();
617
- // expect(lastResult().message).toMatch("Other Error");
618
- expect(match(throwingFn).not.toThrow(new Error("Other Error"))).toPass();
619
- });
620
- });
621
- });
622
-
623
- describe("when actual is not a function", function() {
624
- it("should fail with an exception", function() {
625
- var exception = catchException(function() {
626
- match('not-a-function').toThrow();
627
- });
628
- expect(exception).toBeDefined();
629
- expect(exception.message).toEqual('Actual is not a function');
630
- });
631
-
632
- describe("and matcher is inverted with .not", function() {
633
- it("should fail with an exception", function() {
634
- var exception = catchException(function() {
635
- match('not-a-function').not.toThrow();
636
- });
637
- expect(exception).toBeDefined();
638
- expect(exception.message).toEqual('Actual is not a function');
639
- });
640
- });
641
- });
642
-
643
-
644
- describe("when code block does not throw an exception", function() {
645
- it("should fail (or pass when inverted with .not)", function() {
646
- expect(match(
647
- function() {
648
- }).toThrow()).toFail();
649
- expect(lastResult().message).toEqual('Expected function to throw an exception.');
650
- });
651
- });
652
- });
653
-
654
- describe(".not.matcher", function() {
655
- it("should invert the sense of any matcher", function() {
656
- expect(match(37).not.toBeGreaterThan(42)).toPass();
657
- expect(match(42).not.toBeGreaterThan(37)).toFail();
658
- expect(match("abc").not.toEqual("def")).toPass();
659
- expect(match("abc").not.toEqual("abc")).toFail();
660
- });
661
-
662
- it("should provide an inverted default message", function() {
663
- match(37).not.toBeGreaterThan(42);
664
- expect(lastResult().message).toEqual("Passed.");
665
-
666
- match(42).not.toBeGreaterThan(37);
667
- expect(lastResult().message).toEqual("Expected 42 not to be greater than 37.");
668
- });
669
-
670
- it("should use the second message when the matcher sets an array of custom messages", function() {
671
- spec.addMatchers({
672
- custom: function() {
673
- this.message = function() {
674
- return ['Expected it was called.', 'Expected it wasn\'t called.'];
675
- };
676
- return this.actual;
677
- }
678
- });
679
-
680
- match(true).custom();
681
- expect(lastResult().message).toEqual("Passed.");
682
- match(false).custom();
683
- expect(lastResult().message).toEqual("Expected it was called.");
684
- match(true).not.custom();
685
- expect(lastResult().message).toEqual("Expected it wasn't called.");
686
- match(false).not.custom();
687
- expect(lastResult().message).toEqual("Passed.");
688
- });
689
- });
690
-
691
- describe("spy matchers >>", function() {
692
- var TestClass;
693
- beforeEach(function() {
694
- TestClass = {
695
- normalFunction: function() {
696
- },
697
- spyFunction: jasmine.createSpy("My spy")
698
- };
699
- });
700
-
701
- function shouldThrowAnExceptionWhenInvokedOnANonSpy(methodName) {
702
- return function() {
703
- expect(
704
- function() {
705
- match(TestClass.normalFunction)[methodName]();
706
- }).toThrow('Expected a spy, but got Function.');
707
-
708
- expect(
709
- function() {
710
- match(jasmine.undefined)[methodName]();
711
- }).toThrow('Expected a spy, but got undefined.');
712
-
713
- expect(
714
- function() {
715
- match({some:'object'})[methodName]();
716
- }).toThrow('Expected a spy, but got { some : \'object\' }.');
717
-
718
- expect(
719
- function() {
720
- match("<b>")[methodName]();
721
- }).toThrow('Expected a spy, but got \'<b>\'.');
722
- };
723
- }
724
-
725
- describe("toHaveBeenCalled", function() {
726
- it("should pass if the spy was called", function() {
727
- expect(match(TestClass.spyFunction).toHaveBeenCalled()).toFail();
728
-
729
- TestClass.spyFunction();
730
- expect(match(TestClass.spyFunction).toHaveBeenCalled()).toPass();
731
- });
732
-
733
- it("should throw an exception when invoked with any arguments", function() {
734
- expect(
735
- function() {
736
- match(TestClass.normalFunction).toHaveBeenCalled("unwanted argument");
737
- }).toThrow('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
738
- });
739
-
740
- it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalled'));
741
- });
742
-
743
- describe("wasCalled", function() {
744
- it("should alias toHaveBeenCalled", function() {
745
- spyOn(TestClass, 'normalFunction');
746
-
747
- TestClass.normalFunction();
748
-
749
- expect(TestClass.normalFunction).wasCalled();
750
- });
751
- });
752
-
753
-
754
- describe("wasNotCalled", function() {
755
- it("should pass iff the spy was not called", function() {
756
- expect(match(TestClass.spyFunction).wasNotCalled()).toPass();
757
-
758
- TestClass.spyFunction();
759
- expect(match(TestClass.spyFunction).wasNotCalled()).toFail();
760
- });
761
-
762
- it("should throw an exception when invoked with any arguments", function() {
763
- expect(
764
- function() {
765
- match(TestClass.normalFunction).wasNotCalled("unwanted argument");
766
- }).toThrow('wasNotCalled does not take arguments');
767
- });
768
-
769
- it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalled'));
770
- });
771
-
772
- describe("toHaveBeenCalledWith", function() {
773
- it('toHaveBeenCalledWith should return true if it was called with the expected args', function() {
774
- TestClass.spyFunction('a', 'b', 'c');
775
- expect(match(TestClass.spyFunction).toHaveBeenCalledWith('a', 'b', 'c')).toPass();
776
- });
777
-
778
- it('should return false if it was not called with the expected args', function() {
779
- TestClass.spyFunction('a', 'b', 'c');
780
- var expected = match(TestClass.spyFunction);
781
- expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail();
782
- var result = lastResult();
783
- expect(result.passed()).toFail();
784
- expect(result.expected).toEqual(['c', 'b', 'a']);
785
- expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
786
- expect(result.message).toContain(jasmine.pp(result.expected));
787
- expect(result.message).toContain(jasmine.pp(result.actual.mostRecentCall.args));
788
- });
789
-
790
- it('should return false if it was not called', function() {
791
- var expected = match(TestClass.spyFunction);
792
- expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail();
793
- var result = lastResult();
794
- expect(result.passed()).toFail();
795
- expect(result.expected).toEqual(['c', 'b', 'a']);
796
- expect(result.actual.argsForCall).toEqual([]);
797
- expect(result.message).toContain(jasmine.pp(result.expected));
798
- });
799
-
800
- it('should allow matches across multiple calls', function() {
801
- TestClass.spyFunction('a', 'b', 'c');
802
- TestClass.spyFunction('d', 'e', 'f');
803
- var expected = match(TestClass.spyFunction);
804
- expect(expected.toHaveBeenCalledWith('a', 'b', 'c')).toPass();
805
- expect(expected.toHaveBeenCalledWith('d', 'e', 'f')).toPass();
806
- expect(expected.toHaveBeenCalledWith('x', 'y', 'z')).toFail();
807
- });
808
-
809
- it("should return a decent message", function() {
810
- TestClass.spyFunction('a', 'b', 'c');
811
- TestClass.spyFunction('d', 'e', 'f');
812
- var expected = match(TestClass.spyFunction);
813
- expect(expected.toHaveBeenCalledWith('a', 'b')).toFail();
814
- expect(lastResult().message).toEqual("Expected spy My spy to have been called with [ 'a', 'b' ] but actual calls were [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ]");
815
- });
816
-
817
- it("should return a decent message when it hasn't been called", function() {
818
- var expected = match(TestClass.spyFunction);
819
- expect(expected.toHaveBeenCalledWith('a', 'b')).toFail();
820
- expect(lastResult().message).toEqual("Expected spy My spy to have been called with [ 'a', 'b' ] but it was never called.");
821
- });
822
-
823
- it("should return a decent message when inverted", function() {
824
- TestClass.spyFunction('a', 'b', 'c');
825
- TestClass.spyFunction('d', 'e', 'f');
826
- var expected = match(TestClass.spyFunction);
827
- expect(expected.not.toHaveBeenCalledWith('a', 'b', 'c')).toFail();
828
- expect(lastResult().message).toEqual("Expected spy My spy not to have been called with [ 'a', 'b', 'c' ] but it was.");
829
- });
830
-
831
- it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalledWith'));
832
-
833
- describe("to build an ExpectationResult", function () {
834
- beforeEach(function() {
835
- var currentSuite;
836
- var spec;
837
- currentSuite = env.describe('default current suite', function() {
838
- spec = env.it();
839
- }, spec);
840
- TestClass = { someFunction: function(a, b) {
841
- } };
842
- spec.spyOn(TestClass, 'someFunction');
843
- });
844
-
845
- it("should should handle the case of a spy", function() {
846
- TestClass.someFunction('a', 'c');
847
- var matcher = match(TestClass.someFunction);
848
- matcher.toHaveBeenCalledWith('a', 'b');
849
-
850
- var result = lastResult();
851
- expect(result.matcherName).toEqual("toHaveBeenCalledWith");
852
- expect(result.passed()).toFail();
853
- expect(result.message).toContain(jasmine.pp(['a', 'b']));
854
- expect(result.message).toContain(jasmine.pp(['a', 'c']));
855
- expect(result.actual).toEqual(TestClass.someFunction);
856
- expect(result.expected).toEqual(['a','b']);
857
- });
858
- });
859
- });
860
-
861
- describe("wasCalledWith", function() {
862
- it("should alias toHaveBeenCalledWith", function() {
863
- spyOn(TestClass, 'normalFunction');
864
-
865
- TestClass.normalFunction(123);
866
-
867
- expect(TestClass.normalFunction).wasCalledWith(123);
868
- });
869
- });
870
-
871
- describe("wasNotCalledWith", function() {
872
- it('should return true if the spy was NOT called with the expected args', function() {
873
- TestClass.spyFunction('a', 'b', 'c');
874
- expect(match(TestClass.spyFunction).wasNotCalledWith('c', 'b', 'a')).toPass();
875
- });
876
-
877
- it('should return false if it WAS called with the expected args', function() {
878
- TestClass.spyFunction('a', 'b', 'c');
879
- var expected = match(TestClass.spyFunction);
880
- expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail();
881
- var result = lastResult();
882
- expect(result.passed()).toFail();
883
- expect(result.expected).toEqual(['a', 'b', 'c']);
884
- expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
885
- expect(result.message).toContain(jasmine.pp(result.expected));
886
- });
887
-
888
- it('should return true if it was not called', function() {
889
- var expected = match(TestClass.spyFunction);
890
- expect(expected.wasNotCalledWith('c', 'b', 'a')).toPass();
891
- });
892
-
893
- it('should allow matches across multiple calls', function() {
894
- var expected = match(TestClass.spyFunction);
895
- TestClass.spyFunction('a', 'b', 'c');
896
- TestClass.spyFunction('d', 'e', 'f');
897
- expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail();
898
- expect(expected.wasNotCalledWith('d', 'e', 'f')).toFail();
899
- expect(expected.wasNotCalledWith('x', 'y', 'z')).toPass();
900
- });
901
-
902
- it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalledWith'));
903
- });
904
- });
905
-
906
- describe("ObjectContaining", function () {
907
- describe("with an empty object", function () {
908
- var containing;
909
- beforeEach(function () {
910
- containing = new jasmine.Matchers.ObjectContaining({});
911
- });
912
- it("matches everything", function () {
913
- expect(containing.jasmineMatches("foo", [], [])).toBe(true);
914
- });
915
-
916
- it("says it didn't expect to contain anything", function () {
917
- expect(containing.jasmineToString()).toEqual("<jasmine.objectContaining({ })>");
918
- });
919
- });
920
-
921
- describe("with an object with items in it", function () {
922
- var containing, mismatchKeys, mismatchValues;
923
- beforeEach(function () {
924
- mismatchKeys = [];
925
- mismatchValues = [];
926
- containing = new jasmine.Matchers.ObjectContaining({foo: "fooVal", bar: "barVal"});
927
- });
928
-
929
- it("doesn't match an empty object", function () {
930
- expect(containing.jasmineMatches({}, mismatchKeys, mismatchValues)).toBe(false);
931
- });
932
-
933
- it("doesn't match an object with none of the specified options", function () {
934
- expect(containing.jasmineMatches({baz:"stuff"}, mismatchKeys, mismatchValues)).toBe(false);
935
- });
936
-
937
- it("adds a message for each missing key", function () {
938
- containing.jasmineMatches({foo: "fooVal"}, mismatchKeys, mismatchValues);
939
- expect(mismatchKeys.length).toEqual(1);
940
- });
941
-
942
- it("doesn't match an object when the values are different", function () {
943
- expect(containing.jasmineMatches({foo:"notFoo", bar:"notBar"}, mismatchKeys, mismatchValues)).toBe(false);
944
- });
945
-
946
- it("adds a message when values don't match", function () {
947
- containing.jasmineMatches({foo: "fooVal", bar: "notBar"}, mismatchKeys, mismatchValues);
948
- expect(mismatchValues.length).toEqual(1);
949
- });
950
-
951
- it("doesn't match an object with only one of the values matching", function () {
952
- expect(containing.jasmineMatches({foo:"notFoo", bar:"barVal"}, mismatchKeys, mismatchValues)).toBe(false);
953
- });
954
-
955
- it("matches when all the values are the same", function () {
956
- expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal"}, mismatchKeys, mismatchValues)).toBe(true);
957
- });
958
-
959
- it("matches when there are additional values", function () {
960
- expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal", baz: "bazVal"}, mismatchKeys, mismatchValues)).toBe(true);
961
- });
962
-
963
- it("doesn't modify missingKeys or missingValues when match is successful", function () {
964
- containing.jasmineMatches({foo: "fooVal", bar: "barVal"}, mismatchKeys, mismatchValues);
965
- expect(mismatchKeys.length).toEqual(0);
966
- expect(mismatchValues.length).toEqual(0);
967
- });
968
-
969
- it("says what it expects to contain", function () {
970
- expect(containing.jasmineToString()).toEqual("<jasmine.objectContaining(" + jasmine.pp({foo:"fooVal", bar:"barVal"}) + ")>");
971
- });
972
- });
973
-
974
- describe("in real life", function () {
975
- var method;
976
- beforeEach(function () {
977
- method = jasmine.createSpy("method");
978
- method({a:"b", c:"d"});
979
- });
980
- it("works correctly for positive matches", function () {
981
- expect(method).toHaveBeenCalledWith(jasmine.objectContaining({a:"b"}));
982
- });
983
-
984
- it("works correctly for negative matches", function () {
985
- expect(method).not.toHaveBeenCalledWith(jasmine.objectContaining({z:"x"}));
986
- });
987
- });
988
- });
989
-
990
- describe("Matchers.Any", function () {
991
- var any;
992
- describe(".jasmineToString", function () {
993
- describe("with Object", function () {
994
- it("says it's looking for an object", function () {
995
- any = jasmine.any(Object);
996
- expect(any.jasmineToString().replace(/\n/g, "")).toMatch(/<jasmine\.any\(function Object.*\)>/);
997
- });
998
- });
999
-
1000
- describe("with Function", function () {
1001
- it("says it's looking for a function", function () {
1002
- any = jasmine.any(Function);
1003
- expect(any.jasmineToString().replace(/\n/g, "")).toMatch(/<jasmine\.any\(function Function.*\)>/);
1004
- });
1005
- });
1006
-
1007
- describe("with String", function () {
1008
- it("says it's looking for a string", function () {
1009
- any = jasmine.any(String);
1010
- expect(any.jasmineToString().replace(/\n/g, "")).toMatch(/<jasmine\.any\(function String.*\)>/);
1011
- });
1012
- });
1013
-
1014
- describe("with Number", function () {
1015
- it("says it's looking for a number", function () {
1016
- any = jasmine.any(Number);
1017
- expect(any.jasmineToString().replace(/\n/g, "")).toMatch(/<jasmine\.any\(function Number.*\)>/);
1018
- });
1019
- });
1020
-
1021
- describe("with some other defined 'class'", function () {
1022
- it("says it's looking for an object", function () {
1023
- function MyClass () {}
1024
- any = jasmine.any(MyClass);
1025
- expect(any.jasmineToString().replace("\n", "")).toMatch(/<jasmine\.any\(function MyClass.*\)>/);
1026
- });
1027
- });
1028
- });
1029
-
1030
- describe(".jasmineMatches", function () {
1031
- describe("with Object", function () {
1032
- beforeEach(function () {
1033
- any = jasmine.any(Object);
1034
- });
1035
-
1036
- it("matches an empty object", function () {
1037
- expect(any.jasmineMatches({})).toEqual(true);
1038
- });
1039
-
1040
- it("matches a newed up object", function () {
1041
- expect(any.jasmineMatches(new Object())).toEqual(true);
1042
- });
1043
-
1044
- it("doesn't match a string", function () {
1045
- expect(any.jasmineMatches("")).toEqual(false);
1046
- });
1047
-
1048
- it("doesn't match a number", function () {
1049
- expect(any.jasmineMatches(123)).toEqual(false);
1050
- });
1051
-
1052
- it("doesn't match a function", function () {
1053
- expect(any.jasmineMatches(function () {})).toEqual(false);
1054
- });
1055
- });
1056
-
1057
- describe("with Function", function () {
1058
- beforeEach(function () {
1059
- any = jasmine.any(Function);
1060
- });
1061
-
1062
- it("doesn't match an object", function () {
1063
- expect(any.jasmineMatches({})).toEqual(false);
1064
- });
1065
-
1066
- it("doesn't match a string", function () {
1067
- expect(any.jasmineMatches("")).toEqual(false);
1068
- });
1069
-
1070
- it("doesn't match a number", function () {
1071
- expect(any.jasmineMatches(123)).toEqual(false);
1072
- });
1073
-
1074
- it("matches a function", function () {
1075
- expect(any.jasmineMatches(function () {})).toEqual(true);
1076
- });
1077
- });
1078
-
1079
- describe("with Number", function () {
1080
- beforeEach(function () {
1081
- any = jasmine.any(Number);
1082
- });
1083
-
1084
- it("doesn't match an object", function () {
1085
- expect(any.jasmineMatches({})).toEqual(false);
1086
- });
1087
-
1088
- it("doesn't match a string", function () {
1089
- expect(any.jasmineMatches("")).toEqual(false);
1090
- });
1091
-
1092
- it("matches a number", function () {
1093
- expect(any.jasmineMatches(123)).toEqual(true);
1094
- });
1095
-
1096
- it("doesn't match a function", function () {
1097
- expect(any.jasmineMatches(function () {})).toEqual(false);
1098
- });
1099
- });
1100
-
1101
- describe("with String", function () {
1102
- beforeEach(function () {
1103
- any = jasmine.any(String);
1104
- });
1105
-
1106
- it("doesn't match an object", function () {
1107
- expect(any.jasmineMatches({})).toEqual(false);
1108
- });
1109
-
1110
- it("matches a string", function () {
1111
- expect(any.jasmineMatches("")).toEqual(true);
1112
- });
1113
-
1114
- it("doesn't match a number", function () {
1115
- expect(any.jasmineMatches(123)).toEqual(false);
1116
- });
1117
-
1118
- it("doesn't match a function", function () {
1119
- expect(any.jasmineMatches(function () {})).toEqual(false);
1120
- });
1121
- });
1122
-
1123
- describe("with some defined 'class'", function () {
1124
- function MyClass () {}
1125
- beforeEach(function () {
1126
- any = jasmine.any(MyClass);
1127
- });
1128
-
1129
- it("doesn't match an object", function () {
1130
- expect(any.jasmineMatches({})).toEqual(false);
1131
- });
1132
-
1133
- it("doesn't match a string", function () {
1134
- expect(any.jasmineMatches("")).toEqual(false);
1135
- });
1136
-
1137
- it("doesn't match a number", function () {
1138
- expect(any.jasmineMatches(123)).toEqual(false);
1139
- });
1140
-
1141
- it("doesn't match a function", function () {
1142
- expect(any.jasmineMatches(function () {})).toEqual(false);
1143
- });
1144
-
1145
- it("matches an instance of the defined class", function () {
1146
- expect(any.jasmineMatches(new MyClass())).toEqual(true);
1147
- });
1148
- });
1149
- });
1150
- });
1151
-
1152
- describe("all matchers", function() {
1153
- it("should return null, for future-proofing, since we might eventually allow matcher chaining", function() {
1154
- expect(match(true).toBe(true)).toBeUndefined();
1155
- });
1156
- });
1157
- });