jasnode 0.2.0.0

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