evergreen 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/README.rdoc +30 -4
  2. data/config/routes.rb +1 -1
  3. data/lib/evergreen.rb +14 -50
  4. data/lib/evergreen/application.rb +46 -0
  5. data/lib/evergreen/cli.rb +2 -2
  6. data/lib/evergreen/rails.rb +4 -0
  7. data/lib/evergreen/resources/evergreen.css +3 -1
  8. data/lib/evergreen/resources/evergreen.js +3 -0
  9. data/lib/evergreen/runner.rb +124 -36
  10. data/lib/evergreen/server.rb +9 -18
  11. data/lib/evergreen/spec.rb +26 -14
  12. data/lib/evergreen/suite.rb +44 -0
  13. data/lib/evergreen/tasks.rb +6 -0
  14. data/lib/evergreen/template.rb +7 -10
  15. data/lib/evergreen/version.rb +1 -1
  16. data/lib/evergreen/views/layout.erb +1 -0
  17. data/lib/evergreen/views/list.erb +2 -2
  18. data/lib/evergreen/views/spec.erb +18 -10
  19. data/lib/jasmine/Gemfile +6 -0
  20. data/lib/jasmine/MIT.LICENSE +2 -2
  21. data/lib/jasmine/README.markdown +5 -459
  22. data/lib/jasmine/Rakefile +22 -16
  23. data/lib/jasmine/example/SpecRunner.html +1 -1
  24. data/lib/jasmine/jsdoc-template/allclasses.tmpl +17 -0
  25. data/lib/jasmine/jsdoc-template/allfiles.tmpl +56 -0
  26. data/lib/jasmine/jsdoc-template/class.tmpl +646 -0
  27. data/lib/jasmine/jsdoc-template/index.tmpl +39 -0
  28. data/lib/jasmine/jsdoc-template/publish.js +184 -0
  29. data/lib/jasmine/jsdoc-template/static/default.css +162 -0
  30. data/lib/jasmine/jsdoc-template/static/header.html +2 -0
  31. data/lib/jasmine/jsdoc-template/static/index.html +19 -0
  32. data/lib/jasmine/jsdoc-template/symbol.tmpl +35 -0
  33. data/lib/jasmine/lib/jasmine-html.js +12 -6
  34. data/lib/jasmine/lib/jasmine.js +122 -44
  35. data/lib/jasmine/spec/runner.html +0 -1
  36. data/lib/jasmine/spec/suites/CustomMatchersSpec.js +18 -9
  37. data/lib/jasmine/spec/suites/MatchersSpec.js +241 -162
  38. data/lib/jasmine/spec/suites/SpecRunningSpec.js +120 -62
  39. data/lib/jasmine/spec/suites/TrivialReporterSpec.js +3 -0
  40. data/lib/jasmine/spec/suites/WaitsForBlockSpec.js +9 -9
  41. data/lib/jasmine/src/Env.js +1 -0
  42. data/lib/jasmine/src/Matchers.js +35 -17
  43. data/lib/jasmine/src/Queue.js +6 -1
  44. data/lib/jasmine/src/Spec.js +34 -2
  45. data/lib/jasmine/src/WaitsForBlock.js +28 -13
  46. data/lib/jasmine/src/base.js +15 -8
  47. data/lib/jasmine/src/html/TrivialReporter.js +12 -6
  48. data/lib/jasmine/src/version.json +2 -2
  49. data/lib/tasks/evergreen.rake +1 -1
  50. data/spec/meta_spec.rb +21 -2
  51. data/spec/runner_spec.rb +16 -18
  52. data/spec/spec_helper.rb +12 -4
  53. data/spec/spec_spec.rb +4 -11
  54. data/spec/suite1/spec/javascripts/invalid_coffee_spec.coffee +1 -0
  55. data/spec/suite1/spec/javascripts/spec_helper.coffee +1 -1
  56. data/spec/suite2/config/evergreen.rb +5 -0
  57. data/spec/suite2/public_html/foo.js +1 -0
  58. data/spec/suite2/spec/awesome_spec.js +12 -0
  59. data/spec/suite2/spec/failing_spec.js +5 -0
  60. data/spec/suite2/templates/foo.html +1 -0
  61. data/spec/suite_spec.rb +26 -0
  62. data/spec/template_spec.rb +3 -9
  63. metadata +52 -20
  64. data/lib/jasmine/lib/consolex.js +0 -28
