jasmine 1.0.2.1 → 1.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +0 -3
  3. data/README.markdown +7 -1
  4. data/Rakefile +10 -24
  5. data/generators/jasmine/templates/jasmine-example/SpecRunner.html +40 -13
  6. data/generators/jasmine/templates/jasmine-example/spec/SpecHelper.js +3 -3
  7. data/jasmine.gemspec +18 -8
  8. data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +8 -2
  9. data/lib/jasmine/base.rb +9 -6
  10. data/lib/jasmine/command_line_tool.rb +1 -1
  11. data/lib/jasmine/firebug/firebug-1.6.2.xpi +0 -0
  12. data/lib/jasmine/firebug/firebug-1.7.0.xpi +0 -0
  13. data/lib/jasmine/firebug/firebug-license.txt +30 -0
  14. data/lib/jasmine/firebug/firebug.rb +30 -0
  15. data/lib/jasmine/selenium_driver.rb +8 -2
  16. data/lib/jasmine/server.rb +4 -7
  17. data/lib/jasmine/tasks/jasmine.rake +15 -6
  18. data/lib/jasmine/version.rb +1 -1
  19. data/spec/fixture/Rakefile +4 -0
  20. data/spec/fixture/spec/example_spec.js +5 -0
  21. data/spec/fixture/src/example.js +3 -0
  22. data/spec/jasmine_command_line_tool_rakeless_spec.rb +20 -0
  23. data/spec/jasmine_rails2_spec.rb +1 -1
  24. data/spec/jasmine_self_test_config.rb +6 -2
  25. data/spec/jasmine_self_test_spec.rb +0 -1
  26. data/spec/server_spec.rb +12 -11
  27. metadata +39 -92
  28. data/.gitmodules +0 -3
  29. data/jasmine/Gemfile +0 -6
  30. data/jasmine/HowToRelease.markdown +0 -29
  31. data/jasmine/MIT.LICENSE +0 -20
  32. data/jasmine/README.markdown +0 -50
  33. data/jasmine/Rakefile +0 -166
  34. data/jasmine/cruise_config.rb +0 -21
  35. data/jasmine/example/SpecRunner.html +0 -27
  36. data/jasmine/example/spec/PlayerSpec.js +0 -58
  37. data/jasmine/example/spec/SpecHelper.js +0 -9
  38. data/jasmine/example/src/Player.js +0 -22
  39. data/jasmine/example/src/Song.js +0 -7
  40. data/jasmine/images/jasmine_favicon.png +0 -0
  41. data/jasmine/jsdoc-template/allclasses.tmpl +0 -17
  42. data/jasmine/jsdoc-template/allfiles.tmpl +0 -56
  43. data/jasmine/jsdoc-template/class.tmpl +0 -646
  44. data/jasmine/jsdoc-template/index.tmpl +0 -39
  45. data/jasmine/jsdoc-template/publish.js +0 -184
  46. data/jasmine/jsdoc-template/static/default.css +0 -162
  47. data/jasmine/jsdoc-template/static/header.html +0 -2
  48. data/jasmine/jsdoc-template/static/index.html +0 -19
  49. data/jasmine/jsdoc-template/symbol.tmpl +0 -35
  50. data/jasmine/jshint/jshint.js +0 -5919
  51. data/jasmine/jshint/run.js +0 -98
  52. data/jasmine/lib/jasmine-html.js +0 -190
  53. data/jasmine/lib/jasmine.css +0 -166
  54. data/jasmine/lib/jasmine.js +0 -2445
  55. data/jasmine/lib/json2.js +0 -478
  56. data/jasmine/spec/node_suite.js +0 -233
  57. data/jasmine/spec/runner.html +0 -82
  58. data/jasmine/spec/suites/BaseSpec.js +0 -27
  59. data/jasmine/spec/suites/CustomMatchersSpec.js +0 -97
  60. data/jasmine/spec/suites/EnvSpec.js +0 -158
  61. data/jasmine/spec/suites/ExceptionsSpec.js +0 -107
  62. data/jasmine/spec/suites/JsApiReporterSpec.js +0 -103
  63. data/jasmine/spec/suites/MatchersSpec.js +0 -795
  64. data/jasmine/spec/suites/MockClockSpec.js +0 -38
  65. data/jasmine/spec/suites/MultiReporterSpec.js +0 -45
  66. data/jasmine/spec/suites/NestedResultsSpec.js +0 -54
  67. data/jasmine/spec/suites/PrettyPrintSpec.js +0 -93
  68. data/jasmine/spec/suites/QueueSpec.js +0 -23
  69. data/jasmine/spec/suites/ReporterSpec.js +0 -56
  70. data/jasmine/spec/suites/RunnerSpec.js +0 -267
  71. data/jasmine/spec/suites/SpecRunningSpec.js +0 -1253
  72. data/jasmine/spec/suites/SpecSpec.js +0 -124
  73. data/jasmine/spec/suites/SpySpec.js +0 -201
  74. data/jasmine/spec/suites/SuiteSpec.js +0 -120
  75. data/jasmine/spec/suites/TrivialConsoleReporterSpec.js +0 -431
  76. data/jasmine/spec/suites/TrivialReporterSpec.js +0 -238
  77. data/jasmine/spec/suites/UtilSpec.js +0 -39
  78. data/jasmine/spec/suites/WaitsForBlockSpec.js +0 -118
  79. data/jasmine/src/Block.js +0 -22
  80. data/jasmine/src/Env.js +0 -264
  81. data/jasmine/src/JsApiReporter.js +0 -102
  82. data/jasmine/src/Matchers.js +0 -354
  83. data/jasmine/src/MultiReporter.js +0 -35
  84. data/jasmine/src/NestedResults.js +0 -80
  85. data/jasmine/src/PrettyPrinter.js +0 -123
  86. data/jasmine/src/Queue.js +0 -99
  87. data/jasmine/src/Reporter.js +0 -31
  88. data/jasmine/src/Runner.js +0 -77
  89. data/jasmine/src/Spec.js +0 -242
  90. data/jasmine/src/Suite.js +0 -82
  91. data/jasmine/src/WaitsBlock.js +0 -15
  92. data/jasmine/src/WaitsForBlock.js +0 -54
  93. data/jasmine/src/base.js +0 -608
  94. data/jasmine/src/console/TrivialConsoleReporter.js +0 -144
  95. data/jasmine/src/html/TrivialReporter.js +0 -190
  96. data/jasmine/src/html/jasmine.css +0 -166
  97. data/jasmine/src/mock-timeout.js +0 -183
  98. data/jasmine/src/util.js +0 -67
  99. data/jasmine/src/version.json +0 -5
