josephholsten-jasmine 1.1.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.gitmodules +3 -0
- data/Gemfile +5 -0
- data/HOW_TO_TEST.markdown +9 -0
- data/MIT.LICENSE +20 -0
- data/README.markdown +71 -0
- data/RELEASE.markdown +22 -0
- data/Rakefile +76 -0
- data/bin/jasmine +6 -0
- data/generators/jasmine/jasmine_generator.rb +32 -0
- data/generators/jasmine/templates/INSTALL +9 -0
- data/generators/jasmine/templates/jasmine-example/SpecRunner.html +27 -0
- data/generators/jasmine/templates/jasmine-example/spec/PlayerSpec.js +58 -0
- data/generators/jasmine/templates/jasmine-example/spec/SpecHelper.js +9 -0
- data/generators/jasmine/templates/jasmine-example/src/Player.js +22 -0
- data/generators/jasmine/templates/jasmine-example/src/Song.js +7 -0
- data/generators/jasmine/templates/lib/tasks/jasmine.rake +8 -0
- data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
- data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
- data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/jasmine/Gemfile +6 -0
- data/jasmine/Gemfile.lock +33 -0
- data/jasmine/HowToRelease.markdown +29 -0
- data/jasmine/MIT.LICENSE +20 -0
- data/jasmine/README.markdown +50 -0
- data/jasmine/Rakefile +166 -0
- data/jasmine/cruise_config.rb +21 -0
- data/jasmine/example/SpecRunner.html +27 -0
- data/jasmine/example/spec/PlayerSpec.js +58 -0
- data/jasmine/example/spec/SpecHelper.js +9 -0
- data/jasmine/example/src/Player.js +22 -0
- data/jasmine/example/src/Song.js +7 -0
- data/jasmine/images/jasmine_favicon.png +0 -0
- data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
- data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
- data/jasmine/jsdoc-template/class.tmpl +646 -0
- data/jasmine/jsdoc-template/index.tmpl +39 -0
- data/jasmine/jsdoc-template/publish.js +184 -0
- data/jasmine/jsdoc-template/static/default.css +162 -0
- data/jasmine/jsdoc-template/static/header.html +2 -0
- data/jasmine/jsdoc-template/static/index.html +19 -0
- data/jasmine/jsdoc-template/symbol.tmpl +35 -0
- data/jasmine/jshint/jshint.js +5919 -0
- data/jasmine/jshint/run.js +98 -0
- data/jasmine/lib/jasmine-html.js +190 -0
- data/jasmine/lib/jasmine.css +166 -0
- data/jasmine/lib/jasmine.js +2445 -0
- data/jasmine/lib/json2.js +478 -0
- data/jasmine/spec/node_suite.js +233 -0
- data/jasmine/spec/runner.html +82 -0
- data/jasmine/spec/suites/BaseSpec.js +27 -0
- data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
- data/jasmine/spec/suites/EnvSpec.js +158 -0
- data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
- data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
- data/jasmine/spec/suites/MatchersSpec.js +795 -0
- data/jasmine/spec/suites/MockClockSpec.js +38 -0
- data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
- data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
- data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
- data/jasmine/spec/suites/QueueSpec.js +23 -0
- data/jasmine/spec/suites/ReporterSpec.js +56 -0
- data/jasmine/spec/suites/RunnerSpec.js +267 -0
- data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
- data/jasmine/spec/suites/SpecSpec.js +124 -0
- data/jasmine/spec/suites/SpySpec.js +201 -0
- data/jasmine/spec/suites/SuiteSpec.js +120 -0
- data/jasmine/spec/suites/TrivialConsoleReporterSpec.js +431 -0
- data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
- data/jasmine/spec/suites/UtilSpec.js +39 -0
- data/jasmine/spec/suites/WaitsForBlockSpec.js +118 -0
- data/jasmine/src/Block.js +22 -0
- data/jasmine/src/Env.js +264 -0
- data/jasmine/src/JsApiReporter.js +102 -0
- data/jasmine/src/Matchers.js +354 -0
- data/jasmine/src/MultiReporter.js +35 -0
- data/jasmine/src/NestedResults.js +80 -0
- data/jasmine/src/PrettyPrinter.js +123 -0
- data/jasmine/src/Queue.js +99 -0
- data/jasmine/src/Reporter.js +31 -0
- data/jasmine/src/Runner.js +77 -0
- data/jasmine/src/Spec.js +242 -0
- data/jasmine/src/Suite.js +82 -0
- data/jasmine/src/WaitsBlock.js +15 -0
- data/jasmine/src/WaitsForBlock.js +54 -0
- data/jasmine/src/base.js +608 -0
- data/jasmine/src/console/TrivialConsoleReporter.js +144 -0
- data/jasmine/src/html/TrivialReporter.js +190 -0
- data/jasmine/src/html/jasmine.css +166 -0
- data/jasmine/src/mock-timeout.js +183 -0
- data/jasmine/src/util.js +67 -0
- data/jasmine/src/version.json +5 -0
- data/jasmine.gemspec +52 -0
- data/lib/generators/jasmine/examples/USAGE +11 -0
- data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
- data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
- data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
- data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
- data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
- data/lib/generators/jasmine/install/USAGE +11 -0
- data/lib/generators/jasmine/install/install_generator.rb +18 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
- data/lib/generators/jasmine/jasmine_generator.rb +32 -0
- data/lib/generators/jasmine/templates/INSTALL +9 -0
- data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/lib/jasmine/base.rb +66 -0
- data/lib/jasmine/command_line_tool.rb +72 -0
- data/lib/jasmine/config.rb +190 -0
- data/lib/jasmine/railtie.rb +20 -0
- data/lib/jasmine/run.html.erb +44 -0
- data/lib/jasmine/selenium_driver.rb +49 -0
- data/lib/jasmine/server.rb +106 -0
- data/lib/jasmine/spec_builder.rb +162 -0
- data/lib/jasmine/tasks/jasmine.rake +44 -0
- data/lib/jasmine/version.rb +3 -0
- data/lib/jasmine.rb +14 -0
- data/spec/config_spec.rb +308 -0
- data/spec/fixture/jasmine.erb.yml +4 -0
- data/spec/jasmine_command_line_tool_spec.rb +29 -0
- data/spec/jasmine_pojs_spec.rb +51 -0
- data/spec/jasmine_rails2_spec.rb +93 -0
- data/spec/jasmine_rails3_spec.rb +71 -0
- data/spec/jasmine_self_test_config.rb +15 -0
- data/spec/jasmine_self_test_spec.rb +24 -0
- data/spec/server_spec.rb +80 -0
- data/spec/spec_helper.rb +65 -0
- metadata +386 -0
data/jasmine/src/base.js
ADDED
@@ -0,0 +1,608 @@
|
|
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;
|