@@ -21,11 +21,16 @@ jasmine.unimplementedMethod_ = function() {
21
21
  jasmine.undefined = jasmine.___undefined___;
22
22
 
23
23
  /**
24
- * Default interval for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed.
24
+ * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
25
25
  *
26
26
  */
27
27
  jasmine.DEFAULT_UPDATE_INTERVAL = 250;
28
28
 
29
+ /**
30
+ * Default timeout interval in milliseconds for waitsFor() blocks.
31
+ */
32
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
33
+
29
34
  jasmine.getGlobal = function() {
30
35
  function getGlobal() {
31
36
  return this;
@@ -490,22 +495,24 @@ var runs = function(func) {
490
495
  };
491
496
 
492
497
  /**
493
- * Waits for a timeout before moving to the next runs()-defined block.
494
- * @param {Number} timeout
498
+ * Waits a fixed time period before moving to the next block.
499
+ *
500
+ * @deprecated Use waitsFor() instead
501
+ * @param {Number} timeout milliseconds to wait
495
502
  */
496
503
  var waits = function(timeout) {
497
504
  jasmine.getEnv().currentSpec.waits(timeout);
498
505
  };
499
506
 
500
507
  /**
501
- * Waits for the latchFunction to return true before proceeding to the next runs()-defined block.
508
+ * Waits for the latchFunction to return true before proceeding to the next block.
502
509
  *
503
- * @param {Number} timeout
504
510
  * @param {Function} latchFunction
505
- * @param {String} message
511
+ * @param {String} optional_timeoutMessage
512
+ * @param {Number} optional_timeout
506
513
  */
507
- var waitsFor = function(timeout, latchFunction, message) {
508
- jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message);
514
+ var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
515
+ jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
509
516
  };
510
517
 
511
518
  /**
@@ -660,6 +667,7 @@ jasmine.Env = function() {
660
667
  this.reporter = new jasmine.MultiReporter();
661
668
 
662
669
  this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
670
+ this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
663
671
  this.lastUpdate = 0;
664
672
  this.specFilter = function() {
665
673
  return true;
@@ -1135,7 +1143,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
1135
1143
  message: message
1136
1144
  });
1137
1145
  this.spec.addMatcherResult(expectationResult);
1138
- return result;
1146
+ return jasmine.undefined;
1139
1147
  };
1140
1148
  };
1141
1149
 
@@ -1153,6 +1161,7 @@ jasmine.Matchers.prototype.toBe = function(expected) {
1153
1161
  /**
1154
1162
  * toNotBe: compares the actual to the expected using !==
1155
1163
  * @param expected
1164
+ * @deprecated as of 1.0. Use not.toBe() instead.
1156
1165
  */
1157
1166
  jasmine.Matchers.prototype.toNotBe = function(expected) {
1158
1167
  return this.actual !== expected;
@@ -1170,6 +1179,7 @@ jasmine.Matchers.prototype.toEqual = function(expected) {
1170
1179
  /**
1171
1180
  * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
1172
1181
  * @param expected
1182
+ * @deprecated as of 1.0. Use not.toNotEqual() instead.
1173
1183
  */
1174
1184
  jasmine.Matchers.prototype.toNotEqual = function(expected) {
1175
1185
  return !this.env.equals_(this.actual, expected);
@@ -1188,6 +1198,7 @@ jasmine.Matchers.prototype.toMatch = function(expected) {
1188
1198
  /**
1189
1199
  * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
1190
1200
  * @param expected
1201
+ * @deprecated as of 1.0. Use not.toMatch() instead.
1191
1202
  */
1192
1203
  jasmine.Matchers.prototype.toNotMatch = function(expected) {
1193
1204
  return !(new RegExp(expected).test(this.actual));
@@ -1230,11 +1241,6 @@ jasmine.Matchers.prototype.toBeFalsy = function() {
1230
1241
  };
1231
1242
 
1232
1243
 
1233
- /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
1234
- jasmine.Matchers.prototype.wasCalled = function() {
1235
- return this.toHaveBeenCalled();
1236
- };
1237
-
1238
1244
  /**
1239
1245
  * Matcher that checks to see if the actual, a Jasmine spy, was called.
1240
1246
  */
@@ -1248,12 +1254,18 @@ jasmine.Matchers.prototype.toHaveBeenCalled = function() {
1248
1254
  }
1249
1255
 
1250
1256
  this.message = function() {
1251
- return "Expected spy " + this.actual.identity + " to have been called.";
1257
+ return [
1258
+ "Expected spy " + this.actual.identity + " to have been called.",
1259
+ "Expected spy " + this.actual.identity + " not to have been called."
1260
+ ];
1252
1261
  };
1253
1262
 
1254
1263
  return this.actual.wasCalled;
1255
1264
  };
1256
1265
 
1266
+ /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
1267
+ jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled;
1268
+
1257
1269
  /**
1258
1270
  * Matcher that checks to see if the actual, a Jasmine spy, was not called.
1259
1271
  *
@@ -1269,17 +1281,15 @@ jasmine.Matchers.prototype.wasNotCalled = function() {
1269
1281
  }
1270
1282
 
1271
1283
  this.message = function() {
1272
- return "Expected spy " + this.actual.identity + " to not have been called.";
1284
+ return [
1285
+ "Expected spy " + this.actual.identity + " to not have been called.",
1286
+ "Expected spy " + this.actual.identity + " to have been called."
1287
+ ];
1273
1288
  };
1274
1289
 
1275
1290
  return !this.actual.wasCalled;
1276
1291
  };
1277
1292
 
1278
- /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
1279
- jasmine.Matchers.prototype.wasCalledWith = function() {
1280
- return this.toHaveBeenCalledWith.apply(this, arguments);
1281
- };
1282
-
1283
1293
  /**
1284
1294
  * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
1285
1295
  *
@@ -1293,15 +1303,25 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
1293
1303
  }
1294
1304
  this.message = function() {
1295
1305
  if (this.actual.callCount == 0) {
1296
- return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
1306
+ // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
1307
+ return [
1308
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
1309
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
1310
+ ];
1297
1311
  } else {
1298
- return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall);
1312
+ return [
1313
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
1314
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
1315
+ ];
1299
1316
  }
1300
1317
  };
1301
1318
 
1302
1319
  return this.env.contains_(this.actual.argsForCall, expectedArgs);
1303
1320
  };
1304
1321
 
1322
+ /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
1323
+ jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith;
1324
+
1305
1325
  /** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */
1306
1326
  jasmine.Matchers.prototype.wasNotCalledWith = function() {
1307
1327
  var expectedArgs = jasmine.util.argsToArray(arguments);
@@ -1310,7 +1330,10 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() {
1310
1330
  }
1311
1331
 
1312
1332
  this.message = function() {
1313
- return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was";
1333
+ return [
1334
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
1335
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
1336
+ ]
1314
1337
  };
1315
1338
 
1316
1339
  return !this.env.contains_(this.actual.argsForCall, expectedArgs);
@@ -1329,6 +1352,7 @@ jasmine.Matchers.prototype.toContain = function(expected) {
1329
1352
  * Matcher that checks that the expected item is NOT an element in the actual Array.
1330
1353
  *
1331
1354
  * @param {Object} expected
1355
+ * @deprecated as of 1.0. Use not.toNotContain() instead.
1332
1356
  */
1333
1357
  jasmine.Matchers.prototype.toNotContain = function(expected) {
1334
1358
  return !this.env.contains_(this.actual, expected);
@@ -1362,9 +1386,11 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
1362
1386
  result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
1363
1387
  }
1364
1388
 
1389
+ var not = this.isNot ? "not " : "";
1390
+
1365
1391
  this.message = function() {
1366
1392
  if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
1367
- return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' ');
1393
+ return ["Expected function " + not + "to throw", expected ? expected.message || expected : " an exception", ", but it threw", exception.message || exception].join(' ');
1368
1394
  } else {
1369
1395
  return "Expected function to throw an exception.";
1370
1396
  }
@@ -1644,6 +1670,7 @@ jasmine.Queue = function(env) {
1644
1670
  this.running = false;
1645
1671
  this.index = 0;
1646
1672
  this.offset = 0;
1673
+ this.abort = false;
1647
1674
  };
1648
1675
 
1649
1676
  jasmine.Queue.prototype.addBefore = function(block) {
@@ -1678,7 +1705,7 @@ jasmine.Queue.prototype.next_ = function() {
1678
1705
  while (goAgain) {
1679
1706
  goAgain = false;
1680
1707
 
1681
- if (self.index < self.blocks.length) {
1708
+ if (self.index < self.blocks.length && !this.abort) {
1682
1709
  var calledSynchronously = true;
1683
1710
  var completedSynchronously = false;
1684
1711
 
@@ -1688,6 +1715,10 @@ jasmine.Queue.prototype.next_ = function() {
1688
1715
  return;
1689
1716
  }
1690
1717
 
1718
+ if (self.blocks[self.index].abort) {
1719
+ self.abort = true;
1720
+ }
1721
+
1691
1722
  self.offset = 0;
1692
1723
  self.index++;
1693
1724
 
@@ -1884,14 +1915,46 @@ jasmine.Spec.prototype.expect = function(actual) {
1884
1915
  return positive;
1885
1916
  };
1886
1917
 
1918
+ /**
1919
+ * Waits a fixed time period before moving to the next block.
1920
+ *
1921
+ * @deprecated Use waitsFor() instead
1922
+ * @param {Number} timeout milliseconds to wait
1923
+ */
1887
1924
  jasmine.Spec.prototype.waits = function(timeout) {
1888
1925
  var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
1889
1926
  this.addToQueue(waitsFunc);
1890
1927
  return this;
1891
1928
  };
1892
1929
 
1893
- jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) {
1894
- var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this);
1930
+ /**
1931
+ * Waits for the latchFunction to return true before proceeding to the next block.
1932
+ *
1933
+ * @param {Function} latchFunction
1934
+ * @param {String} optional_timeoutMessage
1935
+ * @param {Number} optional_timeout
1936
+ */
1937
+ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
1938
+ var latchFunction_ = null;
1939
+ var optional_timeoutMessage_ = null;
1940
+ var optional_timeout_ = null;
1941
+
1942
+ for (var i = 0; i < arguments.length; i++) {
1943
+ var arg = arguments[i];
1944
+ switch (typeof arg) {
1945
+ case 'function':
1946
+ latchFunction_ = arg;
1947
+ break;
1948
+ case 'string':
1949
+ optional_timeoutMessage_ = arg;
1950
+ break;
1951
+ case 'number':
1952
+ optional_timeout_ = arg;
1953
+ break;
1954
+ }
1955
+ }
1956
+
1957
+ var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
1895
1958
  this.addToQueue(waitsForFunc);
1896
1959
  return this;
1897
1960
  };
@@ -2114,41 +2177,56 @@ jasmine.WaitsBlock.prototype.execute = function (onComplete) {
2114
2177
  onComplete();
2115
2178
  }, this.timeout);
2116
2179
  };
2180
+ /**
2181
+ * A block which waits for some condition to become true, with timeout.
2182
+ *
2183
+ * @constructor
2184
+ * @extends jasmine.Block
2185
+ * @param {jasmine.Env} env The Jasmine environment.
2186
+ * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
2187
+ * @param {Function} latchFunction A function which returns true when the desired condition has been met.
2188
+ * @param {String} message The message to display if the desired condition hasn't been met within the given time period.
2189
+ * @param {jasmine.Spec} spec The Jasmine spec.
2190
+ */
2117
2191
  jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
2118
- this.timeout = timeout;
2192
+ this.timeout = timeout || env.defaultTimeoutInterval;
2119
2193
  this.latchFunction = latchFunction;
2120
2194
  this.message = message;
2121
2195
  this.totalTimeSpentWaitingForLatch = 0;
2122
2196
  jasmine.Block.call(this, env, null, spec);
2123
2197
  };
2124
-
2125
2198
  jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
2126
2199
 
2127
- jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
2200
+ jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
2128
2201
 
2129
- jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
2130
- var self = this;
2131
- self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
2202
+ jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
2203
+ this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
2132
2204
  var latchFunctionResult;
2133
2205
  try {
2134
- latchFunctionResult = self.latchFunction.apply(self.spec);
2206
+ latchFunctionResult = this.latchFunction.apply(this.spec);
2135
2207
  } catch (e) {
2136
- self.spec.fail(e);
2208
+ this.spec.fail(e);
2137
2209
  onComplete();
2138
2210
  return;
2139
2211
  }
2140
2212
 
2141
2213
  if (latchFunctionResult) {
2142
2214
  onComplete();
2143
- } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
2144
- var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
2145
- self.spec.fail({
2215
+ } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
2216
+ var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
2217
+ this.spec.fail({
2146
2218
  name: 'timeout',
2147
2219
  message: message
2148
2220
  });
2221
+
2222
+ this.abort = true;
2223
+ onComplete();
2149
2224
  } else {
2150
- self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
2151
- self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
2225
+ this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
2226
+ var self = this;
2227
+ this.env.setTimeout(function() {
2228
+ self.execute(onComplete);
2229
+ }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
2152
2230
  }
2153
2231
  };
2154
2232
  // Mock setTimeout, clearTimeout
@@ -2336,8 +2414,8 @@ jasmine.getGlobal().clearInterval = function(timeoutKey) {
2336
2414
 
2337
2415
 
2338
2416
  jasmine.version_= {
2339
- "major": 0,
2340
- "minor": 11,
2417
+ "major": 1,
2418
+ "minor": 0,
2341
2419
  "build": 1,
2342
- "revision": 1277514571
2420
+ "revision": 1286311016
2343
2421
  };
@@ -29,7 +29,6 @@
29
29
  <script type="text/javascript" src="../src/WaitsForBlock.js"></script>
30
30
 
31
31
  <script type="text/javascript" src="../src/html/TrivialReporter.js"></script>
32
- <script type="text/javascript" src="../lib/consolex.js"></script>
33
32
 
34
33
 
35
34
 
@@ -11,15 +11,21 @@ describe("Custom Matchers", function() {
11
11
  var spec1, spec2, spec1Matcher, spec2Matcher;
12
12
  var suite = env.describe('some suite', function() {
13
13
  env.beforeEach(function() {
14
- this.addMatchers({ matcherForSuite: function(expected) {
15
- return "matcherForSuite: actual: " + this.actual + "; expected: " + expected;
16
- } });
14
+ this.addMatchers({
15
+ matcherForSuite: function(expected) {
16
+ this.message = "matcherForSuite: actual: " + this.actual + "; expected: " + expected;
17
+ return true;
18
+ }
19
+ });
17
20
  });
18
21
 
19
22
  spec1 = env.it('spec with an expectation').runs(function () {
20
- this.addMatchers({ matcherForSpec: function(expected) {
21
- return "matcherForSpec: actual: " + this.actual + "; expected: " + expected;
22
- } });
23
+ this.addMatchers({
24
+ matcherForSpec: function(expected) {
25
+ this.message = "matcherForSpec: actual: " + this.actual + "; expected: " + expected;
26
+ return true;
27
+ }
28
+ });
23
29
  spec1Matcher = this.expect("xxx");
24
30
  });
25
31
 
@@ -30,10 +36,13 @@ describe("Custom Matchers", function() {
30
36
 
31
37
  suite.execute();
32
38
 
33
- expect(spec1Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: xxx; expected: expected");
34
- expect(spec1Matcher.matcherForSpec("expected")).toEqual("matcherForSpec: actual: xxx; expected: expected");
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");
35
43
 
36
- expect(spec2Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: yyy; expected: expected");
44
+ spec2Matcher.matcherForSuite("expected");
45
+ expect(spec2Matcher.message).toEqual("matcherForSuite: actual: yyy; expected: expected");
37
46
  expect(spec2Matcher.matcherForSpec).toBe(jasmine.undefined);
38
47
  });
39
48
 
@@ -10,6 +10,15 @@ describe("jasmine.Matchers", function() {
10
10
  });
11
11
  });
12
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
+ })
13
22
  });
14
23
 
15
24
  function match(value) {
@@ -20,10 +29,19 @@ describe("jasmine.Matchers", function() {
20
29
  return spec.addMatcherResult.mostRecentCall.args[0];
21
30
  }
22
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
+
23
41
  it("toEqual with primitives, objects, dates, etc.", function() {
24
- expect(match(true).toEqual(true)).toEqual(true);
42
+ expect(match(true).toEqual(true)).toPass();
25
43
 
26
- expect(match({foo:'bar'}).toEqual(null)).toEqual(false);
44
+ expect(match({foo:'bar'}).toEqual(null)).toFail();
27
45
 
28
46
  var functionA = function() {
29
47
  return 'hi';
@@ -31,39 +49,39 @@ describe("jasmine.Matchers", function() {
31
49
  var functionB = function() {
32
50
  return 'hi';
33
51
  };
34
- expect(match({foo:functionA}).toEqual({foo:functionB})).toEqual(false);
35
- expect(match({foo:functionA}).toEqual({foo:functionA})).toEqual(true);
52
+ expect(match({foo:functionA}).toEqual({foo:functionB})).toFail();
53
+ expect(match({foo:functionA}).toEqual({foo:functionA})).toPass();
36
54
 
37
- expect((match(false).toEqual(true))).toEqual(false);
55
+ expect((match(false).toEqual(true))).toFail();
38
56
 
39
57
  var circularGraph = {};
40
58
  circularGraph.referenceToSelf = circularGraph;
41
- expect((match(circularGraph).toEqual(circularGraph))).toEqual(true);
59
+ expect((match(circularGraph).toEqual(circularGraph))).toPass();
42
60
 
43
- expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2009, 1, 3, 15, 17, 19, 1234)))).toEqual(false);
44
- expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2008, 1, 3, 15, 17, 19, 1234)))).toEqual(true);
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();
45
63
 
46
64
 
47
- expect(match(true).toNotEqual(false)).toEqual(true);
48
- expect((match(true).toNotEqual(true))).toEqual(false);
65
+ expect(match(true).toNotEqual(false)).toPass();
66
+ expect((match(true).toNotEqual(true))).toFail();
49
67
 
50
- expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toEqual(false);
51
- expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toEqual(false);
68
+ expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toFail();
69
+ expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toFail();
52
70
 
53
- expect((match(new String("cat")).toEqual("cat"))).toBe(true);
54
- expect((match(new String("cat")).toNotEqual("cat"))).toBe(false);
71
+ expect((match(new String("cat")).toEqual("cat"))).toPass();
72
+ expect((match(new String("cat")).toNotEqual("cat"))).toFail();
55
73
 
56
- expect((match(new Number(5)).toEqual(5))).toBe(true);
57
- expect((match(new Number('5')).toEqual(5))).toBe(true);
58
- expect((match(new Number(5)).toNotEqual(5))).toBe(false);
59
- expect((match(new Number('5')).toNotEqual(5))).toBe(false);
74
+ expect((match(new Number(5)).toEqual(5))).toPass();
75
+ expect((match(new Number('5')).toEqual(5))).toPass();
76
+ expect((match(new Number(5)).toNotEqual(5))).toFail();
77
+ expect((match(new Number('5')).toNotEqual(5))).toFail();
60
78
  });
61
79
 
62
80
  it("toEqual with DOM nodes", function() {
63
81
  var nodeA = document.createElement('div');
64
82
  var nodeB = document.createElement('div');
65
- expect((match(nodeA).toEqual(nodeA))).toEqual(true);
66
- expect((match(nodeA).toEqual(nodeB))).toEqual(false);
83
+ expect((match(nodeA).toEqual(nodeA))).toPass();
84
+ expect((match(nodeA).toEqual(nodeB))).toFail();
67
85
  });
68
86
 
69
87
  it("toEqual to build an Expectation Result", function() {
@@ -75,7 +93,7 @@ describe("jasmine.Matchers", function() {
75
93
  var result = lastResult();
76
94
 
77
95
  expect(result.matcherName).toEqual("toEqual");
78
- expect(result.passed()).toEqual(false);
96
+ expect(result.passed()).toFail();
79
97
  expect(result.message).toMatch(jasmine.pp(actual));
80
98
  expect(result.message).toMatch(jasmine.pp(expected));
81
99
  expect(result.expected).toEqual(expected);
@@ -90,7 +108,7 @@ describe("jasmine.Matchers", function() {
90
108
  var result = lastResult();
91
109
 
92
110
  expect(result.matcherName).toEqual("toNotEqual");
93
- expect(result.passed()).toEqual(false);
111
+ expect(result.passed()).toFail();
94
112
  expect(result.message).toMatch(jasmine.pp(str));
95
113
  expect(result.message).toMatch('not');
96
114
  expect(result.expected).toEqual(str);
@@ -102,12 +120,12 @@ describe("jasmine.Matchers", function() {
102
120
  var b = {};
103
121
  //noinspection UnnecessaryLocalVariableJS
104
122
  var c = a;
105
- expect((match(a).toBe(b))).toEqual(false);
106
- expect((match(a).toBe(a))).toEqual(true);
107
- expect((match(a).toBe(c))).toEqual(true);
108
- expect((match(a).toNotBe(b))).toEqual(true);
109
- expect((match(a).toNotBe(a))).toEqual(false);
110
- expect((match(a).toNotBe(c))).toEqual(false);
123
+ expect((match(a).toBe(b))).toFail();
124
+ expect((match(a).toBe(a))).toPass();
125
+ expect((match(a).toBe(c))).toPass();
126
+ expect((match(a).toNotBe(b))).toPass();
127
+ expect((match(a).toNotBe(a))).toFail();
128
+ expect((match(a).toNotBe(c))).toFail();
111
129
  });
112
130
 
113
131
  it("toBe to build an ExpectationResult", function() {
@@ -119,7 +137,7 @@ describe("jasmine.Matchers", function() {
119
137
  var result = lastResult();
120
138
 
121
139
  expect(result.matcherName).toEqual("toBe");
122
- expect(result.passed()).toEqual(false);
140
+ expect(result.passed()).toFail();
123
141
  expect(result.message).toMatch(jasmine.pp(actual));
124
142
  expect(result.message).toMatch(jasmine.pp(expected));
125
143
  expect(result.expected).toEqual(expected);
@@ -134,24 +152,24 @@ describe("jasmine.Matchers", function() {
134
152
  var result = lastResult();
135
153
 
136
154
  expect(result.matcherName).toEqual("toNotBe");
137
- expect(result.passed()).toEqual(false);
155
+ expect(result.passed()).toFail();
138
156
  expect(result.message).toMatch(str);
139
157
  expect(result.expected).toEqual(str);
140
158
  expect(result.actual).toEqual(str);
141
159
  });
142
160
 
143
161
  it("toMatch and #toNotMatch should perform regular expression matching on strings", function() {
144
- expect((match('foobarbel').toMatch(/bar/))).toEqual(true);
145
- expect((match('foobazbel').toMatch(/bar/))).toEqual(false);
162
+ expect((match('foobarbel').toMatch(/bar/))).toPass();
163
+ expect((match('foobazbel').toMatch(/bar/))).toFail();
146
164
 
147
- expect((match('foobarbel').toMatch("bar"))).toEqual(true);
148
- expect((match('foobazbel').toMatch("bar"))).toEqual(false);
165
+ expect((match('foobarbel').toMatch("bar"))).toPass();
166
+ expect((match('foobazbel').toMatch("bar"))).toFail();
149
167
 
150
- expect((match('foobarbel').toNotMatch(/bar/))).toEqual(false);
151
- expect((match('foobazbel').toNotMatch(/bar/))).toEqual(true);
168
+ expect((match('foobarbel').toNotMatch(/bar/))).toFail();
169
+ expect((match('foobazbel').toNotMatch(/bar/))).toPass();
152
170
 
153
- expect((match('foobarbel').toNotMatch("bar"))).toEqual(false);
154
- expect((match('foobazbel').toNotMatch("bar"))).toEqual(true);
171
+ expect((match('foobarbel').toNotMatch("bar"))).toFail();
172
+ expect((match('foobazbel').toNotMatch("bar"))).toPass();
155
173
  });
156
174
 
157
175
  it("toMatch w/ RegExp to build an ExpectationResult", function() {
@@ -163,7 +181,7 @@ describe("jasmine.Matchers", function() {
163
181
  var result = lastResult();
164
182
 
165
183
  expect(result.matcherName).toEqual("toMatch");
166
- expect(result.passed()).toEqual(false);
184
+ expect(result.passed()).toFail();
167
185
  expect(result.message).toMatch(jasmine.pp(actual));
168
186
  expect(result.message).toMatch(expected.toString());
169
187
  expect(result.expected).toEqual(expected);
@@ -179,7 +197,7 @@ describe("jasmine.Matchers", function() {
179
197
  var result = lastResult();
180
198
 
181
199
  expect(result.matcherName).toEqual("toMatch");
182
- expect(result.passed()).toEqual(false);
200
+ expect(result.passed()).toFail();
183
201
  expect(result.message).toEqual("Expected 'a' to match 'b'.");
184
202
  expect(result.expected).toEqual(expected);
185
203
  expect(result.actual).toEqual(actual);
@@ -194,7 +212,7 @@ describe("jasmine.Matchers", function() {
194
212
  var result = lastResult();
195
213
 
196
214
  expect(result.matcherName).toEqual("toNotMatch");
197
- expect(result.passed()).toEqual(false);
215
+ expect(result.passed()).toFail();
198
216
  expect(result.message).toEqual("Expected 'a' to not match /a/.");
199
217
  expect(result.expected).toEqual(expected);
200
218
  expect(result.actual).toEqual(actual);
@@ -208,15 +226,15 @@ describe("jasmine.Matchers", function() {
208
226
  var result = lastResult();
209
227
 
210
228
  expect(result.matcherName).toEqual("toNotMatch");
211
- expect(result.passed()).toEqual(false);
229
+ expect(result.passed()).toFail();
212
230
  expect(result.message).toEqual("Expected 'a' to not match 'a'.");
213
231
  expect(result.expected).toEqual(str);
214
232
  expect(result.actual).toEqual(str);
215
233
  });
216
234
 
217
235
  it("toBeDefined", function() {
218
- expect(match('foo').toBeDefined()).toEqual(true);
219
- expect(match(jasmine.undefined).toBeDefined()).toEqual(false);
236
+ expect(match('foo').toBeDefined()).toPass();
237
+ expect(match(jasmine.undefined).toBeDefined()).toFail();
220
238
  });
221
239
 
222
240
  it("toBeDefined to build an ExpectationResult", function() {
@@ -226,20 +244,20 @@ describe("jasmine.Matchers", function() {
226
244
  var result = lastResult();
227
245
 
228
246
  expect(result.matcherName).toEqual("toBeDefined");
229
- expect(result.passed()).toEqual(false);
247
+ expect(result.passed()).toFail();
230
248
  expect(result.message).toEqual('Expected undefined to be defined.');
231
249
  expect(result.actual).toEqual(jasmine.undefined);
232
250
  });
233
251
 
234
252
  it("toBeUndefined", function() {
235
- expect(match('foo').toBeUndefined()).toEqual(false);
236
- expect(match(jasmine.undefined).toBeUndefined()).toEqual(true);
253
+ expect(match('foo').toBeUndefined()).toFail();
254
+ expect(match(jasmine.undefined).toBeUndefined()).toPass();
237
255
  });
238
256
 
239
257
  it("toBeNull", function() {
240
- expect(match(null).toBeNull()).toEqual(true);
241
- expect(match(jasmine.undefined).toBeNull()).toEqual(false);
242
- expect(match("foo").toBeNull()).toEqual(false);
258
+ expect(match(null).toBeNull()).toPass();
259
+ expect(match(jasmine.undefined).toBeNull()).toFail();
260
+ expect(match("foo").toBeNull()).toFail();
243
261
  });
244
262
 
245
263
  it("toBeNull w/ String to build an ExpectationResult", function() {
@@ -250,7 +268,7 @@ describe("jasmine.Matchers", function() {
250
268
  var result = lastResult();
251
269
 
252
270
  expect(result.matcherName).toEqual("toBeNull");
253
- expect(result.passed()).toEqual(false);
271
+ expect(result.passed()).toFail();
254
272
  expect(result.message).toMatch(jasmine.pp(actual));
255
273
  expect(result.message).toMatch('null');
256
274
  expect(result.actual).toEqual(actual);
@@ -264,18 +282,18 @@ describe("jasmine.Matchers", function() {
264
282
  var result = lastResult();
265
283
 
266
284
  expect(result.matcherName).toEqual("toBeNull");
267
- expect(result.passed()).toEqual(false);
285
+ expect(result.passed()).toFail();
268
286
  expect(result.message).toMatch(jasmine.pp(actual));
269
287
  expect(result.message).toMatch('null');
270
288
  expect(result.actual).toEqual(actual);
271
289
  });
272
290
 
273
291
  it("toBeFalsy", function() {
274
- expect(match(false).toBeFalsy()).toEqual(true);
275
- expect(match(true).toBeFalsy()).toEqual(false);
276
- expect(match(jasmine.undefined).toBeFalsy()).toEqual(true);
277
- expect(match(0).toBeFalsy()).toEqual(true);
278
- expect(match("").toBeFalsy()).toEqual(true);
292
+ expect(match(false).toBeFalsy()).toPass();
293
+ expect(match(true).toBeFalsy()).toFail();
294
+ expect(match(jasmine.undefined).toBeFalsy()).toPass();
295
+ expect(match(0).toBeFalsy()).toPass();
296
+ expect(match("").toBeFalsy()).toPass();
279
297
  });
280
298
 
281
299
  it("toBeFalsy to build an ExpectationResult", function() {
@@ -286,21 +304,21 @@ describe("jasmine.Matchers", function() {
286
304
  var result = lastResult();
287
305
 
288
306
  expect(result.matcherName).toEqual("toBeFalsy");
289
- expect(result.passed()).toEqual(false);
307
+ expect(result.passed()).toFail();
290
308
  expect(result.message).toMatch(jasmine.pp(actual));
291
309
  expect(result.message).toMatch('falsy');
292
310
  expect(result.actual).toEqual(actual);
293
311
  });
294
312
 
295
313
  it("toBeTruthy", function() {
296
- expect(match(false).toBeTruthy()).toEqual(false);
297
- expect(match(true).toBeTruthy()).toEqual(true);
298
- expect(match(jasmine.undefined).toBeTruthy()).toEqual(false);
299
- expect(match(0).toBeTruthy()).toEqual(false);
300
- expect(match("").toBeTruthy()).toEqual(false);
301
- expect(match("hi").toBeTruthy()).toEqual(true);
302
- expect(match(5).toBeTruthy()).toEqual(true);
303
- expect(match({foo: 1}).toBeTruthy()).toEqual(true);
314
+ expect(match(false).toBeTruthy()).toFail();
315
+ expect(match(true).toBeTruthy()).toPass();
316
+ expect(match(jasmine.undefined).toBeTruthy()).toFail();
317
+ expect(match(0).toBeTruthy()).toFail();
318
+ expect(match("").toBeTruthy()).toFail();
319
+ expect(match("hi").toBeTruthy()).toPass();
320
+ expect(match(5).toBeTruthy()).toPass();
321
+ expect(match({foo: 1}).toBeTruthy()).toPass();
304
322
  });
305
323
 
306
324
  it("toBeTruthy to build an ExpectationResult", function() {
@@ -310,69 +328,69 @@ describe("jasmine.Matchers", function() {
310
328
  var result = lastResult();
311
329
 
312
330
  expect(result.matcherName).toEqual("toBeTruthy");
313
- expect(result.passed()).toEqual(false);
331
+ expect(result.passed()).toFail();
314
332
  expect(result.message).toEqual("Expected false to be truthy.");
315
- expect(result.actual).toEqual(false);
333
+ expect(result.actual).toFail();
316
334
  });
317
335
 
318
336
  it("toEqual", function() {
319
- expect(match(jasmine.undefined).toEqual(jasmine.undefined)).toEqual(true);
320
- expect(match({foo:'bar'}).toEqual({foo:'bar'})).toEqual(true);
321
- expect(match("foo").toEqual({bar: jasmine.undefined})).toEqual(false);
322
- expect(match({foo: jasmine.undefined}).toEqual("goo")).toEqual(false);
323
- expect(match({foo: {bar :jasmine.undefined}}).toEqual("goo")).toEqual(false);
337
+ expect(match(jasmine.undefined).toEqual(jasmine.undefined)).toPass();
338
+ expect(match({foo:'bar'}).toEqual({foo:'bar'})).toPass();
339
+ expect(match("foo").toEqual({bar: jasmine.undefined})).toFail();
340
+ expect(match({foo: jasmine.undefined}).toEqual("goo")).toFail();
341
+ expect(match({foo: {bar :jasmine.undefined}}).toEqual("goo")).toFail();
324
342
  });
325
343
 
326
344
  it("toEqual with jasmine.any()", function() {
327
- expect(match("foo").toEqual(jasmine.any(String))).toEqual(true);
328
- expect(match(3).toEqual(jasmine.any(Number))).toEqual(true);
329
- expect(match("foo").toEqual(jasmine.any(Function))).toEqual(false);
330
- expect(match("foo").toEqual(jasmine.any(Object))).toEqual(false);
331
- expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toEqual(true);
332
- expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toEqual(false);
345
+ expect(match("foo").toEqual(jasmine.any(String))).toPass();
346
+ expect(match(3).toEqual(jasmine.any(Number))).toPass();
347
+ expect(match("foo").toEqual(jasmine.any(Function))).toFail();
348
+ expect(match("foo").toEqual(jasmine.any(Object))).toFail();
349
+ expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toPass();
350
+ expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toFail();
333
351
  expect(match(function() {
334
- }).toEqual(jasmine.any(Object))).toEqual(false);
335
- expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toEqual(true);
352
+ }).toEqual(jasmine.any(Object))).toFail();
353
+ expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toPass();
336
354
  expect(match(function() {
337
- }).toEqual(jasmine.any(Function))).toEqual(true);
355
+ }).toEqual(jasmine.any(Function))).toPass();
338
356
  expect(match(["a", function() {
339
- }]).toEqual(["a", jasmine.any(Function)])).toEqual(true);
357
+ }]).toEqual(["a", jasmine.any(Function)])).toPass();
340
358
  });
341
359
 
342
360
  it("toEqual handles circular objects ok", function() {
343
- expect(match({foo: "bar", baz: jasmine.undefined}).toEqual({foo: "bar", baz: jasmine.undefined})).toEqual(true);
344
- expect(match({foo:['bar','baz','quux']}).toEqual({foo:['bar','baz','quux']})).toEqual(true);
345
- expect(match({foo: {bar:'baz'}, quux:'corge'}).toEqual({foo:{bar:'baz'}, quux:'corge'})).toEqual(true);
361
+ expect(match({foo: "bar", baz: jasmine.undefined}).toEqual({foo: "bar", baz: jasmine.undefined})).toPass();
362
+ expect(match({foo:['bar','baz','quux']}).toEqual({foo:['bar','baz','quux']})).toPass();
363
+ expect(match({foo: {bar:'baz'}, quux:'corge'}).toEqual({foo:{bar:'baz'}, quux:'corge'})).toPass();
346
364
 
347
365
  var circularObject = {};
348
366
  var secondCircularObject = {};
349
367
  circularObject.field = circularObject;
350
368
  secondCircularObject.field = secondCircularObject;
351
- expect(match(circularObject).toEqual(secondCircularObject)).toEqual(true);
369
+ expect(match(circularObject).toEqual(secondCircularObject)).toPass();
352
370
  });
353
371
 
354
372
  it("toNotEqual as slightly surprising behavior, but is it intentional?", function() {
355
- expect(match({x:"x", y:"y", z:"w"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
356
- expect(match({x:"x", y:"y", w:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
357
- expect(match({x:"x", y:"y", z:"z"}).toNotEqual({w: "w", x:"x", y:"y", z:"z"})).toEqual(true);
358
- expect(match({w: "w", x:"x", y:"y", z:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
373
+ expect(match({x:"x", y:"y", z:"w"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
374
+ expect(match({x:"x", y:"y", w:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
375
+ expect(match({x:"x", y:"y", z:"z"}).toNotEqual({w: "w", x:"x", y:"y", z:"z"})).toPass();
376
+ expect(match({w: "w", x:"x", y:"y", z:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
359
377
  });
360
378
 
361
379
  it("toEqual handles arrays", function() {
362
- expect(match([1, "A"]).toEqual([1, "A"])).toEqual(true);
380
+ expect(match([1, "A"]).toEqual([1, "A"])).toPass();
363
381
  });
364
382
 
365
383
  it("toContain and toNotContain", function() {
366
- expect(match('ABC').toContain('A')).toEqual(true);
367
- expect(match('ABC').toContain('X')).toEqual(false);
384
+ expect(match('ABC').toContain('A')).toPass();
385
+ expect(match('ABC').toContain('X')).toFail();
368
386
 
369
- expect(match(['A', 'B', 'C']).toContain('A')).toEqual(true);
370
- expect(match(['A', 'B', 'C']).toContain('F')).toEqual(false);
371
- expect(match(['A', 'B', 'C']).toNotContain('F')).toEqual(true);
372
- expect(match(['A', 'B', 'C']).toNotContain('A')).toEqual(false);
387
+ expect(match(['A', 'B', 'C']).toContain('A')).toPass();
388
+ expect(match(['A', 'B', 'C']).toContain('F')).toFail();
389
+ expect(match(['A', 'B', 'C']).toNotContain('F')).toPass();
390
+ expect(match(['A', 'B', 'C']).toNotContain('A')).toFail();
373
391
 
374
- expect(match(['A', {some:'object'}, 'C']).toContain({some:'object'})).toEqual(true);
375
- expect(match(['A', {some:'object'}, 'C']).toContain({some:'other object'})).toEqual(false);
392
+ expect(match(['A', {some:'object'}, 'C']).toContain({some:'object'})).toPass();
393
+ expect(match(['A', {some:'object'}, 'C']).toContain({some:'other object'})).toFail();
376
394
  });
377
395
 
378
396
  it("toContain to build an ExpectationResult", function() {
@@ -384,7 +402,7 @@ describe("jasmine.Matchers", function() {
384
402
  var result = lastResult();
385
403
 
386
404
  expect(result.matcherName).toEqual("toContain");
387
- expect(result.passed()).toEqual(false);
405
+ expect(result.passed()).toFail();
388
406
  expect(result.message).toMatch(jasmine.pp(actual));
389
407
  expect(result.message).toMatch('contain');
390
408
  expect(result.message).toMatch(jasmine.pp(expected));
@@ -401,7 +419,7 @@ describe("jasmine.Matchers", function() {
401
419
  var result = lastResult();
402
420
 
403
421
  expect(result.matcherName).toEqual("toNotContain");
404
- expect(result.passed()).toEqual(false);
422
+ expect(result.passed()).toFail();
405
423
  expect(result.message).toMatch(jasmine.pp(actual));
406
424
  expect(result.message).toMatch('not contain');
407
425
  expect(result.message).toMatch(jasmine.pp(expected));
@@ -410,9 +428,9 @@ describe("jasmine.Matchers", function() {
410
428
  });
411
429
 
412
430
  it("toBeLessThan should pass if actual is less than expected", function() {
413
- expect(match(37).toBeLessThan(42)).toEqual(true);
414
- expect(match(37).toBeLessThan(-42)).toEqual(false);
415
- expect(match(37).toBeLessThan(37)).toEqual(false);
431
+ expect(match(37).toBeLessThan(42)).toPass();
432
+ expect(match(37).toBeLessThan(-42)).toFail();
433
+ expect(match(37).toBeLessThan(37)).toFail();
416
434
  });
417
435
 
418
436
  it("toBeLessThan to build an ExpectationResult", function() {
@@ -424,7 +442,7 @@ describe("jasmine.Matchers", function() {
424
442
  var result = lastResult();
425
443
 
426
444
  expect(result.matcherName).toEqual("toBeLessThan");
427
- expect(result.passed()).toEqual(false);
445
+ expect(result.passed()).toFail();
428
446
  expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
429
447
  expect(result.message).toMatch(jasmine.pp(expected));
430
448
  expect(result.actual).toEqual(actual);
@@ -432,9 +450,9 @@ describe("jasmine.Matchers", function() {
432
450
  });
433
451
 
434
452
  it("toBeGreaterThan should pass if actual is greater than expected", function() {
435
- expect(match(37).toBeGreaterThan(42)).toEqual(false);
436
- expect(match(37).toBeGreaterThan(-42)).toEqual(true);
437
- expect(match(37).toBeGreaterThan(37)).toEqual(false);
453
+ expect(match(37).toBeGreaterThan(42)).toFail();
454
+ expect(match(37).toBeGreaterThan(-42)).toPass();
455
+ expect(match(37).toBeGreaterThan(37)).toFail();
438
456
  });
439
457
 
440
458
  it("toBeGreaterThan to build an ExpectationResult", function() {
@@ -446,54 +464,95 @@ describe("jasmine.Matchers", function() {
446
464
  var result = lastResult();
447
465
 
448
466
  expect(result.matcherName).toEqual("toBeGreaterThan");
449
- expect(result.passed()).toEqual(false);
467
+ expect(result.passed()).toFail();
450
468
  expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
451
469
  expect(result.message).toMatch(jasmine.pp(expected));
452
470
  expect(result.actual).toEqual(actual);
453
471
  expect(result.expected).toEqual(expected);
454
472
  });
455
473
 
456
- it("toThrow", function() {
457
- var expected = match(function() {
458
- throw new Error("Fake Error");
459
- });
460
- expect(expected.toThrow()).toEqual(true);
461
- expect(expected.toThrow("Fake Error")).toEqual(true);
462
- expect(expected.toThrow(new Error("Fake Error"))).toEqual(true);
474
+ describe("toThrow", function() {
475
+ describe("when code block throws an exception", function() {
476
+ var throwingFn;
463
477
 
464
- expect(expected.toThrow("Other Error")).toEqual(false);
465
- var result = lastResult();
466
- expect(result.message).toMatch("Other Error");
478
+ beforeEach(function() {
479
+ throwingFn = function() {
480
+ throw new Error("Fake Error");
481
+ };
482
+ });
467
483
 
468
- expect(expected.toThrow(new Error("Other Error"))).toEqual(false);
469
- result = lastResult();
470
- expect(result.message).toMatch("Other Error");
484
+ it("should match any exception", function() {
485
+ expect(match(throwingFn).toThrow()).toPass();
486
+ });
471
487
 
472
- var exception;
473
- try {
474
- (function () {
475
- new jasmine.Matchers(env, 'not-a-function', spec).toThrow();
476
- })();
477
- } catch (e) {
478
- exception = e;
479
- }
488
+ it("should match exceptions specified by message", function() {
489
+ expect(match(throwingFn).toThrow("Fake Error")).toPass();
490
+ expect(match(throwingFn).toThrow("Other Error")).toFail();
491
+ expect(lastResult().message).toMatch("Other Error");
492
+ });
480
493
 
481
- expect(exception).toBeDefined();
482
- expect(exception.message).toEqual('Actual is not a function');
494
+ it("should match exceptions specified by Error", function() {
495
+ expect(match(throwingFn).toThrow(new Error("Fake Error"))).toPass();
496
+ expect(match(throwingFn).toThrow(new Error("Other Error"))).toFail();
497
+ expect(lastResult().message).toMatch("Other Error");
498
+ });
483
499
 
500
+ describe("and matcher is inverted with .not", function() {
501
+ it("should match any exception", function() {
502
+ expect(match(throwingFn).not.toThrow()).toFail();
503
+ expect(lastResult().message).toMatch(/Expected function not to throw an exception/);
504
+ });
484
505
 
485
- expect(match(function() {
486
- }).toThrow()).toEqual(false);
487
- result = lastResult();
488
- expect(result.message).toEqual('Expected function to throw an exception.');
506
+ it("should match exceptions specified by message", function() {
507
+ expect(match(throwingFn).not.toThrow("Fake Error")).toFail();
508
+ // expect(lastResult().message).toMatch(/Expected function not to throw Fake Error./);
509
+ expect(match(throwingFn).not.toThrow("Other Error")).toPass();
510
+ });
511
+
512
+ it("should match exceptions specified by Error", function() {
513
+ expect(match(throwingFn).not.toThrow(new Error("Fake Error"))).toFail();
514
+ // expect(lastResult().message).toMatch("Other Error");
515
+ expect(match(throwingFn).not.toThrow(new Error("Other Error"))).toPass();
516
+ });
517
+ });
518
+ });
519
+
520
+ describe("when actual is not a function", function() {
521
+ it("should fail with an exception", function() {
522
+ var exception = catchException(function() {
523
+ match('not-a-function').toThrow();
524
+ });
525
+ expect(exception).toBeDefined();
526
+ expect(exception.message).toEqual('Actual is not a function');
527
+ });
528
+
529
+ describe("and matcher is inverted with .not", function() {
530
+ it("should fail with an exception", function() {
531
+ var exception = catchException(function() {
532
+ match('not-a-function').not.toThrow();
533
+ });
534
+ expect(exception).toBeDefined();
535
+ expect(exception.message).toEqual('Actual is not a function');
536
+ });
537
+ });
538
+ });
539
+
540
+
541
+ describe("when code block does not throw an exception", function() {
542
+ it("should fail (or pass when inverted with .not)", function() {
543
+ expect(match(function() {
544
+ }).toThrow()).toFail();
545
+ expect(lastResult().message).toEqual('Expected function to throw an exception.');
546
+ });
547
+ });
489
548
  });
490
549
 
491
550
  describe(".not.matcher", function() {
492
551
  it("should invert the sense of any matcher", function() {
493
- expect(match(37).not.toBeGreaterThan(42)).toEqual(true);
494
- expect(match(42).not.toBeGreaterThan(37)).toEqual(false);
495
- expect(match("abc").not.toEqual("def")).toEqual(true);
496
- expect(match("abc").not.toEqual("abc")).toEqual(false);
552
+ expect(match(37).not.toBeGreaterThan(42)).toPass();
553
+ expect(match(42).not.toBeGreaterThan(37)).toFail();
554
+ expect(match("abc").not.toEqual("def")).toPass();
555
+ expect(match("abc").not.toEqual("abc")).toFail();
497
556
  });
498
557
 
499
558
  it("should provide an inverted default message", function() {
@@ -557,10 +616,10 @@ describe("jasmine.Matchers", function() {
557
616
 
558
617
  describe("toHaveBeenCalled", function() {
559
618
  it("should pass if the spy was called", function() {
560
- expect(match(TestClass.spyFunction).toHaveBeenCalled()).toEqual(false);
619
+ expect(match(TestClass.spyFunction).toHaveBeenCalled()).toFail();
561
620
 
562
621
  TestClass.spyFunction();
563
- expect(match(TestClass.spyFunction).toHaveBeenCalled()).toEqual(true);
622
+ expect(match(TestClass.spyFunction).toHaveBeenCalled()).toPass();
564
623
  });
565
624
 
566
625
  it("should throw an exception when invoked with any arguments", function() {
@@ -585,10 +644,10 @@ describe("jasmine.Matchers", function() {
585
644
 
586
645
  describe("wasNotCalled", function() {
587
646
  it("should pass iff the spy was not called", function() {
588
- expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(true);
647
+ expect(match(TestClass.spyFunction).wasNotCalled()).toPass();
589
648
 
590
649
  TestClass.spyFunction();
591
- expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(false);
650
+ expect(match(TestClass.spyFunction).wasNotCalled()).toFail();
592
651
  });
593
652
 
594
653
  it("should throw an exception when invoked with any arguments", function() {
@@ -603,15 +662,15 @@ describe("jasmine.Matchers", function() {
603
662
  describe("toHaveBeenCalledWith", function() {
604
663
  it('toHaveBeenCalledWith should return true if it was called with the expected args', function() {
605
664
  TestClass.spyFunction('a', 'b', 'c');
606
- expect(match(TestClass.spyFunction).toHaveBeenCalledWith('a', 'b', 'c')).toEqual(true);
665
+ expect(match(TestClass.spyFunction).toHaveBeenCalledWith('a', 'b', 'c')).toPass();
607
666
  });
608
667
 
609
668
  it('should return false if it was not called with the expected args', function() {
610
669
  TestClass.spyFunction('a', 'b', 'c');
611
670
  var expected = match(TestClass.spyFunction);
612
- expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toEqual(false);
671
+ expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail();
613
672
  var result = lastResult();
614
- expect(result.passed()).toEqual(false);
673
+ expect(result.passed()).toFail();
615
674
  expect(result.expected).toEqual(['c', 'b', 'a']);
616
675
  expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
617
676
  expect(result.message).toContain(jasmine.pp(result.expected));
@@ -620,21 +679,37 @@ describe("jasmine.Matchers", function() {
620
679
 
621
680
  it('should return false if it was not called', function() {
622
681
  var expected = match(TestClass.spyFunction);
623
- expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toEqual(false);
682
+ expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail();
624
683
  var result = lastResult();
625
- expect(result.passed()).toEqual(false);
684
+ expect(result.passed()).toFail();
626
685
  expect(result.expected).toEqual(['c', 'b', 'a']);
627
686
  expect(result.actual.argsForCall).toEqual([]);
628
687
  expect(result.message).toContain(jasmine.pp(result.expected));
629
688
  });
630
689
 
631
690
  it('should allow matches across multiple calls', function() {
691
+ TestClass.spyFunction('a', 'b', 'c');
692
+ TestClass.spyFunction('d', 'e', 'f');
632
693
  var expected = match(TestClass.spyFunction);
694
+ expect(expected.toHaveBeenCalledWith('a', 'b', 'c')).toPass();
695
+ expect(expected.toHaveBeenCalledWith('d', 'e', 'f')).toPass();
696
+ expect(expected.toHaveBeenCalledWith('x', 'y', 'z')).toFail();
697
+ });
698
+
699
+ it("should return a decent message", function() {
633
700
  TestClass.spyFunction('a', 'b', 'c');
634
701
  TestClass.spyFunction('d', 'e', 'f');
635
- expect(expected.toHaveBeenCalledWith('a', 'b', 'c')).toEqual(true);
636
- expect(expected.toHaveBeenCalledWith('d', 'e', 'f')).toEqual(true);
637
- expect(expected.toHaveBeenCalledWith('x', 'y', 'z')).toEqual(false);
702
+ var expected = match(TestClass.spyFunction);
703
+ expect(expected.toHaveBeenCalledWith('a', 'b')).toFail();
704
+ expect(lastResult().message).toEqual("Expected spy to have been called with [ 'a', 'b' ] but was called with [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]");
705
+ });
706
+
707
+ it("should return a decent message when inverted", function() {
708
+ TestClass.spyFunction('a', 'b', 'c');
709
+ TestClass.spyFunction('d', 'e', 'f');
710
+ var expected = match(TestClass.spyFunction);
711
+ expect(expected.not.toHaveBeenCalledWith('a', 'b', 'c')).toFail();
712
+ expect(lastResult().message).toEqual("Expected spy not to have been called with [ 'a', 'b', 'c' ] but was called with [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]");
638
713
  });
639
714
 
640
715
  it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalledWith'));
@@ -658,7 +733,7 @@ describe("jasmine.Matchers", function() {
658
733
 
659
734
  var result = lastResult();
660
735
  expect(result.matcherName).toEqual("toHaveBeenCalledWith");
661
- expect(result.passed()).toEqual(false);
736
+ expect(result.passed()).toFail();
662
737
  expect(result.message).toContain(jasmine.pp(['a', 'b']));
663
738
  expect(result.message).toContain(jasmine.pp(['a', 'c']));
664
739
  expect(result.actual).toEqual(TestClass.someFunction);
@@ -680,15 +755,15 @@ describe("jasmine.Matchers", function() {
680
755
  describe("wasNotCalledWith", function() {
681
756
  it('should return true if the spy was NOT called with the expected args', function() {
682
757
  TestClass.spyFunction('a', 'b', 'c');
683
- expect(match(TestClass.spyFunction).wasNotCalledWith('c', 'b', 'a')).toEqual(true);
758
+ expect(match(TestClass.spyFunction).wasNotCalledWith('c', 'b', 'a')).toPass();
684
759
  });
685
760
 
686
761
  it('should return false if it WAS called with the expected args', function() {
687
762
  TestClass.spyFunction('a', 'b', 'c');
688
763
  var expected = match(TestClass.spyFunction);
689
- expect(expected.wasNotCalledWith('a', 'b', 'c')).toEqual(false);
764
+ expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail();
690
765
  var result = lastResult();
691
- expect(result.passed()).toEqual(false);
766
+ expect(result.passed()).toFail();
692
767
  expect(result.expected).toEqual(['a', 'b', 'c']);
693
768
  expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
694
769
  expect(result.message).toContain(jasmine.pp(result.expected));
@@ -696,21 +771,25 @@ describe("jasmine.Matchers", function() {
696
771
 
697
772
  it('should return true if it was not called', function() {
698
773
  var expected = match(TestClass.spyFunction);
699
- expect(expected.wasNotCalledWith('c', 'b', 'a')).toEqual(true);
774
+ expect(expected.wasNotCalledWith('c', 'b', 'a')).toPass();
700
775
  });
701
776
 
702
777
  it('should allow matches across multiple calls', function() {
703
778
  var expected = match(TestClass.spyFunction);
704
779
  TestClass.spyFunction('a', 'b', 'c');
705
780
  TestClass.spyFunction('d', 'e', 'f');
706
- expect(expected.wasNotCalledWith('a', 'b', 'c')).toEqual(false);
707
- expect(expected.wasNotCalledWith('d', 'e', 'f')).toEqual(false);
708
- expect(expected.wasNotCalledWith('x', 'y', 'z')).toEqual(true);
781
+ expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail();
782
+ expect(expected.wasNotCalledWith('d', 'e', 'f')).toFail();
783
+ expect(expected.wasNotCalledWith('x', 'y', 'z')).toPass();
709
784
  });
710
785
 
711
786
  it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalledWith'));
712
-
713
787
  });
788
+ });
714
789
 
790
+ describe("all matchers", function() {
791
+ it("should return null, for future-proofing, since we might eventually allow matcher chaining", function() {
792
+ expect(match(true).toBe(true)).toBeUndefined();
793
+ });
715
794
  });
716
795
  });