diff --git a/doc/files.html b/doc/files.html index d4f45ac..dd38626 100644 --- a/doc/files.html +++ b/doc/files.html @@ -194,6 +194,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -258,7 +260,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    \ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 6776f4c..7413bd4 100644 --- a/doc/index.html +++ b/doc/index.html @@ -194,6 +194,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -248,6 +250,12 @@ ul.inheritsList
    +
    +

    jasmine.Matchers

    + +
    +
    +

    jasmine.MultiReporter

    @@ -300,7 +308,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    \ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 88e6b7e..c11f55b 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -908,7 +910,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index 89eb241..74b37ef 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -339,7 +341,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 41c689f..f085258 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -507,7 +509,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 092d343..680bd84 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -316,7 +318,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html new file mode 100644 index 0000000..354af43 --- /dev/null +++ b/doc/symbols/jasmine.Matchers.html @@ -0,0 +1,1018 @@ + + + + + + + JsDoc Reference - jasmine.Matchers + + + + + + + + + + + +
    + +
    Class Index +| File Index
    +
    +

    Classes

    + +
    + +
    + +
    + +

    + + Class jasmine.Matchers +

    + + +

    + + + + + +
    Defined in: jasmine-0.10.0.js. + +

    + + + + + + + + + + + + + + + + + +
    Class Summary
    Constructor AttributesConstructor Name and Description
      +
    + jasmine.Matchers(env, actual, results) +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Method Summary
    Method AttributesMethod Name and Description
      +
    toBe(expected) +
    +
    Matcher that compares the actual to the expected using ===.
    +
      + +
    Matcher that compares the acutal to undefined.
    +
      + +
    Matcher that boolean nots the actual.
    +
      + +
    Matcher that compares the actual to null.
    +
      + +
    Matcher that boolean not-nots the actual.
    +
      +
    toContain(item) +
    +
    Matcher that checks that the expected item is an element in the actual Array.
    +
      +
    toEqual(expected) +
    +
    Matcher that compares the actual to the expected using common sense equality.
    +
      +
    toMatch(reg_exp) +
    +
    Matcher that compares the actual to the expected using a regular expression.
    +
      +
    toNotBe(expected) +
    +
    Matcher that compares the actual to the expected using !==
    +
      +
    toNotContain(item) +
    +
    Matcher that checks that the expected item is NOT an element in the actual Array.
    +
      +
    toNotEqual(expected) +
    +
    Matcher that compares the actual to the expected using the ! of jasmine.Matchers.toEqual
    +
      +
    toNotMatch(reg_exp) +
    +
    Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
    +
      +
    toThrow(expectedException) +
    +
    Matcher that checks that the expected exception was thrown by the actual.
    +
      + +
    Matcher that checks to see if the acutal, a Jasmine spy, was called.
    +
      + +
    Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters.
    +
      + +
    Matcher that checks to see if the acutal, a Jasmine spy, was not called.
    +
    + + + + + + + + + +
    +
    + Class Detail +
    + +
    + jasmine.Matchers(env, actual, results) +
    + +
    + + +
    + + + + + +
    +
    Parameters:
    + +
    + {jasmine.Env} env + +
    +
    + +
    + actual + +
    +
    + +
    + {jasmine.NestedResults} results + +
    +
    + +
    + + + + + + + + +
    + + + + + + + +
    + Method Detail +
    + + +
    + + + toBe(expected) + +
    +
    + Matcher that compares the actual to the expected using ===. + + +
    + + + + +
    +
    Parameters:
    + +
    + expected + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + toBeDefined() + +
    +
    + Matcher that compares the acutal to undefined. + + +
    + + + + + + + + + + + +
    + + +
    + + + toBeFalsy() + +
    +
    + Matcher that boolean nots the actual. + + +
    + + + + + + + + + + + +
    + + +
    + + + toBeNull() + +
    +
    + Matcher that compares the actual to null. + + +
    + + + + + + + + + + + +
    + + +
    + + + toBeTruthy() + +
    +
    + Matcher that boolean not-nots the actual. + + +
    + + + + + + + + + + + +
    + + +
    + + + toContain(item) + +
    +
    + Matcher that checks that the expected item is an element in the actual Array. + + +
    + + + + +
    +
    Parameters:
    + +
    + {Object} item + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + toEqual(expected) + +
    +
    + Matcher that compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. + + +
    + + + + +
    +
    Parameters:
    + +
    + expected + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + toMatch(reg_exp) + +
    +
    + Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +a pattern or a String. + + +
    + + + + +
    +
    Parameters:
    + +
    + reg_exp + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + toNotBe(expected) + +
    +
    + Matcher that compares the actual to the expected using !== + + +
    + + + + +
    +
    Parameters:
    + +
    + expected + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + toNotContain(item) + +
    +
    + Matcher that checks that the expected item is NOT an element in the actual Array. + + +
    + + + + +
    +
    Parameters:
    + +
    + {Object} item + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + toNotEqual(expected) + +
    +
    + Matcher that compares the actual to the expected using the ! of jasmine.Matchers.toEqual + + +
    + + + + +
    +
    Parameters:
    + +
    + expected + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + toNotMatch(reg_exp) + +
    +
    + Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch + + +
    + + + + +
    +
    Parameters:
    + +
    + reg_exp + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + toThrow(expectedException) + +
    +
    + Matcher that checks that the expected exception was thrown by the actual. + + +
    + + + + +
    +
    Parameters:
    + +
    + {String} expectedException + +
    +
    + +
    + + + + + + + + +
    + + +
    + + + wasCalled() + +
    +
    + Matcher that checks to see if the acutal, a Jasmine spy, was called. + + +
    + + + + + + + + + + + +
    + + +
    + + + wasCalledWith() + +
    +
    + Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. + + +
    + + + +
    
    +					
    +					
    +					
    +						
    +						
    +						
    +						
    +						
    +						
    +						
    +
    +					
    + + +
    + + + wasNotCalled() + +
    +
    + Matcher that checks to see if the acutal, a Jasmine spy, was not called. + + +
    + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT) +
    + + diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 953a3bd..4583077 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -316,7 +318,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index 104e3b3..297c8ef 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -700,7 +702,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 88a9edc..75d611b 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -316,7 +318,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index 36b7c6b..33a0020 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -327,7 +329,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index 686bf44..50f500d 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -339,7 +341,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index e2ea450..55d0e19 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -845,7 +847,7 @@ expect(foo.bar.callCount).toEqual(0);
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index cc06f7e..29f8593 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -345,7 +347,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index 6a0e168..8196f3e 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -353,15 +355,6 @@ Jasmine environment. - - <static>   - -
    jasmine.Matchers(env,, actual, results) -
    -
    - - - <static>   @@ -655,54 +648,6 @@ Jasmine environment. -
    - - -
    <static> - - - jasmine.Matchers(env,, actual, results) - -
    -
    - - - -
    - - - - -
    -
    Parameters:
    - -
    - env, - -
    -
    actual, results
    - -
    - actual - -
    -
    - -
    - results - -
    -
    - -
    - - - - - - - -
    @@ -785,7 +730,7 @@ Jasmine environment.
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index b8053ea..4540ba5 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -199,6 +199,8 @@ ul.inheritsList
  • jasmine.JsApiReporter
  • +
  • jasmine.Matchers
  • +
  • jasmine.MultiReporter
  • jasmine.NestedResults
  • @@ -316,7 +318,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 13:32:51 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Tue Oct 27 2009 16:48:57 GMT-0700 (PDT)
    diff --git a/doc/symbols/src/lib_jasmine-0.10.0.js.html b/doc/symbols/src/lib_jasmine-0.10.0.js.html index f3553c5..1d3f0b1 100644 --- a/doc/symbols/src/lib_jasmine-0.10.0.js.html +++ b/doc/symbols/src/lib_jasmine-0.10.0.js.html @@ -537,7 +537,7 @@ 530 "major": 0, 531 "minor": 10, 532 "build": 0, -533 "revision": 1256675463 +533 "revision": 1256686889 534 }; 535 /** 536 * @namespace @@ -974,1181 +974,1184 @@ 967 }; 968 969 /** -970 * @param env, actual, results -971 */ -972 jasmine.Matchers = function(env, actual, results) { -973 this.env = env; -974 this.actual = actual; -975 this.passing_message = 'Passed.'; -976 this.results_ = results || new jasmine.NestedResults(); -977 }; -978 -979 jasmine.Matchers.pp = function(str) { -980 return jasmine.util.htmlEscape(jasmine.pp(str)); -981 }; -982 -983 jasmine.Matchers.prototype.results = function() { -984 return this.results_; -985 }; -986 -987 jasmine.Matchers.prototype.report = function(result, failing_message, details) { -988 this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); -989 return result; -990 }; -991 -992 /** -993 * Matcher that compares the actual to the expected using ===. -994 * -995 * @param expected -996 */ -997 jasmine.Matchers.prototype.toBe = function(expected) { -998 return this.report(this.actual === expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -999 + '<br /><br />to be the same object as<br /><br />' + jasmine.Matchers.pp(this.actual) -1000 + '<br />'); -1001 }; -1002 -1003 /** -1004 * Matcher that compares the actual to the expected using !== -1005 * @param expected -1006 */ -1007 jasmine.Matchers.prototype.toNotBe = function(expected) { -1008 return this.report(this.actual !== expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -1009 + '<br /><br />to be a different object from actual, but they were the same.'); -1010 }; -1011 -1012 /** -1013 * Matcher that compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. -1014 * -1015 * @param expected -1016 */ -1017 jasmine.Matchers.prototype.toEqual = function(expected) { -1018 var mismatchKeys = []; -1019 var mismatchValues = []; -1020 -1021 var formatMismatches = function(name, array) { -1022 if (array.length == 0) return ''; -1023 var errorOutput = '<br /><br />Different ' + name + ':<br />'; -1024 for (var i = 0; i < array.length; i++) { -1025 errorOutput += array[i] + '<br />'; -1026 } -1027 return errorOutput; -1028 }; -1029 -1030 return this.report(this.env.equals_(this.actual, expected, mismatchKeys, mismatchValues), -1031 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -1032 + '<br /><br />but got<br /><br />' + jasmine.Matchers.pp(this.actual) -1033 + '<br />' -1034 + formatMismatches('Keys', mismatchKeys) -1035 + formatMismatches('Values', mismatchValues), { -1036 matcherName: 'toEqual', expected: expected, actual: this.actual -1037 }); -1038 }; -1039 -1040 /** -1041 * Matcher that compares the actual to the expected using the ! of jasmine.Matchers.toEqual -1042 * @param expected -1043 */ -1044 jasmine.Matchers.prototype.toNotEqual = function(expected) { -1045 return this.report(!this.env.equals_(this.actual, expected), -1046 'Expected ' + jasmine.Matchers.pp(expected) + ' to not equal ' + jasmine.Matchers.pp(this.actual) + ', but it does.'); -1047 }; -1048 -1049 /** -1050 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes -1051 * a pattern or a String. -1052 * -1053 * @param reg_exp -1054 */ -1055 jasmine.Matchers.prototype.toMatch = function(reg_exp) { -1056 return this.report((new RegExp(reg_exp).test(this.actual)), -1057 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to match ' + reg_exp + '.'); -1058 }; -1059 -1060 /** -1061 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -1062 * @param reg_exp -1063 */ -1064 jasmine.Matchers.prototype.toNotMatch = function(reg_exp) { -1065 return this.report((!new RegExp(reg_exp).test(this.actual)), -1066 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to not match ' + reg_exp + '.'); -1067 }; -1068 -1069 /** -1070 * Matcher that compares the acutal to undefined. -1071 */ -1072 jasmine.Matchers.prototype.toBeDefined = function() { -1073 return this.report((this.actual !== undefined), -1074 'Expected a value to be defined but it was undefined.'); -1075 }; -1076 -1077 /** -1078 * Matcher that compares the actual to null. -1079 * -1080 */ -1081 jasmine.Matchers.prototype.toBeNull = function() { -1082 return this.report((this.actual === null), -1083 'Expected a value to be null but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1084 }; -1085 -1086 /** -1087 * Matcher that boolean not-nots the actual. -1088 */ -1089 jasmine.Matchers.prototype.toBeTruthy = function() { -1090 return this.report(!!this.actual, -1091 'Expected a value to be truthy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1092 }; -1093 -1094 /** -1095 * Matcher that boolean nots the actual. -1096 */ -1097 jasmine.Matchers.prototype.toBeFalsy = function() { -1098 return this.report(!this.actual, -1099 'Expected a value to be falsy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1100 }; -1101 -1102 /** -1103 * Matcher that checks to see if the acutal, a Jasmine spy, was called. -1104 */ -1105 jasmine.Matchers.prototype.wasCalled = function() { -1106 if (!this.actual || !this.actual.isSpy) { -1107 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -1108 } -1109 if (arguments.length > 0) { -1110 return this.report(false, 'wasCalled matcher does not take arguments'); +970 * @constructor +971 * @param {jasmine.Env} env +972 * @param actual +973 * @param {jasmine.NestedResults} results +974 */ +975 jasmine.Matchers = function(env, actual, results) { +976 this.env = env; +977 this.actual = actual; +978 this.passing_message = 'Passed.'; +979 this.results_ = results || new jasmine.NestedResults(); +980 }; +981 +982 jasmine.Matchers.pp = function(str) { +983 return jasmine.util.htmlEscape(jasmine.pp(str)); +984 }; +985 +986 jasmine.Matchers.prototype.results = function() { +987 return this.results_; +988 }; +989 +990 jasmine.Matchers.prototype.report = function(result, failing_message, details) { +991 this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); +992 return result; +993 }; +994 +995 /** +996 * Matcher that compares the actual to the expected using ===. +997 * +998 * @param expected +999 */ +1000 jasmine.Matchers.prototype.toBe = function(expected) { +1001 return this.report(this.actual === expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +1002 + '<br /><br />to be the same object as<br /><br />' + jasmine.Matchers.pp(this.actual) +1003 + '<br />'); +1004 }; +1005 +1006 /** +1007 * Matcher that compares the actual to the expected using !== +1008 * @param expected +1009 */ +1010 jasmine.Matchers.prototype.toNotBe = function(expected) { +1011 return this.report(this.actual !== expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +1012 + '<br /><br />to be a different object from actual, but they were the same.'); +1013 }; +1014 +1015 /** +1016 * Matcher that compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. +1017 * +1018 * @param expected +1019 */ +1020 jasmine.Matchers.prototype.toEqual = function(expected) { +1021 var mismatchKeys = []; +1022 var mismatchValues = []; +1023 +1024 var formatMismatches = function(name, array) { +1025 if (array.length == 0) return ''; +1026 var errorOutput = '<br /><br />Different ' + name + ':<br />'; +1027 for (var i = 0; i < array.length; i++) { +1028 errorOutput += array[i] + '<br />'; +1029 } +1030 return errorOutput; +1031 }; +1032 +1033 return this.report(this.env.equals_(this.actual, expected, mismatchKeys, mismatchValues), +1034 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +1035 + '<br /><br />but got<br /><br />' + jasmine.Matchers.pp(this.actual) +1036 + '<br />' +1037 + formatMismatches('Keys', mismatchKeys) +1038 + formatMismatches('Values', mismatchValues), { +1039 matcherName: 'toEqual', expected: expected, actual: this.actual +1040 }); +1041 }; +1042 +1043 /** +1044 * Matcher that compares the actual to the expected using the ! of jasmine.Matchers.toEqual +1045 * @param expected +1046 */ +1047 jasmine.Matchers.prototype.toNotEqual = function(expected) { +1048 return this.report(!this.env.equals_(this.actual, expected), +1049 'Expected ' + jasmine.Matchers.pp(expected) + ' to not equal ' + jasmine.Matchers.pp(this.actual) + ', but it does.'); +1050 }; +1051 +1052 /** +1053 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +1054 * a pattern or a String. +1055 * +1056 * @param reg_exp +1057 */ +1058 jasmine.Matchers.prototype.toMatch = function(reg_exp) { +1059 return this.report((new RegExp(reg_exp).test(this.actual)), +1060 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to match ' + reg_exp + '.'); +1061 }; +1062 +1063 /** +1064 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch +1065 * @param reg_exp +1066 */ +1067 jasmine.Matchers.prototype.toNotMatch = function(reg_exp) { +1068 return this.report((!new RegExp(reg_exp).test(this.actual)), +1069 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to not match ' + reg_exp + '.'); +1070 }; +1071 +1072 /** +1073 * Matcher that compares the acutal to undefined. +1074 */ +1075 jasmine.Matchers.prototype.toBeDefined = function() { +1076 return this.report((this.actual !== undefined), +1077 'Expected a value to be defined but it was undefined.'); +1078 }; +1079 +1080 /** +1081 * Matcher that compares the actual to null. +1082 * +1083 */ +1084 jasmine.Matchers.prototype.toBeNull = function() { +1085 return this.report((this.actual === null), +1086 'Expected a value to be null but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1087 }; +1088 +1089 /** +1090 * Matcher that boolean not-nots the actual. +1091 */ +1092 jasmine.Matchers.prototype.toBeTruthy = function() { +1093 return this.report(!!this.actual, +1094 'Expected a value to be truthy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1095 }; +1096 +1097 /** +1098 * Matcher that boolean nots the actual. +1099 */ +1100 jasmine.Matchers.prototype.toBeFalsy = function() { +1101 return this.report(!this.actual, +1102 'Expected a value to be falsy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1103 }; +1104 +1105 /** +1106 * Matcher that checks to see if the acutal, a Jasmine spy, was called. +1107 */ +1108 jasmine.Matchers.prototype.wasCalled = function() { +1109 if (!this.actual || !this.actual.isSpy) { +1110 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); 1111 } -1112 return this.report((this.actual.wasCalled), -1113 'Expected spy "' + this.actual.identity + '" to have been called, but it was not.'); -1114 }; -1115 -1116 /** -1117 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. -1118 */ -1119 jasmine.Matchers.prototype.wasNotCalled = function() { -1120 if (!this.actual || !this.actual.isSpy) { -1121 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -1122 } -1123 return this.report((!this.actual.wasCalled), -1124 'Expected spy "' + this.actual.identity + '" to not have been called, but it was.'); -1125 }; -1126 -1127 /** -1128 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. -1129 * -1130 * @example -1131 * -1132 */ -1133 jasmine.Matchers.prototype.wasCalledWith = function() { -1134 if (!this.actual || !this.actual.isSpy) { -1135 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.', { -1136 matcherName: 'wasCalledWith' -1137 }); -1138 } -1139 -1140 var args = jasmine.util.argsToArray(arguments); -1141 -1142 return this.report(this.env.contains_(this.actual.argsForCall, args), -1143 'Expected ' + jasmine.Matchers.pp(this.actual.argsForCall) + ' to contain ' + jasmine.Matchers.pp(args) + ', but it does not.', { -1144 matcherName: 'wasCalledWith', expected: args, actual: this.actual.argsForCall -1145 }); -1146 }; -1147 -1148 /** -1149 * Matcher that checks that the expected item is an element in the actual Array. -1150 * -1151 * @param {Object} item -1152 */ -1153 jasmine.Matchers.prototype.toContain = function(item) { -1154 return this.report(this.env.contains_(this.actual, item), -1155 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to contain ' + jasmine.Matchers.pp(item) + ', but it does not.', { -1156 matcherName: 'toContain', expected: item, actual: this.actual -1157 }); -1158 }; -1159 -1160 /** -1161 * Matcher that checks that the expected item is NOT an element in the actual Array. -1162 * -1163 * @param {Object} item -1164 */ -1165 jasmine.Matchers.prototype.toNotContain = function(item) { -1166 return this.report(!this.env.contains_(this.actual, item), -1167 'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.'); -1168 }; -1169 -1170 jasmine.Matchers.prototype.toBeLessThan = function(expected) { -1171 return this.report(this.actual < expected, -1172 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); -1173 }; -1174 -1175 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { -1176 return this.report(this.actual > expected, -1177 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); -1178 }; -1179 -1180 /** -1181 * Matcher that checks that the expected exception was thrown by the actual. -1182 * -1183 * @param {String} expectedException -1184 */ -1185 jasmine.Matchers.prototype.toThrow = function(expectedException) { -1186 var exception = null; -1187 try { -1188 this.actual(); -1189 } catch (e) { -1190 exception = e; -1191 } -1192 if (expectedException !== undefined) { -1193 if (exception == null) { -1194 return this.report(false, "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it did not."); -1195 } -1196 return this.report( -1197 this.env.equals_( -1198 exception.message || exception, -1199 expectedException.message || expectedException), -1200 "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it threw " + jasmine.Matchers.pp(exception) + "."); -1201 } else { -1202 return this.report(exception != null, "Expected function to throw an exception, but it did not."); -1203 } -1204 }; -1205 -1206 jasmine.Matchers.Any = function(expectedClass) { -1207 this.expectedClass = expectedClass; -1208 }; -1209 -1210 jasmine.Matchers.Any.prototype.matches = function(other) { -1211 if (this.expectedClass == String) { -1212 return typeof other == 'string' || other instanceof String; -1213 } -1214 -1215 if (this.expectedClass == Number) { -1216 return typeof other == 'number' || other instanceof Number; -1217 } -1218 -1219 if (this.expectedClass == Function) { -1220 return typeof other == 'function' || other instanceof Function; -1221 } -1222 -1223 if (this.expectedClass == Object) { -1224 return typeof other == 'object'; -1225 } -1226 -1227 return other instanceof this.expectedClass; -1228 }; +1112 if (arguments.length > 0) { +1113 return this.report(false, 'wasCalled matcher does not take arguments'); +1114 } +1115 return this.report((this.actual.wasCalled), +1116 'Expected spy "' + this.actual.identity + '" to have been called, but it was not.'); +1117 }; +1118 +1119 /** +1120 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. +1121 */ +1122 jasmine.Matchers.prototype.wasNotCalled = function() { +1123 if (!this.actual || !this.actual.isSpy) { +1124 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +1125 } +1126 return this.report((!this.actual.wasCalled), +1127 'Expected spy "' + this.actual.identity + '" to not have been called, but it was.'); +1128 }; +1129 +1130 /** +1131 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. +1132 * +1133 * @example +1134 * +1135 */ +1136 jasmine.Matchers.prototype.wasCalledWith = function() { +1137 if (!this.actual || !this.actual.isSpy) { +1138 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.', { +1139 matcherName: 'wasCalledWith' +1140 }); +1141 } +1142 +1143 var args = jasmine.util.argsToArray(arguments); +1144 +1145 return this.report(this.env.contains_(this.actual.argsForCall, args), +1146 'Expected ' + jasmine.Matchers.pp(this.actual.argsForCall) + ' to contain ' + jasmine.Matchers.pp(args) + ', but it does not.', { +1147 matcherName: 'wasCalledWith', expected: args, actual: this.actual.argsForCall +1148 }); +1149 }; +1150 +1151 /** +1152 * Matcher that checks that the expected item is an element in the actual Array. +1153 * +1154 * @param {Object} item +1155 */ +1156 jasmine.Matchers.prototype.toContain = function(item) { +1157 return this.report(this.env.contains_(this.actual, item), +1158 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to contain ' + jasmine.Matchers.pp(item) + ', but it does not.', { +1159 matcherName: 'toContain', expected: item, actual: this.actual +1160 }); +1161 }; +1162 +1163 /** +1164 * Matcher that checks that the expected item is NOT an element in the actual Array. +1165 * +1166 * @param {Object} item +1167 */ +1168 jasmine.Matchers.prototype.toNotContain = function(item) { +1169 return this.report(!this.env.contains_(this.actual, item), +1170 'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.'); +1171 }; +1172 +1173 jasmine.Matchers.prototype.toBeLessThan = function(expected) { +1174 return this.report(this.actual < expected, +1175 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); +1176 }; +1177 +1178 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +1179 return this.report(this.actual > expected, +1180 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); +1181 }; +1182 +1183 /** +1184 * Matcher that checks that the expected exception was thrown by the actual. +1185 * +1186 * @param {String} expectedException +1187 */ +1188 jasmine.Matchers.prototype.toThrow = function(expectedException) { +1189 var exception = null; +1190 try { +1191 this.actual(); +1192 } catch (e) { +1193 exception = e; +1194 } +1195 if (expectedException !== undefined) { +1196 if (exception == null) { +1197 return this.report(false, "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it did not."); +1198 } +1199 return this.report( +1200 this.env.equals_( +1201 exception.message || exception, +1202 expectedException.message || expectedException), +1203 "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it threw " + jasmine.Matchers.pp(exception) + "."); +1204 } else { +1205 return this.report(exception != null, "Expected function to throw an exception, but it did not."); +1206 } +1207 }; +1208 +1209 jasmine.Matchers.Any = function(expectedClass) { +1210 this.expectedClass = expectedClass; +1211 }; +1212 +1213 jasmine.Matchers.Any.prototype.matches = function(other) { +1214 if (this.expectedClass == String) { +1215 return typeof other == 'string' || other instanceof String; +1216 } +1217 +1218 if (this.expectedClass == Number) { +1219 return typeof other == 'number' || other instanceof Number; +1220 } +1221 +1222 if (this.expectedClass == Function) { +1223 return typeof other == 'function' || other instanceof Function; +1224 } +1225 +1226 if (this.expectedClass == Object) { +1227 return typeof other == 'object'; +1228 } 1229 -1230 jasmine.Matchers.Any.prototype.toString = function() { -1231 return '<jasmine.any(' + this.expectedClass + ')>'; -1232 }; -1233 -1234 /** -1235 * @constructor -1236 */ -1237 jasmine.MultiReporter = function() { -1238 this.subReporters_ = []; -1239 }; -1240 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); -1241 -1242 jasmine.MultiReporter.prototype.addReporter = function(reporter) { -1243 this.subReporters_.push(reporter); -1244 }; -1245 -1246 (function() { -1247 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; -1248 for (var i = 0; i < functionNames.length; i++) { -1249 var functionName = functionNames[i]; -1250 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { -1251 return function() { -1252 for (var j = 0; j < this.subReporters_.length; j++) { -1253 var subReporter = this.subReporters_[j]; -1254 if (subReporter[functionName]) { -1255 subReporter[functionName].apply(subReporter, arguments); -1256 } -1257 } -1258 }; -1259 })(functionName); -1260 } -1261 })(); -1262 /** -1263 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults -1264 * -1265 * @constructor -1266 */ -1267 jasmine.NestedResults = function() { -1268 /** -1269 * The total count of results -1270 */ -1271 this.totalCount = 0; -1272 /** -1273 * Number of passed results -1274 */ -1275 this.passedCount = 0; -1276 /** -1277 * Number of failed results -1278 */ -1279 this.failedCount = 0; -1280 /** -1281 * Was this suite/spec skipped? -1282 */ -1283 this.skipped = false; -1284 /** -1285 * @ignore -1286 */ -1287 this.items_ = []; -1288 }; -1289 -1290 /** -1291 * Roll up the result counts. -1292 * -1293 * @param result -1294 */ -1295 jasmine.NestedResults.prototype.rollupCounts = function(result) { -1296 this.totalCount += result.totalCount; -1297 this.passedCount += result.passedCount; -1298 this.failedCount += result.failedCount; -1299 }; -1300 -1301 /** -1302 * Tracks a result's message. -1303 * @param message -1304 */ -1305 jasmine.NestedResults.prototype.log = function(message) { -1306 this.items_.push(new jasmine.MessageResult(message)); -1307 }; -1308 -1309 /** -1310 * Getter for the results: message & results. -1311 */ -1312 jasmine.NestedResults.prototype.getItems = function() { -1313 return this.items_; -1314 }; -1315 -1316 /** -1317 * Adds a result, tracking counts (total, passed, & failed) -1318 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result -1319 */ -1320 jasmine.NestedResults.prototype.addResult = function(result) { -1321 if (result.type != 'MessageResult') { -1322 if (result.items_) { -1323 this.rollupCounts(result); -1324 } else { -1325 this.totalCount++; -1326 if (result.passed()) { -1327 this.passedCount++; -1328 } else { -1329 this.failedCount++; -1330 } -1331 } -1332 } -1333 this.items_.push(result); -1334 }; -1335 -1336 /** -1337 * @returns {Boolean} True if <b>everything</b> below passed -1338 */ -1339 jasmine.NestedResults.prototype.passed = function() { -1340 return this.passedCount === this.totalCount; -1341 }; -1342 /** -1343 * Base class for pretty printing for expectation results. -1344 */ -1345 jasmine.PrettyPrinter = function() { -1346 this.ppNestLevel_ = 0; -1347 }; -1348 -1349 /** -1350 * Formats a value in a nice, human-readable string. -1351 * -1352 * @param value -1353 * @returns {String} -1354 */ -1355 jasmine.PrettyPrinter.prototype.format = function(value) { -1356 if (this.ppNestLevel_ > 40) { -1357 // return '(jasmine.pp nested too deeply!)'; -1358 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); -1359 } -1360 -1361 this.ppNestLevel_++; -1362 try { -1363 if (value === undefined) { -1364 this.emitScalar('undefined'); -1365 } else if (value === null) { -1366 this.emitScalar('null'); -1367 } else if (value.navigator && value.frames && value.setTimeout) { -1368 this.emitScalar('<window>'); -1369 } else if (value instanceof jasmine.Matchers.Any) { -1370 this.emitScalar(value.toString()); -1371 } else if (typeof value === 'string') { -1372 this.emitString(value); -1373 } else if (typeof value === 'function') { -1374 this.emitScalar('Function'); -1375 } else if (typeof value.nodeType === 'number') { -1376 this.emitScalar('HTMLNode'); -1377 } else if (value instanceof Date) { -1378 this.emitScalar('Date(' + value + ')'); -1379 } else if (value.__Jasmine_been_here_before__) { -1380 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); -1381 } else if (jasmine.isArray_(value) || typeof value == 'object') { -1382 value.__Jasmine_been_here_before__ = true; -1383 if (jasmine.isArray_(value)) { -1384 this.emitArray(value); -1385 } else { -1386 this.emitObject(value); -1387 } -1388 delete value.__Jasmine_been_here_before__; -1389 } else { -1390 this.emitScalar(value.toString()); -1391 } -1392 } finally { -1393 this.ppNestLevel_--; -1394 } -1395 }; -1396 -1397 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { -1398 for (var property in obj) { -1399 if (property == '__Jasmine_been_here_before__') continue; -1400 fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); -1401 } -1402 }; -1403 -1404 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; -1405 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; -1406 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; -1407 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; -1408 -1409 jasmine.StringPrettyPrinter = function() { -1410 jasmine.PrettyPrinter.call(this); +1230 return other instanceof this.expectedClass; +1231 }; +1232 +1233 jasmine.Matchers.Any.prototype.toString = function() { +1234 return '<jasmine.any(' + this.expectedClass + ')>'; +1235 }; +1236 +1237 /** +1238 * @constructor +1239 */ +1240 jasmine.MultiReporter = function() { +1241 this.subReporters_ = []; +1242 }; +1243 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); +1244 +1245 jasmine.MultiReporter.prototype.addReporter = function(reporter) { +1246 this.subReporters_.push(reporter); +1247 }; +1248 +1249 (function() { +1250 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; +1251 for (var i = 0; i < functionNames.length; i++) { +1252 var functionName = functionNames[i]; +1253 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { +1254 return function() { +1255 for (var j = 0; j < this.subReporters_.length; j++) { +1256 var subReporter = this.subReporters_[j]; +1257 if (subReporter[functionName]) { +1258 subReporter[functionName].apply(subReporter, arguments); +1259 } +1260 } +1261 }; +1262 })(functionName); +1263 } +1264 })(); +1265 /** +1266 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults +1267 * +1268 * @constructor +1269 */ +1270 jasmine.NestedResults = function() { +1271 /** +1272 * The total count of results +1273 */ +1274 this.totalCount = 0; +1275 /** +1276 * Number of passed results +1277 */ +1278 this.passedCount = 0; +1279 /** +1280 * Number of failed results +1281 */ +1282 this.failedCount = 0; +1283 /** +1284 * Was this suite/spec skipped? +1285 */ +1286 this.skipped = false; +1287 /** +1288 * @ignore +1289 */ +1290 this.items_ = []; +1291 }; +1292 +1293 /** +1294 * Roll up the result counts. +1295 * +1296 * @param result +1297 */ +1298 jasmine.NestedResults.prototype.rollupCounts = function(result) { +1299 this.totalCount += result.totalCount; +1300 this.passedCount += result.passedCount; +1301 this.failedCount += result.failedCount; +1302 }; +1303 +1304 /** +1305 * Tracks a result's message. +1306 * @param message +1307 */ +1308 jasmine.NestedResults.prototype.log = function(message) { +1309 this.items_.push(new jasmine.MessageResult(message)); +1310 }; +1311 +1312 /** +1313 * Getter for the results: message & results. +1314 */ +1315 jasmine.NestedResults.prototype.getItems = function() { +1316 return this.items_; +1317 }; +1318 +1319 /** +1320 * Adds a result, tracking counts (total, passed, & failed) +1321 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result +1322 */ +1323 jasmine.NestedResults.prototype.addResult = function(result) { +1324 if (result.type != 'MessageResult') { +1325 if (result.items_) { +1326 this.rollupCounts(result); +1327 } else { +1328 this.totalCount++; +1329 if (result.passed()) { +1330 this.passedCount++; +1331 } else { +1332 this.failedCount++; +1333 } +1334 } +1335 } +1336 this.items_.push(result); +1337 }; +1338 +1339 /** +1340 * @returns {Boolean} True if <b>everything</b> below passed +1341 */ +1342 jasmine.NestedResults.prototype.passed = function() { +1343 return this.passedCount === this.totalCount; +1344 }; +1345 /** +1346 * Base class for pretty printing for expectation results. +1347 */ +1348 jasmine.PrettyPrinter = function() { +1349 this.ppNestLevel_ = 0; +1350 }; +1351 +1352 /** +1353 * Formats a value in a nice, human-readable string. +1354 * +1355 * @param value +1356 * @returns {String} +1357 */ +1358 jasmine.PrettyPrinter.prototype.format = function(value) { +1359 if (this.ppNestLevel_ > 40) { +1360 // return '(jasmine.pp nested too deeply!)'; +1361 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); +1362 } +1363 +1364 this.ppNestLevel_++; +1365 try { +1366 if (value === undefined) { +1367 this.emitScalar('undefined'); +1368 } else if (value === null) { +1369 this.emitScalar('null'); +1370 } else if (value.navigator && value.frames && value.setTimeout) { +1371 this.emitScalar('<window>'); +1372 } else if (value instanceof jasmine.Matchers.Any) { +1373 this.emitScalar(value.toString()); +1374 } else if (typeof value === 'string') { +1375 this.emitString(value); +1376 } else if (typeof value === 'function') { +1377 this.emitScalar('Function'); +1378 } else if (typeof value.nodeType === 'number') { +1379 this.emitScalar('HTMLNode'); +1380 } else if (value instanceof Date) { +1381 this.emitScalar('Date(' + value + ')'); +1382 } else if (value.__Jasmine_been_here_before__) { +1383 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); +1384 } else if (jasmine.isArray_(value) || typeof value == 'object') { +1385 value.__Jasmine_been_here_before__ = true; +1386 if (jasmine.isArray_(value)) { +1387 this.emitArray(value); +1388 } else { +1389 this.emitObject(value); +1390 } +1391 delete value.__Jasmine_been_here_before__; +1392 } else { +1393 this.emitScalar(value.toString()); +1394 } +1395 } finally { +1396 this.ppNestLevel_--; +1397 } +1398 }; +1399 +1400 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { +1401 for (var property in obj) { +1402 if (property == '__Jasmine_been_here_before__') continue; +1403 fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); +1404 } +1405 }; +1406 +1407 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; +1408 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; +1409 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; +1410 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; 1411 -1412 this.string = ''; -1413 }; -1414 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); -1415 -1416 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { -1417 this.append(value); -1418 }; -1419 -1420 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { -1421 this.append("'" + value + "'"); -1422 }; -1423 -1424 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { -1425 this.append('[ '); -1426 for (var i = 0; i < array.length; i++) { -1427 if (i > 0) { -1428 this.append(', '); -1429 } -1430 this.format(array[i]); -1431 } -1432 this.append(' ]'); -1433 }; -1434 -1435 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { -1436 var self = this; -1437 this.append('{ '); -1438 var first = true; -1439 -1440 this.iterateObject(obj, function(property, isGetter) { -1441 if (first) { -1442 first = false; -1443 } else { -1444 self.append(', '); -1445 } -1446 -1447 self.append(property); -1448 self.append(' : '); -1449 if (isGetter) { -1450 self.append('<getter>'); -1451 } else { -1452 self.format(obj[property]); -1453 } -1454 }); -1455 -1456 this.append(' }'); -1457 }; +1412 jasmine.StringPrettyPrinter = function() { +1413 jasmine.PrettyPrinter.call(this); +1414 +1415 this.string = ''; +1416 }; +1417 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); +1418 +1419 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { +1420 this.append(value); +1421 }; +1422 +1423 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { +1424 this.append("'" + value + "'"); +1425 }; +1426 +1427 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { +1428 this.append('[ '); +1429 for (var i = 0; i < array.length; i++) { +1430 if (i > 0) { +1431 this.append(', '); +1432 } +1433 this.format(array[i]); +1434 } +1435 this.append(' ]'); +1436 }; +1437 +1438 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { +1439 var self = this; +1440 this.append('{ '); +1441 var first = true; +1442 +1443 this.iterateObject(obj, function(property, isGetter) { +1444 if (first) { +1445 first = false; +1446 } else { +1447 self.append(', '); +1448 } +1449 +1450 self.append(property); +1451 self.append(' : '); +1452 if (isGetter) { +1453 self.append('<getter>'); +1454 } else { +1455 self.format(obj[property]); +1456 } +1457 }); 1458 -1459 jasmine.StringPrettyPrinter.prototype.append = function(value) { -1460 this.string += value; -1461 }; -1462 jasmine.Queue = function(env) { -1463 this.env = env; -1464 this.blocks = []; -1465 this.running = false; -1466 this.index = 0; -1467 this.offset = 0; -1468 }; -1469 -1470 jasmine.Queue.prototype.addBefore = function(block) { -1471 this.blocks.unshift(block); -1472 }; -1473 -1474 jasmine.Queue.prototype.add = function(block) { -1475 this.blocks.push(block); -1476 }; -1477 -1478 jasmine.Queue.prototype.insertNext = function(block) { -1479 this.blocks.splice((this.index + this.offset + 1), 0, block); -1480 this.offset++; -1481 }; -1482 -1483 jasmine.Queue.prototype.start = function(onComplete) { -1484 this.running = true; -1485 this.onComplete = onComplete; -1486 this.next_(); -1487 }; -1488 -1489 jasmine.Queue.prototype.isRunning = function() { -1490 return this.running; -1491 }; -1492 -1493 jasmine.Queue.LOOP_DONT_RECURSE = true; -1494 -1495 jasmine.Queue.prototype.next_ = function() { -1496 var self = this; -1497 var goAgain = true; -1498 -1499 while (goAgain) { -1500 goAgain = false; -1501 -1502 if (self.index < self.blocks.length) { -1503 var calledSynchronously = true; -1504 var completedSynchronously = false; -1505 -1506 var onComplete = function () { -1507 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { -1508 completedSynchronously = true; -1509 return; -1510 } -1511 -1512 self.offset = 0; -1513 self.index++; +1459 this.append(' }'); +1460 }; +1461 +1462 jasmine.StringPrettyPrinter.prototype.append = function(value) { +1463 this.string += value; +1464 }; +1465 jasmine.Queue = function(env) { +1466 this.env = env; +1467 this.blocks = []; +1468 this.running = false; +1469 this.index = 0; +1470 this.offset = 0; +1471 }; +1472 +1473 jasmine.Queue.prototype.addBefore = function(block) { +1474 this.blocks.unshift(block); +1475 }; +1476 +1477 jasmine.Queue.prototype.add = function(block) { +1478 this.blocks.push(block); +1479 }; +1480 +1481 jasmine.Queue.prototype.insertNext = function(block) { +1482 this.blocks.splice((this.index + this.offset + 1), 0, block); +1483 this.offset++; +1484 }; +1485 +1486 jasmine.Queue.prototype.start = function(onComplete) { +1487 this.running = true; +1488 this.onComplete = onComplete; +1489 this.next_(); +1490 }; +1491 +1492 jasmine.Queue.prototype.isRunning = function() { +1493 return this.running; +1494 }; +1495 +1496 jasmine.Queue.LOOP_DONT_RECURSE = true; +1497 +1498 jasmine.Queue.prototype.next_ = function() { +1499 var self = this; +1500 var goAgain = true; +1501 +1502 while (goAgain) { +1503 goAgain = false; +1504 +1505 if (self.index < self.blocks.length) { +1506 var calledSynchronously = true; +1507 var completedSynchronously = false; +1508 +1509 var onComplete = function () { +1510 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { +1511 completedSynchronously = true; +1512 return; +1513 } 1514 -1515 var now = new Date().getTime(); -1516 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { -1517 self.env.lastUpdate = now; -1518 self.env.setTimeout(function() { -1519 self.next_(); -1520 }, 0); -1521 } else { -1522 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { -1523 goAgain = true; -1524 } else { -1525 self.next_(); -1526 } -1527 } -1528 }; -1529 self.blocks[self.index].execute(onComplete); -1530 -1531 calledSynchronously = false; -1532 if (completedSynchronously) { -1533 onComplete(); -1534 } -1535 -1536 } else { -1537 self.running = false; -1538 if (self.onComplete) { -1539 self.onComplete(); -1540 } -1541 } -1542 } -1543 }; -1544 -1545 jasmine.Queue.prototype.results = function() { -1546 var results = new jasmine.NestedResults(); -1547 for (var i = 0; i < this.blocks.length; i++) { -1548 if (this.blocks[i].results) { -1549 results.addResult(this.blocks[i].results()); -1550 } -1551 } -1552 return results; -1553 }; -1554 -1555 -1556 /* JasmineReporters.reporter -1557 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to -1558 * descendants of this object to do something with the results (see json_reporter.js) -1559 */ -1560 jasmine.Reporters = {}; -1561 -1562 jasmine.Reporters.reporter = function(callbacks) { -1563 var that = { -1564 callbacks: callbacks || {}, -1565 -1566 doCallback: function(callback, results) { -1567 if (callback) { -1568 callback(results); -1569 } -1570 }, -1571 -1572 reportRunnerResults: function(runner) { -1573 that.doCallback(that.callbacks.runnerCallback, runner); -1574 }, -1575 reportSuiteResults: function(suite) { -1576 that.doCallback(that.callbacks.suiteCallback, suite); +1515 self.offset = 0; +1516 self.index++; +1517 +1518 var now = new Date().getTime(); +1519 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { +1520 self.env.lastUpdate = now; +1521 self.env.setTimeout(function() { +1522 self.next_(); +1523 }, 0); +1524 } else { +1525 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { +1526 goAgain = true; +1527 } else { +1528 self.next_(); +1529 } +1530 } +1531 }; +1532 self.blocks[self.index].execute(onComplete); +1533 +1534 calledSynchronously = false; +1535 if (completedSynchronously) { +1536 onComplete(); +1537 } +1538 +1539 } else { +1540 self.running = false; +1541 if (self.onComplete) { +1542 self.onComplete(); +1543 } +1544 } +1545 } +1546 }; +1547 +1548 jasmine.Queue.prototype.results = function() { +1549 var results = new jasmine.NestedResults(); +1550 for (var i = 0; i < this.blocks.length; i++) { +1551 if (this.blocks[i].results) { +1552 results.addResult(this.blocks[i].results()); +1553 } +1554 } +1555 return results; +1556 }; +1557 +1558 +1559 /* JasmineReporters.reporter +1560 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to +1561 * descendants of this object to do something with the results (see json_reporter.js) +1562 */ +1563 jasmine.Reporters = {}; +1564 +1565 jasmine.Reporters.reporter = function(callbacks) { +1566 var that = { +1567 callbacks: callbacks || {}, +1568 +1569 doCallback: function(callback, results) { +1570 if (callback) { +1571 callback(results); +1572 } +1573 }, +1574 +1575 reportRunnerResults: function(runner) { +1576 that.doCallback(that.callbacks.runnerCallback, runner); 1577 }, -1578 reportSpecResults: function(spec) { -1579 that.doCallback(that.callbacks.specCallback, spec); +1578 reportSuiteResults: function(suite) { +1579 that.doCallback(that.callbacks.suiteCallback, suite); 1580 }, -1581 log: function (str) { -1582 if (console && console.log) console.log(str); -1583 } -1584 }; -1585 -1586 return that; -1587 }; +1581 reportSpecResults: function(spec) { +1582 that.doCallback(that.callbacks.specCallback, spec); +1583 }, +1584 log: function (str) { +1585 if (console && console.log) console.log(str); +1586 } +1587 }; 1588 -1589 /** -1590 * Runner -1591 * -1592 * @constructor -1593 * @param {jasmine.Env} env -1594 */ -1595 jasmine.Runner = function(env) { -1596 var self = this; -1597 self.env = env; -1598 self.queue = new jasmine.Queue(env); -1599 self.before_ = []; -1600 self.after_ = []; -1601 self.suites_ = []; -1602 }; -1603 -1604 jasmine.Runner.prototype.execute = function() { -1605 var self = this; -1606 if (self.env.reporter.reportRunnerStarting) { -1607 self.env.reporter.reportRunnerStarting(this); -1608 } -1609 self.queue.start(function () { -1610 self.finishCallback(); -1611 }); -1612 }; -1613 -1614 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { -1615 beforeEachFunction.typeName = 'beforeEach'; -1616 this.before_.push(beforeEachFunction); -1617 }; -1618 -1619 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { -1620 afterEachFunction.typeName = 'afterEach'; -1621 this.after_.push(afterEachFunction); -1622 }; -1623 -1624 -1625 jasmine.Runner.prototype.finishCallback = function() { -1626 this.env.reporter.reportRunnerResults(this); -1627 }; -1628 -1629 jasmine.Runner.prototype.addSuite = function(suite) { -1630 this.suites_.push(suite); -1631 }; -1632 -1633 jasmine.Runner.prototype.add = function(block) { -1634 if (block instanceof jasmine.Suite) { -1635 this.addSuite(block); -1636 } -1637 this.queue.add(block); -1638 }; -1639 -1640 jasmine.Runner.prototype.specs = function () { -1641 var suites = this.suites(); -1642 var specs = []; -1643 for (var i = 0; i < suites.length; i++) { -1644 specs = specs.concat(suites[i].specs()); -1645 } -1646 return specs; -1647 }; -1648 -1649 -1650 jasmine.Runner.prototype.suites = function() { -1651 return this.suites_; -1652 }; -1653 -1654 jasmine.Runner.prototype.results = function() { -1655 return this.queue.results(); -1656 }; -1657 /** -1658 * Internal representation of a Jasmine specification, or test. -1659 * -1660 * @constructor -1661 * @param {jasmine.Env} env -1662 * @param {jasmine.Suite} suite -1663 * @param {String} description -1664 */ -1665 jasmine.Spec = function(env, suite, description) { -1666 if (!env) { -1667 throw new Error('jasmine.Env() required'); -1668 } -1669 ; -1670 if (!suite) { -1671 throw new Error('jasmine.Suite() required'); -1672 } -1673 ; -1674 var spec = this; -1675 spec.id = env.nextSpecId ? env.nextSpecId() : null; -1676 spec.env = env; -1677 spec.suite = suite; -1678 spec.description = description; -1679 spec.queue = new jasmine.Queue(env); -1680 -1681 spec.afterCallbacks = []; -1682 spec.spies_ = []; +1589 return that; +1590 }; +1591 +1592 /** +1593 * Runner +1594 * +1595 * @constructor +1596 * @param {jasmine.Env} env +1597 */ +1598 jasmine.Runner = function(env) { +1599 var self = this; +1600 self.env = env; +1601 self.queue = new jasmine.Queue(env); +1602 self.before_ = []; +1603 self.after_ = []; +1604 self.suites_ = []; +1605 }; +1606 +1607 jasmine.Runner.prototype.execute = function() { +1608 var self = this; +1609 if (self.env.reporter.reportRunnerStarting) { +1610 self.env.reporter.reportRunnerStarting(this); +1611 } +1612 self.queue.start(function () { +1613 self.finishCallback(); +1614 }); +1615 }; +1616 +1617 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { +1618 beforeEachFunction.typeName = 'beforeEach'; +1619 this.before_.push(beforeEachFunction); +1620 }; +1621 +1622 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { +1623 afterEachFunction.typeName = 'afterEach'; +1624 this.after_.push(afterEachFunction); +1625 }; +1626 +1627 +1628 jasmine.Runner.prototype.finishCallback = function() { +1629 this.env.reporter.reportRunnerResults(this); +1630 }; +1631 +1632 jasmine.Runner.prototype.addSuite = function(suite) { +1633 this.suites_.push(suite); +1634 }; +1635 +1636 jasmine.Runner.prototype.add = function(block) { +1637 if (block instanceof jasmine.Suite) { +1638 this.addSuite(block); +1639 } +1640 this.queue.add(block); +1641 }; +1642 +1643 jasmine.Runner.prototype.specs = function () { +1644 var suites = this.suites(); +1645 var specs = []; +1646 for (var i = 0; i < suites.length; i++) { +1647 specs = specs.concat(suites[i].specs()); +1648 } +1649 return specs; +1650 }; +1651 +1652 +1653 jasmine.Runner.prototype.suites = function() { +1654 return this.suites_; +1655 }; +1656 +1657 jasmine.Runner.prototype.results = function() { +1658 return this.queue.results(); +1659 }; +1660 /** +1661 * Internal representation of a Jasmine specification, or test. +1662 * +1663 * @constructor +1664 * @param {jasmine.Env} env +1665 * @param {jasmine.Suite} suite +1666 * @param {String} description +1667 */ +1668 jasmine.Spec = function(env, suite, description) { +1669 if (!env) { +1670 throw new Error('jasmine.Env() required'); +1671 } +1672 ; +1673 if (!suite) { +1674 throw new Error('jasmine.Suite() required'); +1675 } +1676 ; +1677 var spec = this; +1678 spec.id = env.nextSpecId ? env.nextSpecId() : null; +1679 spec.env = env; +1680 spec.suite = suite; +1681 spec.description = description; +1682 spec.queue = new jasmine.Queue(env); 1683 -1684 spec.results_ = new jasmine.NestedResults(); -1685 spec.results_.description = description; -1686 spec.matchersClass = null; -1687 }; -1688 -1689 jasmine.Spec.prototype.getFullName = function() { -1690 return this.suite.getFullName() + ' ' + this.description + '.'; -1691 }; -1692 -1693 -1694 jasmine.Spec.prototype.results = function() { -1695 return this.results_; -1696 }; -1697 -1698 jasmine.Spec.prototype.log = function(message) { -1699 return this.results_.log(message); -1700 }; -1701 -1702 jasmine.Spec.prototype.runs = function (func) { -1703 var block = new jasmine.Block(this.env, func, this); -1704 this.addToQueue(block); -1705 return this; -1706 }; -1707 -1708 jasmine.Spec.prototype.addToQueue = function (block) { -1709 if (this.queue.isRunning()) { -1710 this.queue.insertNext(block); -1711 } else { -1712 this.queue.add(block); -1713 } -1714 }; -1715 -1716 jasmine.Spec.prototype.expect = function(actual) { -1717 return new (this.getMatchersClass_())(this.env, actual, this.results_); -1718 }; -1719 -1720 jasmine.Spec.prototype.waits = function(timeout) { -1721 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); -1722 this.addToQueue(waitsFunc); -1723 return this; -1724 }; -1725 -1726 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { -1727 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); -1728 this.addToQueue(waitsForFunc); -1729 return this; -1730 }; -1731 -1732 jasmine.Spec.prototype.fail = function (e) { -1733 this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); -1734 }; -1735 -1736 jasmine.Spec.prototype.getMatchersClass_ = function() { -1737 return this.matchersClass || jasmine.Matchers; -1738 }; -1739 -1740 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { -1741 var parent = this.getMatchersClass_(); -1742 var newMatchersClass = function() { -1743 parent.apply(this, arguments); -1744 }; -1745 jasmine.util.inherit(newMatchersClass, parent); -1746 for (var method in matchersPrototype) { -1747 newMatchersClass.prototype[method] = matchersPrototype[method]; -1748 } -1749 this.matchersClass = newMatchersClass; -1750 }; -1751 -1752 jasmine.Spec.prototype.finishCallback = function() { -1753 this.env.reporter.reportSpecResults(this); -1754 }; -1755 -1756 jasmine.Spec.prototype.finish = function(onComplete) { -1757 this.removeAllSpies(); -1758 this.finishCallback(); -1759 if (onComplete) { -1760 onComplete(); -1761 } -1762 }; -1763 -1764 jasmine.Spec.prototype.after = function(doAfter, test) { -1765 -1766 if (this.queue.isRunning()) { -1767 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -1768 } else { -1769 this.afterCallbacks.unshift(doAfter); -1770 } -1771 }; -1772 -1773 jasmine.Spec.prototype.execute = function(onComplete) { -1774 var spec = this; -1775 if (!spec.env.specFilter(spec)) { -1776 spec.results_.skipped = true; -1777 spec.finish(onComplete); -1778 return; -1779 } -1780 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); -1781 -1782 spec.env.currentSpec = spec; -1783 -1784 spec.addBeforesAndAftersToQueue(); -1785 -1786 spec.queue.start(function () { -1787 spec.finish(onComplete); -1788 }); -1789 }; -1790 -1791 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -1792 var runner = this.env.currentRunner(); -1793 for (var suite = this.suite; suite; suite = suite.parentSuite) { -1794 for (var i = 0; i < suite.before_.length; i++) { -1795 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -1796 } -1797 } -1798 for (var i = 0; i < runner.before_.length; i++) { -1799 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +1684 spec.afterCallbacks = []; +1685 spec.spies_ = []; +1686 +1687 spec.results_ = new jasmine.NestedResults(); +1688 spec.results_.description = description; +1689 spec.matchersClass = null; +1690 }; +1691 +1692 jasmine.Spec.prototype.getFullName = function() { +1693 return this.suite.getFullName() + ' ' + this.description + '.'; +1694 }; +1695 +1696 +1697 jasmine.Spec.prototype.results = function() { +1698 return this.results_; +1699 }; +1700 +1701 jasmine.Spec.prototype.log = function(message) { +1702 return this.results_.log(message); +1703 }; +1704 +1705 jasmine.Spec.prototype.runs = function (func) { +1706 var block = new jasmine.Block(this.env, func, this); +1707 this.addToQueue(block); +1708 return this; +1709 }; +1710 +1711 jasmine.Spec.prototype.addToQueue = function (block) { +1712 if (this.queue.isRunning()) { +1713 this.queue.insertNext(block); +1714 } else { +1715 this.queue.add(block); +1716 } +1717 }; +1718 +1719 jasmine.Spec.prototype.expect = function(actual) { +1720 return new (this.getMatchersClass_())(this.env, actual, this.results_); +1721 }; +1722 +1723 jasmine.Spec.prototype.waits = function(timeout) { +1724 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); +1725 this.addToQueue(waitsFunc); +1726 return this; +1727 }; +1728 +1729 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { +1730 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); +1731 this.addToQueue(waitsForFunc); +1732 return this; +1733 }; +1734 +1735 jasmine.Spec.prototype.fail = function (e) { +1736 this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); +1737 }; +1738 +1739 jasmine.Spec.prototype.getMatchersClass_ = function() { +1740 return this.matchersClass || jasmine.Matchers; +1741 }; +1742 +1743 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { +1744 var parent = this.getMatchersClass_(); +1745 var newMatchersClass = function() { +1746 parent.apply(this, arguments); +1747 }; +1748 jasmine.util.inherit(newMatchersClass, parent); +1749 for (var method in matchersPrototype) { +1750 newMatchersClass.prototype[method] = matchersPrototype[method]; +1751 } +1752 this.matchersClass = newMatchersClass; +1753 }; +1754 +1755 jasmine.Spec.prototype.finishCallback = function() { +1756 this.env.reporter.reportSpecResults(this); +1757 }; +1758 +1759 jasmine.Spec.prototype.finish = function(onComplete) { +1760 this.removeAllSpies(); +1761 this.finishCallback(); +1762 if (onComplete) { +1763 onComplete(); +1764 } +1765 }; +1766 +1767 jasmine.Spec.prototype.after = function(doAfter, test) { +1768 +1769 if (this.queue.isRunning()) { +1770 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +1771 } else { +1772 this.afterCallbacks.unshift(doAfter); +1773 } +1774 }; +1775 +1776 jasmine.Spec.prototype.execute = function(onComplete) { +1777 var spec = this; +1778 if (!spec.env.specFilter(spec)) { +1779 spec.results_.skipped = true; +1780 spec.finish(onComplete); +1781 return; +1782 } +1783 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +1784 +1785 spec.env.currentSpec = spec; +1786 +1787 spec.addBeforesAndAftersToQueue(); +1788 +1789 spec.queue.start(function () { +1790 spec.finish(onComplete); +1791 }); +1792 }; +1793 +1794 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +1795 var runner = this.env.currentRunner(); +1796 for (var suite = this.suite; suite; suite = suite.parentSuite) { +1797 for (var i = 0; i < suite.before_.length; i++) { +1798 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +1799 } 1800 } -1801 for (i = 0; i < this.afterCallbacks.length; i++) { -1802 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +1801 for (var i = 0; i < runner.before_.length; i++) { +1802 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); 1803 } -1804 for (suite = this.suite; suite; suite = suite.parentSuite) { -1805 for (var i = 0; i < suite.after_.length; i++) { -1806 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -1807 } -1808 } -1809 for (var i = 0; i < runner.after_.length; i++) { -1810 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +1804 for (i = 0; i < this.afterCallbacks.length; i++) { +1805 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +1806 } +1807 for (suite = this.suite; suite; suite = suite.parentSuite) { +1808 for (var i = 0; i < suite.after_.length; i++) { +1809 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +1810 } 1811 } -1812 }; -1813 -1814 jasmine.Spec.prototype.explodes = function() { -1815 throw 'explodes function should not have been called'; -1816 }; -1817 -1818 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -1819 if (obj == undefined) { -1820 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -1821 } -1822 -1823 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { -1824 throw methodName + '() method does not exist'; -1825 } -1826 -1827 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -1828 throw new Error(methodName + ' has already been spied upon'); -1829 } -1830 -1831 var spyObj = jasmine.createSpy(methodName); -1832 -1833 this.spies_.push(spyObj); -1834 spyObj.baseObj = obj; -1835 spyObj.methodName = methodName; -1836 spyObj.originalValue = obj[methodName]; -1837 -1838 obj[methodName] = spyObj; -1839 -1840 return spyObj; -1841 }; +1812 for (var i = 0; i < runner.after_.length; i++) { +1813 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +1814 } +1815 }; +1816 +1817 jasmine.Spec.prototype.explodes = function() { +1818 throw 'explodes function should not have been called'; +1819 }; +1820 +1821 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +1822 if (obj == undefined) { +1823 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +1824 } +1825 +1826 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { +1827 throw methodName + '() method does not exist'; +1828 } +1829 +1830 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +1831 throw new Error(methodName + ' has already been spied upon'); +1832 } +1833 +1834 var spyObj = jasmine.createSpy(methodName); +1835 +1836 this.spies_.push(spyObj); +1837 spyObj.baseObj = obj; +1838 spyObj.methodName = methodName; +1839 spyObj.originalValue = obj[methodName]; +1840 +1841 obj[methodName] = spyObj; 1842 -1843 jasmine.Spec.prototype.removeAllSpies = function() { -1844 for (var i = 0; i < this.spies_.length; i++) { -1845 var spy = this.spies_[i]; -1846 spy.baseObj[spy.methodName] = spy.originalValue; -1847 } -1848 this.spies_ = []; -1849 }; -1850 -1851 /** -1852 * Internal representation of a Jasmine suite. -1853 * -1854 * @constructor -1855 * @param {jasmine.Env} env -1856 * @param {String} description -1857 * @param {Function} specDefinitions -1858 * @param {jasmine.Suite} parentSuite -1859 */ -1860 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { -1861 var self = this; -1862 self.id = env.nextSuiteId ? env.nextSuiteId() : null; -1863 self.description = description; -1864 self.queue = new jasmine.Queue(env); -1865 self.parentSuite = parentSuite; -1866 self.env = env; -1867 self.before_ = []; -1868 self.after_ = []; -1869 self.specs_ = []; -1870 }; -1871 -1872 jasmine.Suite.prototype.getFullName = function() { -1873 var fullName = this.description; -1874 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { -1875 fullName = parentSuite.description + ' ' + fullName; -1876 } -1877 return fullName; -1878 }; -1879 -1880 jasmine.Suite.prototype.finish = function(onComplete) { -1881 this.env.reporter.reportSuiteResults(this); -1882 this.finished = true; -1883 if (typeof(onComplete) == 'function') { -1884 onComplete(); -1885 } -1886 }; -1887 -1888 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { -1889 beforeEachFunction.typeName = 'beforeEach'; -1890 this.before_.push(beforeEachFunction); -1891 }; -1892 -1893 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { -1894 afterEachFunction.typeName = 'afterEach'; -1895 this.after_.push(afterEachFunction); -1896 }; -1897 -1898 jasmine.Suite.prototype.results = function() { -1899 return this.queue.results(); -1900 }; -1901 -1902 jasmine.Suite.prototype.add = function(block) { -1903 if (block instanceof jasmine.Suite) { -1904 this.env.currentRunner().addSuite(block); -1905 } else { -1906 this.specs_.push(block); -1907 } -1908 this.queue.add(block); -1909 }; -1910 -1911 jasmine.Suite.prototype.specs = function() { -1912 return this.specs_; -1913 }; -1914 -1915 jasmine.Suite.prototype.execute = function(onComplete) { -1916 var self = this; -1917 this.queue.start(function () { -1918 self.finish(onComplete); -1919 }); -1920 }; -1921 jasmine.WaitsBlock = function(env, timeout, spec) { -1922 this.timeout = timeout; -1923 jasmine.Block.call(this, env, null, spec); -1924 }; -1925 -1926 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); -1927 -1928 jasmine.WaitsBlock.prototype.execute = function (onComplete) { -1929 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); -1930 this.env.setTimeout(function () { -1931 onComplete(); -1932 }, this.timeout); -1933 }; -1934 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { -1935 this.timeout = timeout; -1936 this.latchFunction = latchFunction; -1937 this.message = message; -1938 this.totalTimeSpentWaitingForLatch = 0; -1939 jasmine.Block.call(this, env, null, spec); -1940 }; -1941 -1942 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); -1943 -1944 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; -1945 -1946 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { -1947 var self = this; -1948 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); -1949 var latchFunctionResult; -1950 try { -1951 latchFunctionResult = self.latchFunction.apply(self.spec); -1952 } catch (e) { -1953 self.spec.fail(e); -1954 onComplete(); -1955 return; -1956 } -1957 -1958 if (latchFunctionResult) { -1959 onComplete(); -1960 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { -1961 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); -1962 self.spec.fail({ -1963 name: 'timeout', -1964 message: message -1965 }); -1966 self.spec._next(); -1967 } else { -1968 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; -1969 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); -1970 } -1971 }; -1972 // Mock setTimeout, clearTimeout -1973 // Contributed by Pivotal Computer Systems, www.pivotalsf.com -1974 -1975 jasmine.FakeTimer = function() { -1976 this.reset(); +1843 return spyObj; +1844 }; +1845 +1846 jasmine.Spec.prototype.removeAllSpies = function() { +1847 for (var i = 0; i < this.spies_.length; i++) { +1848 var spy = this.spies_[i]; +1849 spy.baseObj[spy.methodName] = spy.originalValue; +1850 } +1851 this.spies_ = []; +1852 }; +1853 +1854 /** +1855 * Internal representation of a Jasmine suite. +1856 * +1857 * @constructor +1858 * @param {jasmine.Env} env +1859 * @param {String} description +1860 * @param {Function} specDefinitions +1861 * @param {jasmine.Suite} parentSuite +1862 */ +1863 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { +1864 var self = this; +1865 self.id = env.nextSuiteId ? env.nextSuiteId() : null; +1866 self.description = description; +1867 self.queue = new jasmine.Queue(env); +1868 self.parentSuite = parentSuite; +1869 self.env = env; +1870 self.before_ = []; +1871 self.after_ = []; +1872 self.specs_ = []; +1873 }; +1874 +1875 jasmine.Suite.prototype.getFullName = function() { +1876 var fullName = this.description; +1877 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { +1878 fullName = parentSuite.description + ' ' + fullName; +1879 } +1880 return fullName; +1881 }; +1882 +1883 jasmine.Suite.prototype.finish = function(onComplete) { +1884 this.env.reporter.reportSuiteResults(this); +1885 this.finished = true; +1886 if (typeof(onComplete) == 'function') { +1887 onComplete(); +1888 } +1889 }; +1890 +1891 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { +1892 beforeEachFunction.typeName = 'beforeEach'; +1893 this.before_.push(beforeEachFunction); +1894 }; +1895 +1896 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { +1897 afterEachFunction.typeName = 'afterEach'; +1898 this.after_.push(afterEachFunction); +1899 }; +1900 +1901 jasmine.Suite.prototype.results = function() { +1902 return this.queue.results(); +1903 }; +1904 +1905 jasmine.Suite.prototype.add = function(block) { +1906 if (block instanceof jasmine.Suite) { +1907 this.env.currentRunner().addSuite(block); +1908 } else { +1909 this.specs_.push(block); +1910 } +1911 this.queue.add(block); +1912 }; +1913 +1914 jasmine.Suite.prototype.specs = function() { +1915 return this.specs_; +1916 }; +1917 +1918 jasmine.Suite.prototype.execute = function(onComplete) { +1919 var self = this; +1920 this.queue.start(function () { +1921 self.finish(onComplete); +1922 }); +1923 }; +1924 jasmine.WaitsBlock = function(env, timeout, spec) { +1925 this.timeout = timeout; +1926 jasmine.Block.call(this, env, null, spec); +1927 }; +1928 +1929 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); +1930 +1931 jasmine.WaitsBlock.prototype.execute = function (onComplete) { +1932 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); +1933 this.env.setTimeout(function () { +1934 onComplete(); +1935 }, this.timeout); +1936 }; +1937 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { +1938 this.timeout = timeout; +1939 this.latchFunction = latchFunction; +1940 this.message = message; +1941 this.totalTimeSpentWaitingForLatch = 0; +1942 jasmine.Block.call(this, env, null, spec); +1943 }; +1944 +1945 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); +1946 +1947 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; +1948 +1949 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { +1950 var self = this; +1951 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); +1952 var latchFunctionResult; +1953 try { +1954 latchFunctionResult = self.latchFunction.apply(self.spec); +1955 } catch (e) { +1956 self.spec.fail(e); +1957 onComplete(); +1958 return; +1959 } +1960 +1961 if (latchFunctionResult) { +1962 onComplete(); +1963 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { +1964 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); +1965 self.spec.fail({ +1966 name: 'timeout', +1967 message: message +1968 }); +1969 self.spec._next(); +1970 } else { +1971 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; +1972 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); +1973 } +1974 }; +1975 // Mock setTimeout, clearTimeout +1976 // Contributed by Pivotal Computer Systems, www.pivotalsf.com 1977 -1978 var self = this; -1979 self.setTimeout = function(funcToCall, millis) { -1980 self.timeoutsMade++; -1981 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); -1982 return self.timeoutsMade; -1983 }; -1984 -1985 self.setInterval = function(funcToCall, millis) { -1986 self.timeoutsMade++; -1987 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); -1988 return self.timeoutsMade; -1989 }; -1990 -1991 self.clearTimeout = function(timeoutKey) { -1992 self.scheduledFunctions[timeoutKey] = undefined; -1993 }; -1994 -1995 self.clearInterval = function(timeoutKey) { -1996 self.scheduledFunctions[timeoutKey] = undefined; -1997 }; -1998 -1999 }; -2000 -2001 jasmine.FakeTimer.prototype.reset = function() { -2002 this.timeoutsMade = 0; -2003 this.scheduledFunctions = {}; -2004 this.nowMillis = 0; -2005 }; -2006 -2007 jasmine.FakeTimer.prototype.tick = function(millis) { -2008 var oldMillis = this.nowMillis; -2009 var newMillis = oldMillis + millis; -2010 this.runFunctionsWithinRange(oldMillis, newMillis); -2011 this.nowMillis = newMillis; -2012 }; -2013 -2014 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { -2015 var scheduledFunc; -2016 var funcsToRun = []; -2017 for (var timeoutKey in this.scheduledFunctions) { -2018 scheduledFunc = this.scheduledFunctions[timeoutKey]; -2019 if (scheduledFunc != undefined && -2020 scheduledFunc.runAtMillis >= oldMillis && -2021 scheduledFunc.runAtMillis <= nowMillis) { -2022 funcsToRun.push(scheduledFunc); -2023 this.scheduledFunctions[timeoutKey] = undefined; -2024 } -2025 } -2026 -2027 if (funcsToRun.length > 0) { -2028 funcsToRun.sort(function(a, b) { -2029 return a.runAtMillis - b.runAtMillis; -2030 }); -2031 for (var i = 0; i < funcsToRun.length; ++i) { -2032 try { -2033 var funcToRun = funcsToRun[i]; -2034 this.nowMillis = funcToRun.runAtMillis; -2035 funcToRun.funcToCall(); -2036 if (funcToRun.recurring) { -2037 this.scheduleFunction(funcToRun.timeoutKey, -2038 funcToRun.funcToCall, -2039 funcToRun.millis, -2040 true); -2041 } -2042 } catch(e) { -2043 } -2044 } -2045 this.runFunctionsWithinRange(oldMillis, nowMillis); -2046 } -2047 }; -2048 -2049 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { -2050 this.scheduledFunctions[timeoutKey] = { -2051 runAtMillis: this.nowMillis + millis, -2052 funcToCall: funcToCall, -2053 recurring: recurring, -2054 timeoutKey: timeoutKey, -2055 millis: millis -2056 }; -2057 }; -2058 -2059 -2060 jasmine.Clock = { -2061 defaultFakeTimer: new jasmine.FakeTimer(), +1978 jasmine.FakeTimer = function() { +1979 this.reset(); +1980 +1981 var self = this; +1982 self.setTimeout = function(funcToCall, millis) { +1983 self.timeoutsMade++; +1984 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); +1985 return self.timeoutsMade; +1986 }; +1987 +1988 self.setInterval = function(funcToCall, millis) { +1989 self.timeoutsMade++; +1990 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); +1991 return self.timeoutsMade; +1992 }; +1993 +1994 self.clearTimeout = function(timeoutKey) { +1995 self.scheduledFunctions[timeoutKey] = undefined; +1996 }; +1997 +1998 self.clearInterval = function(timeoutKey) { +1999 self.scheduledFunctions[timeoutKey] = undefined; +2000 }; +2001 +2002 }; +2003 +2004 jasmine.FakeTimer.prototype.reset = function() { +2005 this.timeoutsMade = 0; +2006 this.scheduledFunctions = {}; +2007 this.nowMillis = 0; +2008 }; +2009 +2010 jasmine.FakeTimer.prototype.tick = function(millis) { +2011 var oldMillis = this.nowMillis; +2012 var newMillis = oldMillis + millis; +2013 this.runFunctionsWithinRange(oldMillis, newMillis); +2014 this.nowMillis = newMillis; +2015 }; +2016 +2017 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { +2018 var scheduledFunc; +2019 var funcsToRun = []; +2020 for (var timeoutKey in this.scheduledFunctions) { +2021 scheduledFunc = this.scheduledFunctions[timeoutKey]; +2022 if (scheduledFunc != undefined && +2023 scheduledFunc.runAtMillis >= oldMillis && +2024 scheduledFunc.runAtMillis <= nowMillis) { +2025 funcsToRun.push(scheduledFunc); +2026 this.scheduledFunctions[timeoutKey] = undefined; +2027 } +2028 } +2029 +2030 if (funcsToRun.length > 0) { +2031 funcsToRun.sort(function(a, b) { +2032 return a.runAtMillis - b.runAtMillis; +2033 }); +2034 for (var i = 0; i < funcsToRun.length; ++i) { +2035 try { +2036 var funcToRun = funcsToRun[i]; +2037 this.nowMillis = funcToRun.runAtMillis; +2038 funcToRun.funcToCall(); +2039 if (funcToRun.recurring) { +2040 this.scheduleFunction(funcToRun.timeoutKey, +2041 funcToRun.funcToCall, +2042 funcToRun.millis, +2043 true); +2044 } +2045 } catch(e) { +2046 } +2047 } +2048 this.runFunctionsWithinRange(oldMillis, nowMillis); +2049 } +2050 }; +2051 +2052 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { +2053 this.scheduledFunctions[timeoutKey] = { +2054 runAtMillis: this.nowMillis + millis, +2055 funcToCall: funcToCall, +2056 recurring: recurring, +2057 timeoutKey: timeoutKey, +2058 millis: millis +2059 }; +2060 }; +2061 2062 -2063 reset: function() { -2064 jasmine.Clock.assertInstalled(); -2065 jasmine.Clock.defaultFakeTimer.reset(); -2066 }, -2067 -2068 tick: function(millis) { -2069 jasmine.Clock.assertInstalled(); -2070 jasmine.Clock.defaultFakeTimer.tick(millis); -2071 }, -2072 -2073 runFunctionsWithinRange: function(oldMillis, nowMillis) { -2074 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); -2075 }, -2076 -2077 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { -2078 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); -2079 }, -2080 -2081 useMock: function() { -2082 var spec = jasmine.getEnv().currentSpec; -2083 spec.after(jasmine.Clock.uninstallMock); -2084 -2085 jasmine.Clock.installMock(); -2086 }, +2063 jasmine.Clock = { +2064 defaultFakeTimer: new jasmine.FakeTimer(), +2065 +2066 reset: function() { +2067 jasmine.Clock.assertInstalled(); +2068 jasmine.Clock.defaultFakeTimer.reset(); +2069 }, +2070 +2071 tick: function(millis) { +2072 jasmine.Clock.assertInstalled(); +2073 jasmine.Clock.defaultFakeTimer.tick(millis); +2074 }, +2075 +2076 runFunctionsWithinRange: function(oldMillis, nowMillis) { +2077 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); +2078 }, +2079 +2080 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { +2081 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); +2082 }, +2083 +2084 useMock: function() { +2085 var spec = jasmine.getEnv().currentSpec; +2086 spec.after(jasmine.Clock.uninstallMock); 2087 -2088 installMock: function() { -2089 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; -2090 }, -2091 -2092 uninstallMock: function() { -2093 jasmine.Clock.assertInstalled(); -2094 jasmine.Clock.installed = jasmine.Clock.real; -2095 }, -2096 -2097 real: { -2098 setTimeout: window.setTimeout, -2099 clearTimeout: window.clearTimeout, -2100 setInterval: window.setInterval, -2101 clearInterval: window.clearInterval -2102 }, -2103 -2104 assertInstalled: function() { -2105 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { -2106 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); -2107 } -2108 }, -2109 -2110 installed: null -2111 }; -2112 jasmine.Clock.installed = jasmine.Clock.real; -2113 -2114 //else for IE support -2115 window.setTimeout = function(funcToCall, millis) { -2116 if (jasmine.Clock.installed.setTimeout.apply) { -2117 return jasmine.Clock.installed.setTimeout.apply(this, arguments); -2118 } else { -2119 return jasmine.Clock.installed.setTimeout(funcToCall, millis); -2120 } -2121 }; -2122 -2123 window.setInterval = function(funcToCall, millis) { -2124 if (jasmine.Clock.installed.setInterval.apply) { -2125 return jasmine.Clock.installed.setInterval.apply(this, arguments); -2126 } else { -2127 return jasmine.Clock.installed.setInterval(funcToCall, millis); -2128 } -2129 }; -2130 -2131 window.clearTimeout = function(timeoutKey) { -2132 if (jasmine.Clock.installed.clearTimeout.apply) { -2133 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); -2134 } else { -2135 return jasmine.Clock.installed.clearTimeout(timeoutKey); -2136 } -2137 }; -2138 -2139 window.clearInterval = function(timeoutKey) { -2140 if (jasmine.Clock.installed.clearTimeout.apply) { -2141 return jasmine.Clock.installed.clearInterval.apply(this, arguments); -2142 } else { -2143 return jasmine.Clock.installed.clearInterval(timeoutKey); -2144 } -2145 }; -2146 -2147 \ No newline at end of file +2088 jasmine.Clock.installMock(); +2089 }, +2090 +2091 installMock: function() { +2092 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; +2093 }, +2094 +2095 uninstallMock: function() { +2096 jasmine.Clock.assertInstalled(); +2097 jasmine.Clock.installed = jasmine.Clock.real; +2098 }, +2099 +2100 real: { +2101 setTimeout: window.setTimeout, +2102 clearTimeout: window.clearTimeout, +2103 setInterval: window.setInterval, +2104 clearInterval: window.clearInterval +2105 }, +2106 +2107 assertInstalled: function() { +2108 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { +2109 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); +2110 } +2111 }, +2112 +2113 installed: null +2114 }; +2115 jasmine.Clock.installed = jasmine.Clock.real; +2116 +2117 //else for IE support +2118 window.setTimeout = function(funcToCall, millis) { +2119 if (jasmine.Clock.installed.setTimeout.apply) { +2120 return jasmine.Clock.installed.setTimeout.apply(this, arguments); +2121 } else { +2122 return jasmine.Clock.installed.setTimeout(funcToCall, millis); +2123 } +2124 }; +2125 +2126 window.setInterval = function(funcToCall, millis) { +2127 if (jasmine.Clock.installed.setInterval.apply) { +2128 return jasmine.Clock.installed.setInterval.apply(this, arguments); +2129 } else { +2130 return jasmine.Clock.installed.setInterval(funcToCall, millis); +2131 } +2132 }; +2133 +2134 window.clearTimeout = function(timeoutKey) { +2135 if (jasmine.Clock.installed.clearTimeout.apply) { +2136 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); +2137 } else { +2138 return jasmine.Clock.installed.clearTimeout(timeoutKey); +2139 } +2140 }; +2141 +2142 window.clearInterval = function(timeoutKey) { +2143 if (jasmine.Clock.installed.clearTimeout.apply) { +2144 return jasmine.Clock.installed.clearInterval.apply(this, arguments); +2145 } else { +2146 return jasmine.Clock.installed.clearInterval(timeoutKey); +2147 } +2148 }; +2149 +2150 \ No newline at end of file diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index 1477b84..2b7e4ba 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -530,7 +530,7 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1256675572 + "revision": 1256687337 }; /** * @namespace diff --git a/spec/suites/MockClockSpec.js b/spec/suites/MockClockSpec.js new file mode 100644 index 0000000..dca3ff2 --- /dev/null +++ b/spec/suites/MockClockSpec.js @@ -0,0 +1,34 @@ +describe("MockClock", function () { + + beforeEach(function() { + jasmine.Clock.useMock(); + }); + + describe("setTimeout", function () { + it("should mock the clock when useMock is in a beforeEach", function() { + var expected = false; + setTimeout(function() { + expected = true; + }, 30000); + expect(expected).toBe(false); + jasmine.Clock.tick(30001); + expect(expected).toBe(true); + }); + }); + + describe("setInterval", function () { + it("should mock the clock when useMock is in a beforeEach", function() { + var interval = 0; + setInterval(function() { + interval++; + }, 30000); + expect(interval).toEqual(0); + jasmine.Clock.tick(30001); + expect(interval).toEqual(1); + jasmine.Clock.tick(30001); + expect(interval).toEqual(2); + jasmine.Clock.tick(1); + expect(interval).toEqual(2); + }); + }); +});