jazz 0.1.1

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