evergreen 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/README.rdoc +4 -0
  2. data/bin/evergreen +18 -0
  3. data/lib/evergreen.rb +44 -0
  4. data/lib/evergreen/cli.rb +23 -0
  5. data/lib/evergreen/evergreen.js +3 -0
  6. data/lib/evergreen/runner.rb +56 -0
  7. data/lib/evergreen/server.rb +31 -0
  8. data/lib/evergreen/spec.rb +60 -0
  9. data/lib/evergreen/version.rb +3 -0
  10. data/lib/evergreen/views/list.erb +6 -0
  11. data/lib/evergreen/views/spec.erb +37 -0
  12. data/lib/jasmine/MIT.LICENSE +20 -0
  13. data/lib/jasmine/README.markdown +489 -0
  14. data/lib/jasmine/Rakefile +146 -0
  15. data/lib/jasmine/cruise_config.rb +21 -0
  16. data/lib/jasmine/doc/files.html +460 -0
  17. data/lib/jasmine/doc/index.html +322 -0
  18. data/lib/jasmine/doc/symbols/_global_.html +918 -0
  19. data/lib/jasmine/doc/symbols/jasmine.Block.html +417 -0
  20. data/lib/jasmine/doc/symbols/jasmine.Clock.html +678 -0
  21. data/lib/jasmine/doc/symbols/jasmine.Env.html +1169 -0
  22. data/lib/jasmine/doc/symbols/jasmine.JsApiReporter.html +822 -0
  23. data/lib/jasmine/doc/symbols/jasmine.Matchers.html +1474 -0
  24. data/lib/jasmine/doc/symbols/jasmine.MultiReporter.html +394 -0
  25. data/lib/jasmine/doc/symbols/jasmine.NestedResults.html +710 -0
  26. data/lib/jasmine/doc/symbols/jasmine.Reporter.html +574 -0
  27. data/lib/jasmine/doc/symbols/jasmine.Runner.html +710 -0
  28. data/lib/jasmine/doc/symbols/jasmine.Spec.html +1253 -0
  29. data/lib/jasmine/doc/symbols/jasmine.Spy.html +855 -0
  30. data/lib/jasmine/doc/symbols/jasmine.Suite.html +705 -0
  31. data/lib/jasmine/doc/symbols/jasmine.html +1345 -0
  32. data/lib/jasmine/doc/symbols/jasmine.util.html +535 -0
  33. data/lib/jasmine/doc/symbols/src/lib_TrivialReporter.js.html +124 -0
  34. data/lib/jasmine/doc/symbols/src/src_Block.js.html +29 -0
  35. data/lib/jasmine/doc/symbols/src/src_Env.js.html +248 -0
  36. data/lib/jasmine/doc/symbols/src/src_JsApiReporter.js.html +111 -0
  37. data/lib/jasmine/doc/symbols/src/src_Matchers.js.html +344 -0
  38. data/lib/jasmine/doc/symbols/src/src_MultiReporter.js.html +36 -0
  39. data/lib/jasmine/doc/symbols/src/src_NestedResults.js.html +88 -0
  40. data/lib/jasmine/doc/symbols/src/src_PrettyPrinter.js.html +130 -0
  41. data/lib/jasmine/doc/symbols/src/src_Queue.js.html +102 -0
  42. data/lib/jasmine/doc/symbols/src/src_Reporter.js.html +35 -0
  43. data/lib/jasmine/doc/symbols/src/src_Reporters.js.html +51 -0
  44. data/lib/jasmine/doc/symbols/src/src_Runner.js.html +75 -0
  45. data/lib/jasmine/doc/symbols/src/src_Spec.js.html +214 -0
  46. data/lib/jasmine/doc/symbols/src/src_Suite.js.html +77 -0
  47. data/lib/jasmine/doc/symbols/src/src_WaitsBlock.js.html +21 -0
  48. data/lib/jasmine/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
  49. data/lib/jasmine/doc/symbols/src/src_base.js.html +585 -0
  50. data/lib/jasmine/doc/symbols/src/src_mock-timeout.js.html +185 -0
  51. data/lib/jasmine/doc/symbols/src/src_util.js.html +75 -0
  52. data/lib/jasmine/example/example_runner.html +22 -0
  53. data/lib/jasmine/example/spec/example_suite.js +11 -0
  54. data/lib/jasmine/images/fail-16.png +0 -0
  55. data/lib/jasmine/images/fail.png +0 -0
  56. data/lib/jasmine/images/go-16.png +0 -0
  57. data/lib/jasmine/images/go.png +0 -0
  58. data/lib/jasmine/images/pending-16.png +0 -0
  59. data/lib/jasmine/images/pending.png +0 -0
  60. data/lib/jasmine/images/question-bk.png +0 -0
  61. data/lib/jasmine/images/questionbk-16.png +0 -0
  62. data/lib/jasmine/images/spinner.gif +0 -0
  63. data/lib/jasmine/lib/TrivialReporter.js +171 -0
  64. data/lib/jasmine/lib/consolex.js +28 -0
  65. data/lib/jasmine/lib/jasmine-0.10.4.js +2371 -0
  66. data/lib/jasmine/lib/jasmine.css +166 -0
  67. data/lib/jasmine/lib/json2.js +478 -0
  68. data/lib/jasmine/spec/jasmine_helper.rb +44 -0
  69. data/lib/jasmine/spec/jasmine_spec.rb +31 -0
  70. data/lib/jasmine/spec/runner.html +80 -0
  71. data/lib/jasmine/spec/saucelabs.yml +24 -0
  72. data/lib/jasmine/spec/suites/CustomMatchersSpec.js +112 -0
  73. data/lib/jasmine/spec/suites/EnvSpec.js +158 -0
  74. data/lib/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  75. data/lib/jasmine/spec/suites/JsApiReporterSpec.js +96 -0
  76. data/lib/jasmine/spec/suites/MatchersSpec.js +709 -0
  77. data/lib/jasmine/spec/suites/MockClockSpec.js +34 -0
  78. data/lib/jasmine/spec/suites/MultiReporterSpec.js +30 -0
  79. data/lib/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  80. data/lib/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  81. data/lib/jasmine/spec/suites/QueueSpec.js +23 -0
  82. data/lib/jasmine/spec/suites/ReporterSpec.js +60 -0
  83. data/lib/jasmine/spec/suites/RunnerSpec.js +267 -0
  84. data/lib/jasmine/spec/suites/SpecRunningSpec.js +1195 -0
  85. data/lib/jasmine/spec/suites/SpecSpec.js +110 -0
  86. data/lib/jasmine/spec/suites/SpySpec.js +201 -0
  87. data/lib/jasmine/spec/suites/SuiteSpec.js +120 -0
  88. data/lib/jasmine/spec/suites/TrivialReporterSpec.js +158 -0
  89. data/lib/jasmine/spec/suites/UtilSpec.js +40 -0
  90. data/lib/jasmine/spec/suites/WaitsForBlockSpec.js +88 -0
  91. data/lib/jasmine/src/Block.js +22 -0
  92. data/lib/jasmine/src/Env.js +263 -0
  93. data/lib/jasmine/src/JsApiReporter.js +104 -0
  94. data/lib/jasmine/src/Matchers.js +336 -0
  95. data/lib/jasmine/src/MultiReporter.js +28 -0
  96. data/lib/jasmine/src/NestedResults.js +80 -0
  97. data/lib/jasmine/src/PrettyPrinter.js +122 -0
  98. data/lib/jasmine/src/Queue.js +94 -0
  99. data/lib/jasmine/src/Reporter.js +27 -0
  100. data/lib/jasmine/src/Reporters.js +43 -0
  101. data/lib/jasmine/src/Runner.js +77 -0
  102. data/lib/jasmine/src/Spec.js +206 -0
  103. data/lib/jasmine/src/Suite.js +82 -0
  104. data/lib/jasmine/src/WaitsBlock.js +13 -0
  105. data/lib/jasmine/src/WaitsForBlock.js +37 -0
  106. data/lib/jasmine/src/base.js +586 -0
  107. data/lib/jasmine/src/mock-timeout.js +177 -0
  108. data/lib/jasmine/src/util.js +67 -0
  109. data/lib/jasmine/src/version.json +5 -0
  110. metadata +238 -0