@@ -1,242 +0,0 @@
1
- /**
2
- * Internal representation of a Jasmine specification, or test.
3
- *
4
- * @constructor
5
- * @param {jasmine.Env} env
6
- * @param {jasmine.Suite} suite
7
- * @param {String} description
8
- */
9
- jasmine.Spec = function(env, suite, description) {
10
- if (!env) {
11
- throw new Error('jasmine.Env() required');
12
- }
13
- if (!suite) {
14
- throw new Error('jasmine.Suite() required');
15
- }
16
- var spec = this;
17
- spec.id = env.nextSpecId ? env.nextSpecId() : null;
18
- spec.env = env;
19
- spec.suite = suite;
20
- spec.description = description;
21
- spec.queue = new jasmine.Queue(env);
22
-
23
- spec.afterCallbacks = [];
24
- spec.spies_ = [];
25
-
26
- spec.results_ = new jasmine.NestedResults();
27
- spec.results_.description = description;
28
- spec.matchersClass = null;
29
- };
30
-
31
- jasmine.Spec.prototype.getFullName = function() {
32
- return this.suite.getFullName() + ' ' + this.description + '.';
33
- };
34
-
35
-
36
- jasmine.Spec.prototype.results = function() {
37
- return this.results_;
38
- };
39
-
40
- /**
41
- * All parameters are pretty-printed and concatenated together, then written to the spec's output.
42
- *
43
- * Be careful not to leave calls to <code>jasmine.log</code> in production code.
44
- */
45
- jasmine.Spec.prototype.log = function() {
46
- return this.results_.log(arguments);
47
- };
48
-
49
- jasmine.Spec.prototype.runs = function (func) {
50
- var block = new jasmine.Block(this.env, func, this);
51
- this.addToQueue(block);
52
- return this;
53
- };
54
-
55
- jasmine.Spec.prototype.addToQueue = function (block) {
56
- if (this.queue.isRunning()) {
57
- this.queue.insertNext(block);
58
- } else {
59
- this.queue.add(block);
60
- }
61
- };
62
-
63
- /**
64
- * @param {jasmine.ExpectationResult} result
65
- */
66
- jasmine.Spec.prototype.addMatcherResult = function(result) {
67
- this.results_.addResult(result);
68
- };
69
-
70
- jasmine.Spec.prototype.expect = function(actual) {
71
- var positive = new (this.getMatchersClass_())(this.env, actual, this);
72
- positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
73
- return positive;
74
- };
75
-
76
- /**
77
- * Waits a fixed time period before moving to the next block.
78
- *
79
- * @deprecated Use waitsFor() instead
80
- * @param {Number} timeout milliseconds to wait
81
- */
82
- jasmine.Spec.prototype.waits = function(timeout) {
83
- var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
84
- this.addToQueue(waitsFunc);
85
- return this;
86
- };
87
-
88
- /**
89
- * Waits for the latchFunction to return true before proceeding to the next block.
90
- *
91
- * @param {Function} latchFunction
92
- * @param {String} optional_timeoutMessage
93
- * @param {Number} optional_timeout
94
- */
95
- jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
96
- var latchFunction_ = null;
97
- var optional_timeoutMessage_ = null;
98
- var optional_timeout_ = null;
99
-
100
- for (var i = 0; i < arguments.length; i++) {
101
- var arg = arguments[i];
102
- switch (typeof arg) {
103
- case 'function':
104
- latchFunction_ = arg;
105
- break;
106
- case 'string':
107
- optional_timeoutMessage_ = arg;
108
- break;
109
- case 'number':
110
- optional_timeout_ = arg;
111
- break;
112
- }
113
- }
114
-
115
- var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
116
- this.addToQueue(waitsForFunc);
117
- return this;
118
- };
119
-
120
- jasmine.Spec.prototype.fail = function (e) {
121
- var expectationResult = new jasmine.ExpectationResult({
122
- passed: false,
123
- message: e ? jasmine.util.formatException(e) : 'Exception'
124
- });
125
- this.results_.addResult(expectationResult);
126
- };
127
-
128
- jasmine.Spec.prototype.getMatchersClass_ = function() {
129
- return this.matchersClass || this.env.matchersClass;
130
- };
131
-
132
- jasmine.Spec.prototype.addMatchers = function(matchersPrototype) {
133
- var parent = this.getMatchersClass_();
134
- var newMatchersClass = function() {
135
- parent.apply(this, arguments);
136
- };
137
- jasmine.util.inherit(newMatchersClass, parent);
138
- jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass);
139
- this.matchersClass = newMatchersClass;
140
- };
141
-
142
- jasmine.Spec.prototype.finishCallback = function() {
143
- this.env.reporter.reportSpecResults(this);
144
- };
145
-
146
- jasmine.Spec.prototype.finish = function(onComplete) {
147
- this.removeAllSpies();
148
- this.finishCallback();
149
- if (onComplete) {
150
- onComplete();
151
- }
152
- };
153
-
154
- jasmine.Spec.prototype.after = function(doAfter) {
155
- if (this.queue.isRunning()) {
156
- this.queue.add(new jasmine.Block(this.env, doAfter, this));
157
- } else {
158
- this.afterCallbacks.unshift(doAfter);
159
- }
160
- };
161
-
162
- jasmine.Spec.prototype.execute = function(onComplete) {
163
- var spec = this;
164
- if (!spec.env.specFilter(spec)) {
165
- spec.results_.skipped = true;
166
- spec.finish(onComplete);
167
- return;
168
- }
169
-
170
- this.env.reporter.reportSpecStarting(this);
171
-
172
- spec.env.currentSpec = spec;
173
-
174
- spec.addBeforesAndAftersToQueue();
175
-
176
- spec.queue.start(function () {
177
- spec.finish(onComplete);
178
- });
179
- };
180
-
181
- jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
182
- var runner = this.env.currentRunner();
183
- var i;
184
-
185
- for (var suite = this.suite; suite; suite = suite.parentSuite) {
186
- for (i = 0; i < suite.before_.length; i++) {
187
- this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
188
- }
189
- }
190
- for (i = 0; i < runner.before_.length; i++) {
191
- this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
192
- }
193
- for (i = 0; i < this.afterCallbacks.length; i++) {
194
- this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this));
195
- }
196
- for (suite = this.suite; suite; suite = suite.parentSuite) {
197
- for (i = 0; i < suite.after_.length; i++) {
198
- this.queue.add(new jasmine.Block(this.env, suite.after_[i], this));
199
- }
200
- }
201
- for (i = 0; i < runner.after_.length; i++) {
202
- this.queue.add(new jasmine.Block(this.env, runner.after_[i], this));
203
- }
204
- };
205
-
206
- jasmine.Spec.prototype.explodes = function() {
207
- throw 'explodes function should not have been called';
208
- };
209
-
210
- jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) {
211
- if (obj == jasmine.undefined) {
212
- throw "spyOn could not find an object to spy upon for " + methodName + "()";
213
- }
214
-
215
- if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
216
- throw methodName + '() method does not exist';
217
- }
218
-
219
- if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) {
220
- throw new Error(methodName + ' has already been spied upon');
221
- }
222
-
223
- var spyObj = jasmine.createSpy(methodName);
224
-
225
- this.spies_.push(spyObj);
226
- spyObj.baseObj = obj;
227
- spyObj.methodName = methodName;
228
- spyObj.originalValue = obj[methodName];
229
-
230
- obj[methodName] = spyObj;
231
-
232
- return spyObj;
233
- };
234
-
235
- jasmine.Spec.prototype.removeAllSpies = function() {
236
- for (var i = 0; i < this.spies_.length; i++) {
237
- var spy = this.spies_[i];
238
- spy.baseObj[spy.methodName] = spy.originalValue;
239
- }
240
- this.spies_ = [];
241
- };
242
-
@@ -1,82 +0,0 @@
1
- /**
2
- * Internal representation of a Jasmine suite.
3
- *
4
- * @constructor
5
- * @param {jasmine.Env} env
6
- * @param {String} description
7
- * @param {Function} specDefinitions
8
- * @param {jasmine.Suite} parentSuite
9
- */
10
- jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
11
- var self = this;
12
- self.id = env.nextSuiteId ? env.nextSuiteId() : null;
13
- self.description = description;
14
- self.queue = new jasmine.Queue(env);
15
- self.parentSuite = parentSuite;
16
- self.env = env;
17
- self.before_ = [];
18
- self.after_ = [];
19
- self.children_ = [];
20
- self.suites_ = [];
21
- self.specs_ = [];
22
- };
23
-
24
- jasmine.Suite.prototype.getFullName = function() {
25
- var fullName = this.description;
26
- for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
27
- fullName = parentSuite.description + ' ' + fullName;
28
- }
29
- return fullName;
30
- };
31
-
32
- jasmine.Suite.prototype.finish = function(onComplete) {
33
- this.env.reporter.reportSuiteResults(this);
34
- this.finished = true;
35
- if (typeof(onComplete) == 'function') {
36
- onComplete();
37
- }
38
- };
39
-
40
- jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
41
- beforeEachFunction.typeName = 'beforeEach';
42
- this.before_.unshift(beforeEachFunction);
43
- };
44
-
45
- jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
46
- afterEachFunction.typeName = 'afterEach';
47
- this.after_.unshift(afterEachFunction);
48
- };
49
-
50
- jasmine.Suite.prototype.results = function() {
51
- return this.queue.results();
52
- };
53
-
54
- jasmine.Suite.prototype.add = function(suiteOrSpec) {
55
- this.children_.push(suiteOrSpec);
56
- if (suiteOrSpec instanceof jasmine.Suite) {
57
- this.suites_.push(suiteOrSpec);
58
- this.env.currentRunner().addSuite(suiteOrSpec);
59
- } else {
60
- this.specs_.push(suiteOrSpec);
61
- }
62
- this.queue.add(suiteOrSpec);
63
- };
64
-
65
- jasmine.Suite.prototype.specs = function() {
66
- return this.specs_;
67
- };
68
-
69
- jasmine.Suite.prototype.suites = function() {
70
- return this.suites_;
71
- };
72
-
73
- jasmine.Suite.prototype.children = function() {
74
- return this.children_;
75
- };
76
-
77
- jasmine.Suite.prototype.execute = function(onComplete) {
78
- var self = this;
79
- this.queue.start(function () {
80
- self.finish(onComplete);
81
- });
82
- };
@@ -1,15 +0,0 @@
1
- jasmine.WaitsBlock = function(env, timeout, spec) {
2
- this.timeout = timeout;
3
- jasmine.Block.call(this, env, null, spec);
4
- };
5
-
6
- jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
7
-
8
- jasmine.WaitsBlock.prototype.execute = function (onComplete) {
9
- if (jasmine.VERBOSE) {
10
- this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
11
- }
12
- this.env.setTimeout(function () {
13
- onComplete();
14
- }, this.timeout);
15
- };
@@ -1,54 +0,0 @@
1
- /**
2
- * A block which waits for some condition to become true, with timeout.
3
- *
4
- * @constructor
5
- * @extends jasmine.Block
6
- * @param {jasmine.Env} env The Jasmine environment.
7
- * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
8
- * @param {Function} latchFunction A function which returns true when the desired condition has been met.
9
- * @param {String} message The message to display if the desired condition hasn't been met within the given time period.
10
- * @param {jasmine.Spec} spec The Jasmine spec.
11
- */
12
- jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
13
- this.timeout = timeout || env.defaultTimeoutInterval;
14
- this.latchFunction = latchFunction;
15
- this.message = message;
16
- this.totalTimeSpentWaitingForLatch = 0;
17
- jasmine.Block.call(this, env, null, spec);
18
- };
19
- jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
20
-
21
- jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
22
-
23
- jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
24
- if (jasmine.VERBOSE) {
25
- this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
26
- }
27
- var latchFunctionResult;
28
- try {
29
- latchFunctionResult = this.latchFunction.apply(this.spec);
30
- } catch (e) {
31
- this.spec.fail(e);
32
- onComplete();
33
- return;
34
- }
35
-
36
- if (latchFunctionResult) {
37
- onComplete();
38
- } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
39
- var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
40
- this.spec.fail({
41
- name: 'timeout',
42
- message: message
43
- });
44
-
45
- this.abort = true;
46
- onComplete();
47
- } else {
48
- this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
49
- var self = this;
50
- this.env.setTimeout(function() {
51
- self.execute(onComplete);
52
- }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
53
- }
54
- };
@@ -1,608 +0,0 @@
1
- var isCommonJS = typeof window == "undefined";
2
-
3
- /**
4
- * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
5
- *
6
- * @namespace
7
- */
8
- var jasmine = {};
9
- if (isCommonJS) exports.jasmine = jasmine;
10
- /**
11
- * @private
12
- */
13
- jasmine.unimplementedMethod_ = function() {
14
- throw new Error("unimplemented method");
15
- };
16
-
17
- /**
18
- * Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just
19
- * a plain old variable and may be redefined by somebody else.
20
- *
21
- * @private
22
- */
23
- jasmine.undefined = jasmine.___undefined___;
24
-
25
- /**
26
- * Show diagnostic messages in the console if set to true
27
- *
28
- */
29
- jasmine.VERBOSE = false;
30
-
31
- /**
32
- * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
33
- *
34
- */
35
- jasmine.DEFAULT_UPDATE_INTERVAL = 250;
36
-
37
- /**
38
- * Default timeout interval in milliseconds for waitsFor() blocks.
39
- */
40
- jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
41
-
42
- jasmine.getGlobal = function() {
43
- function getGlobal() {
44
- return this;
45
- }
46
-
47
- return getGlobal();
48
- };
49
-
50
- /**
51
- * Allows for bound functions to be compared. Internal use only.
52
- *
53
- * @ignore
54
- * @private
55
- * @param base {Object} bound 'this' for the function
56
- * @param name {Function} function to find
57
- */
58
- jasmine.bindOriginal_ = function(base, name) {
59
- var original = base[name];
60
- if (original.apply) {
61
- return function() {
62
- return original.apply(base, arguments);
63
- };
64
- } else {
65
- // IE support
66
- return jasmine.getGlobal()[name];
67
- }
68
- };
69
-
70
- jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');
71
- jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout');
72
- jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval');
73
- jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval');
74
-
75
- jasmine.MessageResult = function(values) {
76
- this.type = 'log';
77
- this.values = values;
78
- this.trace = new Error(); // todo: test better
79
- };
80
-
81
- jasmine.MessageResult.prototype.toString = function() {
82
- var text = "";
83
- for(var i = 0; i < this.values.length; i++) {
84
- if (i > 0) text += " ";
85
- if (jasmine.isString_(this.values[i])) {
86
- text += this.values[i];
87
- } else {
88
- text += jasmine.pp(this.values[i]);
89
- }
90
- }
91
- return text;
92
- };
93
-
94
- jasmine.ExpectationResult = function(params) {
95
- this.type = 'expect';
96
- this.matcherName = params.matcherName;
97
- this.passed_ = params.passed;
98
- this.expected = params.expected;
99
- this.actual = params.actual;
100
-
101
- this.message = this.passed_ ? 'Passed.' : params.message;
102
- this.trace = this.passed_ ? '' : new Error(this.message);
103
- };
104
-
105
- jasmine.ExpectationResult.prototype.toString = function () {
106
- return this.message;
107
- };
108
-
109
- jasmine.ExpectationResult.prototype.passed = function () {
110
- return this.passed_;
111
- };
112
-
113
- /**
114
- * Getter for the Jasmine environment. Ensures one gets created
115
- */
116
- jasmine.getEnv = function() {
117
- var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
118
- return env;
119
- };
120
-
121
- /**
122
- * @ignore
123
- * @private
124
- * @param value
125
- * @returns {Boolean}
126
- */
127
- jasmine.isArray_ = function(value) {
128
- return jasmine.isA_("Array", value);
129
- };
130
-
131
- /**
132
- * @ignore
133
- * @private
134
- * @param value
135
- * @returns {Boolean}
136
- */
137
- jasmine.isString_ = function(value) {
138
- return jasmine.isA_("String", value);
139
- };
140
-
141
- /**
142
- * @ignore
143
- * @private
144
- * @param value
145
- * @returns {Boolean}
146
- */
147
- jasmine.isNumber_ = function(value) {
148
- return jasmine.isA_("Number", value);
149
- };
150
-
151
- /**
152
- * @ignore
153
- * @private
154
- * @param {String} typeName
155
- * @param value
156
- * @returns {Boolean}
157
- */
158
- jasmine.isA_ = function(typeName, value) {
159
- return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
160
- };
161
-
162
- /**
163
- * Pretty printer for expecations. Takes any object and turns it into a human-readable string.
164
- *
165
- * @param value {Object} an object to be outputted
166
- * @returns {String}
167
- */
168
- jasmine.pp = function(value) {
169
- var stringPrettyPrinter = new jasmine.StringPrettyPrinter();
170
- stringPrettyPrinter.format(value);
171
- return stringPrettyPrinter.string;
172
- };
173
-
174
- /**
175
- * Returns true if the object is a DOM Node.
176
- *
177
- * @param {Object} obj object to check
178
- * @returns {Boolean}
179
- */
180
- jasmine.isDomNode = function(obj) {
181
- return obj.nodeType > 0;
182
- };
183
-
184
- /**
185
- * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter.
186
- *
187
- * @example
188
- * // don't care about which function is passed in, as long as it's a function
189
- * expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function));
190
- *
191
- * @param {Class} clazz
192
- * @returns matchable object of the type clazz
193
- */
194
- jasmine.any = function(clazz) {
195
- return new jasmine.Matchers.Any(clazz);
196
- };
197
-
198
- /**
199
- * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
200
- *
201
- * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine
202
- * expectation syntax. Spies can be checked if they were called or not and what the calling params were.
203
- *
204
- * A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs).
205
- *
206
- * Spies are torn down at the end of every spec.
207
- *
208
- * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj.
209
- *
210
- * @example
211
- * // a stub
212
- * var myStub = jasmine.createSpy('myStub'); // can be used anywhere
213
- *
214
- * // spy example
215
- * var foo = {
216
- * not: function(bool) { return !bool; }
217
- * }
218
- *
219
- * // actual foo.not will not be called, execution stops
220
- * spyOn(foo, 'not');
221
-
222
- // foo.not spied upon, execution will continue to implementation
223
- * spyOn(foo, 'not').andCallThrough();
224
- *
225
- * // fake example
226
- * var foo = {
227
- * not: function(bool) { return !bool; }
228
- * }
229
- *
230
- * // foo.not(val) will return val
231
- * spyOn(foo, 'not').andCallFake(function(value) {return value;});
232
- *
233
- * // mock example
234
- * foo.not(7 == 7);
235
- * expect(foo.not).toHaveBeenCalled();
236
- * expect(foo.not).toHaveBeenCalledWith(true);
237
- *
238
- * @constructor
239
- * @see spyOn, jasmine.createSpy, jasmine.createSpyObj
240
- * @param {String} name
241
- */
242
- jasmine.Spy = function(name) {
243
- /**
244
- * The name of the spy, if provided.
245
- */
246
- this.identity = name || 'unknown';
247
- /**
248
- * Is this Object a spy?
249
- */
250
- this.isSpy = true;
251
- /**
252
- * The actual function this spy stubs.
253
- */
254
- this.plan = function() {
255
- };
256
- /**
257
- * Tracking of the most recent call to the spy.
258
- * @example
259
- * var mySpy = jasmine.createSpy('foo');
260
- * mySpy(1, 2);
261
- * mySpy.mostRecentCall.args = [1, 2];
262
- */
263
- this.mostRecentCall = {};
264
-
265
- /**
266
- * Holds arguments for each call to the spy, indexed by call count
267
- * @example
268
- * var mySpy = jasmine.createSpy('foo');
269
- * mySpy(1, 2);
270
- * mySpy(7, 8);
271
- * mySpy.mostRecentCall.args = [7, 8];
272
- * mySpy.argsForCall[0] = [1, 2];
273
- * mySpy.argsForCall[1] = [7, 8];
274
- */
275
- this.argsForCall = [];
276
- this.calls = [];
277
- };
278
-
279
- /**
280
- * Tells a spy to call through to the actual implemenatation.
281
- *
282
- * @example
283
- * var foo = {
284
- * bar: function() { // do some stuff }
285
- * }
286
- *
287
- * // defining a spy on an existing property: foo.bar
288
- * spyOn(foo, 'bar').andCallThrough();
289
- */
290
- jasmine.Spy.prototype.andCallThrough = function() {
291
- this.plan = this.originalValue;
292
- return this;
293
- };
294
-
295
- /**
296
- * For setting the return value of a spy.
297
- *
298
- * @example
299
- * // defining a spy from scratch: foo() returns 'baz'
300
- * var foo = jasmine.createSpy('spy on foo').andReturn('baz');
301
- *
302
- * // defining a spy on an existing property: foo.bar() returns 'baz'
303
- * spyOn(foo, 'bar').andReturn('baz');
304
- *
305
- * @param {Object} value
306
- */
307
- jasmine.Spy.prototype.andReturn = function(value) {
308
- this.plan = function() {
309
- return value;
310
- };
311
- return this;
312
- };
313
-
314
- /**
315
- * For throwing an exception when a spy is called.
316
- *
317
- * @example
318
- * // defining a spy from scratch: foo() throws an exception w/ message 'ouch'
319
- * var foo = jasmine.createSpy('spy on foo').andThrow('baz');
320
- *
321
- * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch'
322
- * spyOn(foo, 'bar').andThrow('baz');
323
- *
324
- * @param {String} exceptionMsg
325
- */
326
- jasmine.Spy.prototype.andThrow = function(exceptionMsg) {
327
- this.plan = function() {
328
- throw exceptionMsg;
329
- };
330
- return this;
331
- };
332
-
333
- /**
334
- * Calls an alternate implementation when a spy is called.
335
- *
336
- * @example
337
- * var baz = function() {
338
- * // do some stuff, return something
339
- * }
340
- * // defining a spy from scratch: foo() calls the function baz
341
- * var foo = jasmine.createSpy('spy on foo').andCall(baz);
342
- *
343
- * // defining a spy on an existing property: foo.bar() calls an anonymnous function
344
- * spyOn(foo, 'bar').andCall(function() { return 'baz';} );
345
- *
346
- * @param {Function} fakeFunc
347
- */
348
- jasmine.Spy.prototype.andCallFake = function(fakeFunc) {
349
- this.plan = fakeFunc;
350
- return this;
351
- };
352
-
353
- /**
354
- * Resets all of a spy's the tracking variables so that it can be used again.
355
- *
356
- * @example
357
- * spyOn(foo, 'bar');
358
- *
359
- * foo.bar();
360
- *
361
- * expect(foo.bar.callCount).toEqual(1);
362
- *
363
- * foo.bar.reset();
364
- *
365
- * expect(foo.bar.callCount).toEqual(0);
366
- */
367
- jasmine.Spy.prototype.reset = function() {
368
- this.wasCalled = false;
369
- this.callCount = 0;
370
- this.argsForCall = [];
371
- this.calls = [];
372
- this.mostRecentCall = {};
373
- };
374
-
375
- jasmine.createSpy = function(name) {
376
-
377
- var spyObj = function() {
378
- spyObj.wasCalled = true;
379
- spyObj.callCount++;
380
- var args = jasmine.util.argsToArray(arguments);
381
- spyObj.mostRecentCall.object = this;
382
- spyObj.mostRecentCall.args = args;
383
- spyObj.argsForCall.push(args);
384
- spyObj.calls.push({object: this, args: args});
385
- return spyObj.plan.apply(this, arguments);
386
- };
387
-
388
- var spy = new jasmine.Spy(name);
389
-
390
- for (var prop in spy) {
391
- spyObj[prop] = spy[prop];
392
- }
393
-
394
- spyObj.reset();
395
-
396
- return spyObj;
397
- };
398
-
399
- /**
400
- * Determines whether an object is a spy.
401
- *
402
- * @param {jasmine.Spy|Object} putativeSpy
403
- * @returns {Boolean}
404
- */
405
- jasmine.isSpy = function(putativeSpy) {
406
- return putativeSpy && putativeSpy.isSpy;
407
- };
408
-
409
- /**
410
- * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something
411
- * large in one call.
412
- *
413
- * @param {String} baseName name of spy class
414
- * @param {Array} methodNames array of names of methods to make spies
415
- */
416
- jasmine.createSpyObj = function(baseName, methodNames) {
417
- if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
418
- throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
419
- }
420
- var obj = {};
421
- for (var i = 0; i < methodNames.length; i++) {
422
- obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]);
423
- }
424
- return obj;
425
- };
426
-
427
- /**
428
- * All parameters are pretty-printed and concatenated together, then written to the current spec's output.
429
- *
430
- * Be careful not to leave calls to <code>jasmine.log</code> in production code.
431
- */
432
- jasmine.log = function() {
433
- var spec = jasmine.getEnv().currentSpec;
434
- spec.log.apply(spec, arguments);
435
- };
436
-
437
- /**
438
- * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
439
- *
440
- * @example
441
- * // spy example
442
- * var foo = {
443
- * not: function(bool) { return !bool; }
444
- * }
445
- * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
446
- *
447
- * @see jasmine.createSpy
448
- * @param obj
449
- * @param methodName
450
- * @returns a Jasmine spy that can be chained with all spy methods
451
- */
452
- var spyOn = function(obj, methodName) {
453
- return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
454
- };
455
- if (isCommonJS) exports.spyOn = spyOn;
456
-
457
- /**
458
- * Creates a Jasmine spec that will be added to the current suite.
459
- *
460
- * // TODO: pending tests
461
- *
462
- * @example
463
- * it('should be true', function() {
464
- * expect(true).toEqual(true);
465
- * });
466
- *
467
- * @param {String} desc description of this specification
468
- * @param {Function} func defines the preconditions and expectations of the spec
469
- */
470
- var it = function(desc, func) {
471
- return jasmine.getEnv().it(desc, func);
472
- };
473
- if (isCommonJS) exports.it = it;
474
-
475
- /**
476
- * Creates a <em>disabled</em> Jasmine spec.
477
- *
478
- * A convenience method that allows existing specs to be disabled temporarily during development.
479
- *
480
- * @param {String} desc description of this specification
481
- * @param {Function} func defines the preconditions and expectations of the spec
482
- */
483
- var xit = function(desc, func) {
484
- return jasmine.getEnv().xit(desc, func);
485
- };
486
- if (isCommonJS) exports.xit = xit;
487
-
488
- /**
489
- * Starts a chain for a Jasmine expectation.
490
- *
491
- * It is passed an Object that is the actual value and should chain to one of the many
492
- * jasmine.Matchers functions.
493
- *
494
- * @param {Object} actual Actual value to test against and expected value
495
- */
496
- var expect = function(actual) {
497
- return jasmine.getEnv().currentSpec.expect(actual);
498
- };
499
- if (isCommonJS) exports.expect = expect;
500
-
501
- /**
502
- * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
503
- *
504
- * @param {Function} func Function that defines part of a jasmine spec.
505
- */
506
- var runs = function(func) {
507
- jasmine.getEnv().currentSpec.runs(func);
508
- };
509
- if (isCommonJS) exports.runs = runs;
510
-
511
- /**
512
- * Waits a fixed time period before moving to the next block.
513
- *
514
- * @deprecated Use waitsFor() instead
515
- * @param {Number} timeout milliseconds to wait
516
- */
517
- var waits = function(timeout) {
518
- jasmine.getEnv().currentSpec.waits(timeout);
519
- };
520
- if (isCommonJS) exports.waits = waits;
521
-
522
- /**
523
- * Waits for the latchFunction to return true before proceeding to the next block.
524
- *
525
- * @param {Function} latchFunction
526
- * @param {String} optional_timeoutMessage
527
- * @param {Number} optional_timeout
528
- */
529
- var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
530
- jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
531
- };
532
- if (isCommonJS) exports.waitsFor = waitsFor;
533
-
534
- /**
535
- * A function that is called before each spec in a suite.
536
- *
537
- * Used for spec setup, including validating assumptions.
538
- *
539
- * @param {Function} beforeEachFunction
540
- */
541
- var beforeEach = function(beforeEachFunction) {
542
- jasmine.getEnv().beforeEach(beforeEachFunction);
543
- };
544
- if (isCommonJS) exports.beforeEach = beforeEach;
545
-
546
- /**
547
- * A function that is called after each spec in a suite.
548
- *
549
- * Used for restoring any state that is hijacked during spec execution.
550
- *
551
- * @param {Function} afterEachFunction
552
- */
553
- var afterEach = function(afterEachFunction) {
554
- jasmine.getEnv().afterEach(afterEachFunction);
555
- };
556
- if (isCommonJS) exports.afterEach = afterEach;
557
-
558
- /**
559
- * Defines a suite of specifications.
560
- *
561
- * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
562
- * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
563
- * of setup in some tests.
564
- *
565
- * @example
566
- * // TODO: a simple suite
567
- *
568
- * // TODO: a simple suite with a nested describe block
569
- *
570
- * @param {String} description A string, usually the class under test.
571
- * @param {Function} specDefinitions function that defines several specs.
572
- */
573
- var describe = function(description, specDefinitions) {
574
- return jasmine.getEnv().describe(description, specDefinitions);
575
- };
576
- if (isCommonJS) exports.describe = describe;
577
-
578
- /**
579
- * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
580
- *
581
- * @param {String} description A string, usually the class under test.
582
- * @param {Function} specDefinitions function that defines several specs.
583
- */
584
- var xdescribe = function(description, specDefinitions) {
585
- return jasmine.getEnv().xdescribe(description, specDefinitions);
586
- };
587
- if (isCommonJS) exports.xdescribe = xdescribe;
588
-
589
-
590
- // Provide the XMLHttpRequest class for IE 5.x-6.x:
591
- jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
592
- function tryIt(f) {
593
- try {
594
- return f();
595
- } catch(e) {
596
- }
597
- return null;
598
- }
599
-
600
- var xhr = tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.6.0");}) ||
601
- tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0");}) ||
602
- tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP");}) ||
603
- tryIt(function(){return new ActiveXObject("Microsoft.XMLHTTP");});
604
-
605
- if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
606
-
607
- return xhr;
608
- } : XMLHttpRequest;