@@ -0,0 +1,82 @@
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
+ };
@@ -0,0 +1,13 @@
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
+ this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
10
+ this.env.setTimeout(function () {
11
+ onComplete();
12
+ }, this.timeout);
13
+ };
@@ -0,0 +1,37 @@
1
+ jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
2
+ this.timeout = timeout;
3
+ this.latchFunction = latchFunction;
4
+ this.message = message;
5
+ this.totalTimeSpentWaitingForLatch = 0;
6
+ jasmine.Block.call(this, env, null, spec);
7
+ };
8
+
9
+ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
10
+
11
+ jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
12
+
13
+ jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
14
+ var self = this;
15
+ self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
16
+ var latchFunctionResult;
17
+ try {
18
+ latchFunctionResult = self.latchFunction.apply(self.spec);
19
+ } catch (e) {
20
+ self.spec.fail(e);
21
+ onComplete();
22
+ return;
23
+ }
24
+
25
+ if (latchFunctionResult) {
26
+ onComplete();
27
+ } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
28
+ var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
29
+ self.spec.fail({
30
+ name: 'timeout',
31
+ message: message
32
+ });
33
+ } else {
34
+ self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
35
+ self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
36
+ }
37
+ };
@@ -0,0 +1,586 @@
1
+ /**
2
+ * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
3
+ *
4
+ * @namespace
5
+ */
6
+ var jasmine = {};
7
+
8
+ /**
9
+ * @private
10
+ */
11
+ jasmine.unimplementedMethod_ = function() {
12
+ throw new Error("unimplemented method");
13
+ };
14
+
15
+ /**
16
+ * Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just
17
+ * a plain old variable and may be redefined by somebody else.
18
+ *
19
+ * @private
20
+ */
21
+ jasmine.undefined = jasmine.___undefined___;
22
+
23
+ /**
24
+ * Default interval for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed.
25
+ *
26
+ */
27
+ jasmine.DEFAULT_UPDATE_INTERVAL = 250;
28
+
29
+ /**
30
+ * Allows for bound functions to be compared. Internal use only.
31
+ *
32
+ * @ignore
33
+ * @private
34
+ * @param base {Object} bound 'this' for the function
35
+ * @param name {Function} function to find
36
+ */
37
+ jasmine.bindOriginal_ = function(base, name) {
38
+ var original = base[name];
39
+ if (original.apply) {
40
+ return function() {
41
+ return original.apply(base, arguments);
42
+ };
43
+ } else {
44
+ // IE support
45
+ return window[name];
46
+ }
47
+ };
48
+
49
+ jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout');
50
+ jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout');
51
+ jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval');
52
+ jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval');
53
+
54
+ jasmine.MessageResult = function(text) {
55
+ this.type = 'MessageResult';
56
+ this.text = text;
57
+ this.trace = new Error(); // todo: test better
58
+ };
59
+
60
+ jasmine.MessageResult.prototype.toString = function() {
61
+ return this.text;
62
+ };
63
+
64
+ jasmine.ExpectationResult = function(params) {
65
+ this.type = 'ExpectationResult';
66
+ this.matcherName = params.matcherName;
67
+ this.passed_ = params.passed;
68
+ this.expected = params.expected;
69
+ this.actual = params.actual;
70
+
71
+ /** @deprecated */
72
+ this.details = params.details;
73
+
74
+ this.message = this.passed_ ? 'Passed.' : params.message;
75
+ this.trace = this.passed_ ? '' : new Error(this.message);
76
+ };
77
+
78
+ jasmine.ExpectationResult.prototype.toString = function () {
79
+ return this.message;
80
+ };
81
+
82
+ jasmine.ExpectationResult.prototype.passed = function () {
83
+ return this.passed_;
84
+ };
85
+
86
+ /**
87
+ * Getter for the Jasmine environment. Ensures one gets created
88
+ */
89
+ jasmine.getEnv = function() {
90
+ return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
91
+ };
92
+
93
+ /**
94
+ * @ignore
95
+ * @private
96
+ * @param value
97
+ * @returns {Boolean}
98
+ */
99
+ jasmine.isArray_ = function(value) {
100
+ return jasmine.isA_("Array", value);
101
+ };
102
+
103
+ /**
104
+ * @ignore
105
+ * @private
106
+ * @param value
107
+ * @returns {Boolean}
108
+ */
109
+ jasmine.isString_ = function(value) {
110
+ return jasmine.isA_("String", value);
111
+ };
112
+
113
+ /**
114
+ * @ignore
115
+ * @private
116
+ * @param value
117
+ * @returns {Boolean}
118
+ */
119
+ jasmine.isNumber_ = function(value) {
120
+ return jasmine.isA_("Number", value);
121
+ };
122
+
123
+ /**
124
+ * @ignore
125
+ * @private
126
+ * @param {String} typeName
127
+ * @param value
128
+ * @returns {Boolean}
129
+ */
130
+ jasmine.isA_ = function(typeName, value) {
131
+ return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
132
+ };
133
+
134
+ /**
135
+ * Pretty printer for expecations. Takes any object and turns it into a human-readable string.
136
+ *
137
+ * @param value {Object} an object to be outputted
138
+ * @returns {String}
139
+ */
140
+ jasmine.pp = function(value) {
141
+ var stringPrettyPrinter = new jasmine.StringPrettyPrinter();
142
+ stringPrettyPrinter.format(value);
143
+ return stringPrettyPrinter.string;
144
+ };
145
+
146
+ /**
147
+ * Returns true if the object is a DOM Node.
148
+ *
149
+ * @param {Object} obj object to check
150
+ * @returns {Boolean}
151
+ */
152
+ jasmine.isDomNode = function(obj) {
153
+ return obj['nodeType'] > 0;
154
+ };
155
+
156
+ /**
157
+ * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter.
158
+ *
159
+ * @example
160
+ * // don't care about which function is passed in, as long as it's a function
161
+ * expect(mySpy).wasCalledWith(jasmine.any(Function));
162
+ *
163
+ * @param {Class} clazz
164
+ * @returns matchable object of the type clazz
165
+ */
166
+ jasmine.any = function(clazz) {
167
+ return new jasmine.Matchers.Any(clazz);
168
+ };
169
+
170
+ /**
171
+ * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
172
+ *
173
+ * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine
174
+ * expectation syntax. Spies can be checked if they were called or not and what the calling params were.
175
+ *
176
+ * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs)
177
+ * Spies are torn down at the end of every spec.
178
+ *
179
+ * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj.
180
+ *
181
+ * @example
182
+ * // a stub
183
+ * var myStub = jasmine.createSpy('myStub'); // can be used anywhere
184
+ *
185
+ * // spy example
186
+ * var foo = {
187
+ * not: function(bool) { return !bool; }
188
+ * }
189
+ *
190
+ * // actual foo.not will not be called, execution stops
191
+ * spyOn(foo, 'not');
192
+
193
+ // foo.not spied upon, execution will continue to implementation
194
+ * spyOn(foo, 'not').andCallThrough();
195
+ *
196
+ * // fake example
197
+ * var foo = {
198
+ * not: function(bool) { return !bool; }
199
+ * }
200
+ *
201
+ * // foo.not(val) will return val
202
+ * spyOn(foo, 'not').andCallFake(function(value) {return value;});
203
+ *
204
+ * // mock example
205
+ * foo.not(7 == 7);
206
+ * expect(foo.not).wasCalled();
207
+ * expect(foo.not).wasCalledWith(true);
208
+ *
209
+ * @constructor
210
+ * @see spyOn, jasmine.createSpy, jasmine.createSpyObj
211
+ * @param {String} name
212
+ */
213
+ jasmine.Spy = function(name) {
214
+ /**
215
+ * The name of the spy, if provided.
216
+ */
217
+ this.identity = name || 'unknown';
218
+ /**
219
+ * Is this Object a spy?
220
+ */
221
+ this.isSpy = true;
222
+ /**
223
+ * The actual function this spy stubs.
224
+ */
225
+ this.plan = function() {
226
+ };
227
+ /**
228
+ * Tracking of the most recent call to the spy.
229
+ * @example
230
+ * var mySpy = jasmine.createSpy('foo');
231
+ * mySpy(1, 2);
232
+ * mySpy.mostRecentCall.args = [1, 2];
233
+ */
234
+ this.mostRecentCall = {};
235
+
236
+ /**
237
+ * Holds arguments for each call to the spy, indexed by call count
238
+ * @example
239
+ * var mySpy = jasmine.createSpy('foo');
240
+ * mySpy(1, 2);
241
+ * mySpy(7, 8);
242
+ * mySpy.mostRecentCall.args = [7, 8];
243
+ * mySpy.argsForCall[0] = [1, 2];
244
+ * mySpy.argsForCall[1] = [7, 8];
245
+ */
246
+ this.argsForCall = [];
247
+ this.calls = [];
248
+ };
249
+
250
+ /**
251
+ * Tells a spy to call through to the actual implemenatation.
252
+ *
253
+ * @example
254
+ * var foo = {
255
+ * bar: function() { // do some stuff }
256
+ * }
257
+ *
258
+ * // defining a spy on an existing property: foo.bar
259
+ * spyOn(foo, 'bar').andCallThrough();
260
+ */
261
+ jasmine.Spy.prototype.andCallThrough = function() {
262
+ this.plan = this.originalValue;
263
+ return this;
264
+ };
265
+
266
+ /**
267
+ * For setting the return value of a spy.
268
+ *
269
+ * @example
270
+ * // defining a spy from scratch: foo() returns 'baz'
271
+ * var foo = jasmine.createSpy('spy on foo').andReturn('baz');
272
+ *
273
+ * // defining a spy on an existing property: foo.bar() returns 'baz'
274
+ * spyOn(foo, 'bar').andReturn('baz');
275
+ *
276
+ * @param {Object} value
277
+ */
278
+ jasmine.Spy.prototype.andReturn = function(value) {
279
+ this.plan = function() {
280
+ return value;
281
+ };
282
+ return this;
283
+ };
284
+
285
+ /**
286
+ * For throwing an exception when a spy is called.
287
+ *
288
+ * @example
289
+ * // defining a spy from scratch: foo() throws an exception w/ message 'ouch'
290
+ * var foo = jasmine.createSpy('spy on foo').andThrow('baz');
291
+ *
292
+ * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch'
293
+ * spyOn(foo, 'bar').andThrow('baz');
294
+ *
295
+ * @param {String} exceptionMsg
296
+ */
297
+ jasmine.Spy.prototype.andThrow = function(exceptionMsg) {
298
+ this.plan = function() {
299
+ throw exceptionMsg;
300
+ };
301
+ return this;
302
+ };
303
+
304
+ /**
305
+ * Calls an alternate implementation when a spy is called.
306
+ *
307
+ * @example
308
+ * var baz = function() {
309
+ * // do some stuff, return something
310
+ * }
311
+ * // defining a spy from scratch: foo() calls the function baz
312
+ * var foo = jasmine.createSpy('spy on foo').andCall(baz);
313
+ *
314
+ * // defining a spy on an existing property: foo.bar() calls an anonymnous function
315
+ * spyOn(foo, 'bar').andCall(function() { return 'baz';} );
316
+ *
317
+ * @param {Function} fakeFunc
318
+ */
319
+ jasmine.Spy.prototype.andCallFake = function(fakeFunc) {
320
+ this.plan = fakeFunc;
321
+ return this;
322
+ };
323
+
324
+ /**
325
+ * Resets all of a spy's the tracking variables so that it can be used again.
326
+ *
327
+ * @example
328
+ * spyOn(foo, 'bar');
329
+ *
330
+ * foo.bar();
331
+ *
332
+ * expect(foo.bar.callCount).toEqual(1);
333
+ *
334
+ * foo.bar.reset();
335
+ *
336
+ * expect(foo.bar.callCount).toEqual(0);
337
+ */
338
+ jasmine.Spy.prototype.reset = function() {
339
+ this.wasCalled = false;
340
+ this.callCount = 0;
341
+ this.argsForCall = [];
342
+ this.calls = [];
343
+ this.mostRecentCall = {};
344
+ };
345
+
346
+ jasmine.createSpy = function(name) {
347
+
348
+ var spyObj = function() {
349
+ spyObj.wasCalled = true;
350
+ spyObj.callCount++;
351
+ var args = jasmine.util.argsToArray(arguments);
352
+ spyObj.mostRecentCall.object = this;
353
+ spyObj.mostRecentCall.args = args;
354
+ spyObj.argsForCall.push(args);
355
+ spyObj.calls.push({object: this, args: args});
356
+ return spyObj.plan.apply(this, arguments);
357
+ };
358
+
359
+ var spy = new jasmine.Spy(name);
360
+
361
+ for (var prop in spy) {
362
+ spyObj[prop] = spy[prop];
363
+ }
364
+
365
+ spyObj.reset();
366
+
367
+ return spyObj;
368
+ };
369
+
370
+ /**
371
+ * Determines whether an object is a spy.
372
+ *
373
+ * @param {jasmine.Spy|Object} putativeSpy
374
+ * @returns {Boolean}
375
+ */
376
+ jasmine.isSpy = function(putativeSpy) {
377
+ return putativeSpy && putativeSpy.isSpy;
378
+ };
379
+
380
+ /**
381
+ * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something
382
+ * large in one call.
383
+ *
384
+ * @param {String} baseName name of spy class
385
+ * @param {Array} methodNames array of names of methods to make spies
386
+ */
387
+ jasmine.createSpyObj = function(baseName, methodNames) {
388
+ if (!jasmine.isArray_(methodNames) || methodNames.length == 0) {
389
+ throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
390
+ }
391
+ var obj = {};
392
+ for (var i = 0; i < methodNames.length; i++) {
393
+ obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]);
394
+ }
395
+ return obj;
396
+ };
397
+
398
+ jasmine.log = function(message) {
399
+ jasmine.getEnv().currentSpec.log(message);
400
+ };
401
+
402
+ /**
403
+ * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
404
+ *
405
+ * @example
406
+ * // spy example
407
+ * var foo = {
408
+ * not: function(bool) { return !bool; }
409
+ * }
410
+ * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
411
+ *
412
+ * @see jasmine.createSpy
413
+ * @param obj
414
+ * @param methodName
415
+ * @returns a Jasmine spy that can be chained with all spy methods
416
+ */
417
+ var spyOn = function(obj, methodName) {
418
+ return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
419
+ };
420
+
421
+ /**
422
+ * Creates a Jasmine spec that will be added to the current suite.
423
+ *
424
+ * // TODO: pending tests
425
+ *
426
+ * @example
427
+ * it('should be true', function() {
428
+ * expect(true).toEqual(true);
429
+ * });
430
+ *
431
+ * @param {String} desc description of this specification
432
+ * @param {Function} func defines the preconditions and expectations of the spec
433
+ */
434
+ var it = function(desc, func) {
435
+ return jasmine.getEnv().it(desc, func);
436
+ };
437
+
438
+ /**
439
+ * Creates a <em>disabled</em> Jasmine spec.
440
+ *
441
+ * A convenience method that allows existing specs to be disabled temporarily during development.
442
+ *
443
+ * @param {String} desc description of this specification
444
+ * @param {Function} func defines the preconditions and expectations of the spec
445
+ */
446
+ var xit = function(desc, func) {
447
+ return jasmine.getEnv().xit(desc, func);
448
+ };
449
+
450
+ /**
451
+ * Starts a chain for a Jasmine expectation.
452
+ *
453
+ * It is passed an Object that is the actual value and should chain to one of the many
454
+ * jasmine.Matchers functions.
455
+ *
456
+ * @param {Object} actual Actual value to test against and expected value
457
+ */
458
+ var expect = function(actual) {
459
+ return jasmine.getEnv().currentSpec.expect(actual);
460
+ };
461
+
462
+ /**
463
+ * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
464
+ *
465
+ * @param {Function} func Function that defines part of a jasmine spec.
466
+ */
467
+ var runs = function(func) {
468
+ jasmine.getEnv().currentSpec.runs(func);
469
+ };
470
+
471
+ /**
472
+ * Waits for a timeout before moving to the next runs()-defined block.
473
+ * @param {Number} timeout
474
+ */
475
+ var waits = function(timeout) {
476
+ jasmine.getEnv().currentSpec.waits(timeout);
477
+ };
478
+
479
+ /**
480
+ * Waits for the latchFunction to return true before proceeding to the next runs()-defined block.
481
+ *
482
+ * @param {Number} timeout
483
+ * @param {Function} latchFunction
484
+ * @param {String} message
485
+ */
486
+ var waitsFor = function(timeout, latchFunction, message) {
487
+ jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message);
488
+ };
489
+
490
+ /**
491
+ * A function that is called before each spec in a suite.
492
+ *
493
+ * Used for spec setup, including validating assumptions.
494
+ *
495
+ * @param {Function} beforeEachFunction
496
+ */
497
+ var beforeEach = function(beforeEachFunction) {
498
+ jasmine.getEnv().beforeEach(beforeEachFunction);
499
+ };
500
+
501
+ /**
502
+ * A function that is called after each spec in a suite.
503
+ *
504
+ * Used for restoring any state that is hijacked during spec execution.
505
+ *
506
+ * @param {Function} afterEachFunction
507
+ */
508
+ var afterEach = function(afterEachFunction) {
509
+ jasmine.getEnv().afterEach(afterEachFunction);
510
+ };
511
+
512
+ /**
513
+ * Defines a suite of specifications.
514
+ *
515
+ * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
516
+ * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
517
+ * of setup in some tests.
518
+ *
519
+ * @example
520
+ * // TODO: a simple suite
521
+ *
522
+ * // TODO: a simple suite with a nested describe block
523
+ *
524
+ * @param {String} description A string, usually the class under test.
525
+ * @param {Function} specDefinitions function that defines several specs.
526
+ */
527
+ var describe = function(description, specDefinitions) {
528
+ return jasmine.getEnv().describe(description, specDefinitions);
529
+ };
530
+
531
+ /**
532
+ * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
533
+ *
534
+ * @param {String} description A string, usually the class under test.
535
+ * @param {Function} specDefinitions function that defines several specs.
536
+ */
537
+ var xdescribe = function(description, specDefinitions) {
538
+ return jasmine.getEnv().xdescribe(description, specDefinitions);
539
+ };
540
+
541
+
542
+ // Provide the XMLHttpRequest class for IE 5.x-6.x:
543
+ jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
544
+ try {
545
+ return new ActiveXObject("Msxml2.XMLHTTP.6.0");
546
+ } catch(e) {
547
+ }
548
+ try {
549
+ return new ActiveXObject("Msxml2.XMLHTTP.3.0");
550
+ } catch(e) {
551
+ }
552
+ try {
553
+ return new ActiveXObject("Msxml2.XMLHTTP");
554
+ } catch(e) {
555
+ }
556
+ try {
557
+ return new ActiveXObject("Microsoft.XMLHTTP");
558
+ } catch(e) {
559
+ }
560
+ throw new Error("This browser does not support XMLHttpRequest.");
561
+ } : XMLHttpRequest;
562
+
563
+ /**
564
+ * Adds suite files to an HTML document so that they are executed, thus adding them to the current
565
+ * Jasmine environment.
566
+ *
567
+ * @param {String} url path to the file to include
568
+ * @param {Boolean} opt_global
569
+ * @deprecated We suggest you use a different method of including JS source files. <code>jasmine.include</code> will be removed soon.
570
+ */
571
+ jasmine.include = function(url, opt_global) {
572
+ if (opt_global) {
573
+ document.write('<script type="text/javascript" src="' + url + '"></' + 'script>');
574
+ } else {
575
+ var xhr;
576
+ try {
577
+ xhr = new jasmine.XmlHttpRequest();
578
+ xhr.open("GET", url, false);
579
+ xhr.send(null);
580
+ } catch(e) {
581
+ throw new Error("couldn't fetch " + url + ": " + e);
582
+ }
583
+
584
+ return eval(xhr.responseText);
585
+ }
586
+ };