josephholsten-jasmine 1.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.gitignore +11 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +5 -0
  4. data/HOW_TO_TEST.markdown +9 -0
  5. data/MIT.LICENSE +20 -0
  6. data/README.markdown +71 -0
  7. data/RELEASE.markdown +22 -0
  8. data/Rakefile +76 -0
  9. data/bin/jasmine +6 -0
  10. data/generators/jasmine/jasmine_generator.rb +32 -0
  11. data/generators/jasmine/templates/INSTALL +9 -0
  12. data/generators/jasmine/templates/jasmine-example/SpecRunner.html +27 -0
  13. data/generators/jasmine/templates/jasmine-example/spec/PlayerSpec.js +58 -0
  14. data/generators/jasmine/templates/jasmine-example/spec/SpecHelper.js +9 -0
  15. data/generators/jasmine/templates/jasmine-example/src/Player.js +22 -0
  16. data/generators/jasmine/templates/jasmine-example/src/Song.js +7 -0
  17. data/generators/jasmine/templates/lib/tasks/jasmine.rake +8 -0
  18. data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  19. data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  20. data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  21. data/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  22. data/jasmine/Gemfile +6 -0
  23. data/jasmine/Gemfile.lock +33 -0
  24. data/jasmine/HowToRelease.markdown +29 -0
  25. data/jasmine/MIT.LICENSE +20 -0
  26. data/jasmine/README.markdown +50 -0
  27. data/jasmine/Rakefile +166 -0
  28. data/jasmine/cruise_config.rb +21 -0
  29. data/jasmine/example/SpecRunner.html +27 -0
  30. data/jasmine/example/spec/PlayerSpec.js +58 -0
  31. data/jasmine/example/spec/SpecHelper.js +9 -0
  32. data/jasmine/example/src/Player.js +22 -0
  33. data/jasmine/example/src/Song.js +7 -0
  34. data/jasmine/images/jasmine_favicon.png +0 -0
  35. data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
  36. data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
  37. data/jasmine/jsdoc-template/class.tmpl +646 -0
  38. data/jasmine/jsdoc-template/index.tmpl +39 -0
  39. data/jasmine/jsdoc-template/publish.js +184 -0
  40. data/jasmine/jsdoc-template/static/default.css +162 -0
  41. data/jasmine/jsdoc-template/static/header.html +2 -0
  42. data/jasmine/jsdoc-template/static/index.html +19 -0
  43. data/jasmine/jsdoc-template/symbol.tmpl +35 -0
  44. data/jasmine/jshint/jshint.js +5919 -0
  45. data/jasmine/jshint/run.js +98 -0
  46. data/jasmine/lib/jasmine-html.js +190 -0
  47. data/jasmine/lib/jasmine.css +166 -0
  48. data/jasmine/lib/jasmine.js +2445 -0
  49. data/jasmine/lib/json2.js +478 -0
  50. data/jasmine/spec/node_suite.js +233 -0
  51. data/jasmine/spec/runner.html +82 -0
  52. data/jasmine/spec/suites/BaseSpec.js +27 -0
  53. data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
  54. data/jasmine/spec/suites/EnvSpec.js +158 -0
  55. data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  56. data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
  57. data/jasmine/spec/suites/MatchersSpec.js +795 -0
  58. data/jasmine/spec/suites/MockClockSpec.js +38 -0
  59. data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
  60. data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  61. data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  62. data/jasmine/spec/suites/QueueSpec.js +23 -0
  63. data/jasmine/spec/suites/ReporterSpec.js +56 -0
  64. data/jasmine/spec/suites/RunnerSpec.js +267 -0
  65. data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
  66. data/jasmine/spec/suites/SpecSpec.js +124 -0
  67. data/jasmine/spec/suites/SpySpec.js +201 -0
  68. data/jasmine/spec/suites/SuiteSpec.js +120 -0
  69. data/jasmine/spec/suites/TrivialConsoleReporterSpec.js +431 -0
  70. data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
  71. data/jasmine/spec/suites/UtilSpec.js +39 -0
  72. data/jasmine/spec/suites/WaitsForBlockSpec.js +118 -0
  73. data/jasmine/src/Block.js +22 -0
  74. data/jasmine/src/Env.js +264 -0
  75. data/jasmine/src/JsApiReporter.js +102 -0
  76. data/jasmine/src/Matchers.js +354 -0
  77. data/jasmine/src/MultiReporter.js +35 -0
  78. data/jasmine/src/NestedResults.js +80 -0
  79. data/jasmine/src/PrettyPrinter.js +123 -0
  80. data/jasmine/src/Queue.js +99 -0
  81. data/jasmine/src/Reporter.js +31 -0
  82. data/jasmine/src/Runner.js +77 -0
  83. data/jasmine/src/Spec.js +242 -0
  84. data/jasmine/src/Suite.js +82 -0
  85. data/jasmine/src/WaitsBlock.js +15 -0
  86. data/jasmine/src/WaitsForBlock.js +54 -0
  87. data/jasmine/src/base.js +608 -0
  88. data/jasmine/src/console/TrivialConsoleReporter.js +144 -0
  89. data/jasmine/src/html/TrivialReporter.js +190 -0
  90. data/jasmine/src/html/jasmine.css +166 -0
  91. data/jasmine/src/mock-timeout.js +183 -0
  92. data/jasmine/src/util.js +67 -0
  93. data/jasmine/src/version.json +5 -0
  94. data/jasmine.gemspec +52 -0
  95. data/lib/generators/jasmine/examples/USAGE +11 -0
  96. data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
  97. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
  98. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
  99. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
  100. data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
  101. data/lib/generators/jasmine/install/USAGE +11 -0
  102. data/lib/generators/jasmine/install/install_generator.rb +18 -0
  103. data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
  104. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
  105. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  106. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
  107. data/lib/generators/jasmine/jasmine_generator.rb +32 -0
  108. data/lib/generators/jasmine/templates/INSTALL +9 -0
  109. data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
  110. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  111. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  112. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  113. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  114. data/lib/jasmine/base.rb +66 -0
  115. data/lib/jasmine/command_line_tool.rb +72 -0
  116. data/lib/jasmine/config.rb +190 -0
  117. data/lib/jasmine/railtie.rb +20 -0
  118. data/lib/jasmine/run.html.erb +44 -0
  119. data/lib/jasmine/selenium_driver.rb +49 -0
  120. data/lib/jasmine/server.rb +106 -0
  121. data/lib/jasmine/spec_builder.rb +162 -0
  122. data/lib/jasmine/tasks/jasmine.rake +44 -0
  123. data/lib/jasmine/version.rb +3 -0
  124. data/lib/jasmine.rb +14 -0
  125. data/spec/config_spec.rb +308 -0
  126. data/spec/fixture/jasmine.erb.yml +4 -0
  127. data/spec/jasmine_command_line_tool_spec.rb +29 -0
  128. data/spec/jasmine_pojs_spec.rb +51 -0
  129. data/spec/jasmine_rails2_spec.rb +93 -0
  130. data/spec/jasmine_rails3_spec.rb +71 -0
  131. data/spec/jasmine_self_test_config.rb +15 -0
  132. data/spec/jasmine_self_test_spec.rb +24 -0
  133. data/spec/server_spec.rb +80 -0
  134. data/spec/spec_helper.rb +65 -0
  135. metadata +386 -0
@@ -0,0 +1,31 @@
1
+ /** No-op base class for Jasmine reporters.
2
+ *
3
+ * @constructor
4
+ */
5
+ jasmine.Reporter = function() {
6
+ };
7
+
8
+ //noinspection JSUnusedLocalSymbols
9
+ jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
10
+ };
11
+
12
+ //noinspection JSUnusedLocalSymbols
13
+ jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
14
+ };
15
+
16
+ //noinspection JSUnusedLocalSymbols
17
+ jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
18
+ };
19
+
20
+ //noinspection JSUnusedLocalSymbols
21
+ jasmine.Reporter.prototype.reportSpecStarting = function(spec) {
22
+ };
23
+
24
+ //noinspection JSUnusedLocalSymbols
25
+ jasmine.Reporter.prototype.reportSpecResults = function(spec) {
26
+ };
27
+
28
+ //noinspection JSUnusedLocalSymbols
29
+ jasmine.Reporter.prototype.log = function(str) {
30
+ };
31
+
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Runner
3
+ *
4
+ * @constructor
5
+ * @param {jasmine.Env} env
6
+ */
7
+ jasmine.Runner = function(env) {
8
+ var self = this;
9
+ self.env = env;
10
+ self.queue = new jasmine.Queue(env);
11
+ self.before_ = [];
12
+ self.after_ = [];
13
+ self.suites_ = [];
14
+ };
15
+
16
+ jasmine.Runner.prototype.execute = function() {
17
+ var self = this;
18
+ if (self.env.reporter.reportRunnerStarting) {
19
+ self.env.reporter.reportRunnerStarting(this);
20
+ }
21
+ self.queue.start(function () {
22
+ self.finishCallback();
23
+ });
24
+ };
25
+
26
+ jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
27
+ beforeEachFunction.typeName = 'beforeEach';
28
+ this.before_.splice(0,0,beforeEachFunction);
29
+ };
30
+
31
+ jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
32
+ afterEachFunction.typeName = 'afterEach';
33
+ this.after_.splice(0,0,afterEachFunction);
34
+ };
35
+
36
+
37
+ jasmine.Runner.prototype.finishCallback = function() {
38
+ this.env.reporter.reportRunnerResults(this);
39
+ };
40
+
41
+ jasmine.Runner.prototype.addSuite = function(suite) {
42
+ this.suites_.push(suite);
43
+ };
44
+
45
+ jasmine.Runner.prototype.add = function(block) {
46
+ if (block instanceof jasmine.Suite) {
47
+ this.addSuite(block);
48
+ }
49
+ this.queue.add(block);
50
+ };
51
+
52
+ jasmine.Runner.prototype.specs = function () {
53
+ var suites = this.suites();
54
+ var specs = [];
55
+ for (var i = 0; i < suites.length; i++) {
56
+ specs = specs.concat(suites[i].specs());
57
+ }
58
+ return specs;
59
+ };
60
+
61
+ jasmine.Runner.prototype.suites = function() {
62
+ return this.suites_;
63
+ };
64
+
65
+ jasmine.Runner.prototype.topLevelSuites = function() {
66
+ var topLevelSuites = [];
67
+ for (var i = 0; i < this.suites_.length; i++) {
68
+ if (!this.suites_[i].parentSuite) {
69
+ topLevelSuites.push(this.suites_[i]);
70
+ }
71
+ }
72
+ return topLevelSuites;
73
+ };
74
+
75
+ jasmine.Runner.prototype.results = function() {
76
+ return this.queue.results();
77
+ };
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Internal representation of a Jasmine specification, or test.
3
+ *
4
+ * @constructor
5
+ * @param {jasmine.Env} env
6
+ * @param {jasmine.Suite} suite
7
+ * @param {String} description
8
+ */
9
+ jasmine.Spec = function(env, suite, description) {
10
+ if (!env) {
11
+ throw new Error('jasmine.Env() required');
12
+ }
13
+ if (!suite) {
14
+ throw new Error('jasmine.Suite() required');
15
+ }
16
+ var spec = this;
17
+ spec.id = env.nextSpecId ? env.nextSpecId() : null;
18
+ spec.env = env;
19
+ spec.suite = suite;
20
+ spec.description = description;
21
+ spec.queue = new jasmine.Queue(env);
22
+
23
+ spec.afterCallbacks = [];
24
+ spec.spies_ = [];
25
+
26
+ spec.results_ = new jasmine.NestedResults();
27
+ spec.results_.description = description;
28
+ spec.matchersClass = null;
29
+ };
30
+
31
+ jasmine.Spec.prototype.getFullName = function() {
32
+ return this.suite.getFullName() + ' ' + this.description + '.';
33
+ };
34
+
35
+
36
+ jasmine.Spec.prototype.results = function() {
37
+ return this.results_;
38
+ };
39
+
40
+ /**
41
+ * All parameters are pretty-printed and concatenated together, then written to the spec's output.
42
+ *
43
+ * Be careful not to leave calls to <code>jasmine.log</code> in production code.
44
+ */
45
+ jasmine.Spec.prototype.log = function() {
46
+ return this.results_.log(arguments);
47
+ };
48
+
49
+ jasmine.Spec.prototype.runs = function (func) {
50
+ var block = new jasmine.Block(this.env, func, this);
51
+ this.addToQueue(block);
52
+ return this;
53
+ };
54
+
55
+ jasmine.Spec.prototype.addToQueue = function (block) {
56
+ if (this.queue.isRunning()) {
57
+ this.queue.insertNext(block);
58
+ } else {
59
+ this.queue.add(block);
60
+ }
61
+ };
62
+
63
+ /**
64
+ * @param {jasmine.ExpectationResult} result
65
+ */
66
+ jasmine.Spec.prototype.addMatcherResult = function(result) {
67
+ this.results_.addResult(result);
68
+ };
69
+
70
+ jasmine.Spec.prototype.expect = function(actual) {
71
+ var positive = new (this.getMatchersClass_())(this.env, actual, this);
72
+ positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
73
+ return positive;
74
+ };
75
+
76
+ /**
77
+ * Waits a fixed time period before moving to the next block.
78
+ *
79
+ * @deprecated Use waitsFor() instead
80
+ * @param {Number} timeout milliseconds to wait
81
+ */
82
+ jasmine.Spec.prototype.waits = function(timeout) {
83
+ var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
84
+ this.addToQueue(waitsFunc);
85
+ return this;
86
+ };
87
+
88
+ /**
89
+ * Waits for the latchFunction to return true before proceeding to the next block.
90
+ *
91
+ * @param {Function} latchFunction
92
+ * @param {String} optional_timeoutMessage
93
+ * @param {Number} optional_timeout
94
+ */
95
+ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
96
+ var latchFunction_ = null;
97
+ var optional_timeoutMessage_ = null;
98
+ var optional_timeout_ = null;
99
+
100
+ for (var i = 0; i < arguments.length; i++) {
101
+ var arg = arguments[i];
102
+ switch (typeof arg) {
103
+ case 'function':
104
+ latchFunction_ = arg;
105
+ break;
106
+ case 'string':
107
+ optional_timeoutMessage_ = arg;
108
+ break;
109
+ case 'number':
110
+ optional_timeout_ = arg;
111
+ break;
112
+ }
113
+ }
114
+
115
+ var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
116
+ this.addToQueue(waitsForFunc);
117
+ return this;
118
+ };
119
+
120
+ jasmine.Spec.prototype.fail = function (e) {
121
+ var expectationResult = new jasmine.ExpectationResult({
122
+ passed: false,
123
+ message: e ? jasmine.util.formatException(e) : 'Exception'
124
+ });
125
+ this.results_.addResult(expectationResult);
126
+ };
127
+
128
+ jasmine.Spec.prototype.getMatchersClass_ = function() {
129
+ return this.matchersClass || this.env.matchersClass;
130
+ };
131
+
132
+ jasmine.Spec.prototype.addMatchers = function(matchersPrototype) {
133
+ var parent = this.getMatchersClass_();
134
+ var newMatchersClass = function() {
135
+ parent.apply(this, arguments);
136
+ };
137
+ jasmine.util.inherit(newMatchersClass, parent);
138
+ jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass);
139
+ this.matchersClass = newMatchersClass;
140
+ };
141
+
142
+ jasmine.Spec.prototype.finishCallback = function() {
143
+ this.env.reporter.reportSpecResults(this);
144
+ };
145
+
146
+ jasmine.Spec.prototype.finish = function(onComplete) {
147
+ this.removeAllSpies();
148
+ this.finishCallback();
149
+ if (onComplete) {
150
+ onComplete();
151
+ }
152
+ };
153
+
154
+ jasmine.Spec.prototype.after = function(doAfter) {
155
+ if (this.queue.isRunning()) {
156
+ this.queue.add(new jasmine.Block(this.env, doAfter, this));
157
+ } else {
158
+ this.afterCallbacks.unshift(doAfter);
159
+ }
160
+ };
161
+
162
+ jasmine.Spec.prototype.execute = function(onComplete) {
163
+ var spec = this;
164
+ if (!spec.env.specFilter(spec)) {
165
+ spec.results_.skipped = true;
166
+ spec.finish(onComplete);
167
+ return;
168
+ }
169
+
170
+ this.env.reporter.reportSpecStarting(this);
171
+
172
+ spec.env.currentSpec = spec;
173
+
174
+ spec.addBeforesAndAftersToQueue();
175
+
176
+ spec.queue.start(function () {
177
+ spec.finish(onComplete);
178
+ });
179
+ };
180
+
181
+ jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
182
+ var runner = this.env.currentRunner();
183
+ var i;
184
+
185
+ for (var suite = this.suite; suite; suite = suite.parentSuite) {
186
+ for (i = 0; i < suite.before_.length; i++) {
187
+ this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
188
+ }
189
+ }
190
+ for (i = 0; i < runner.before_.length; i++) {
191
+ this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
192
+ }
193
+ for (i = 0; i < this.afterCallbacks.length; i++) {
194
+ this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this));
195
+ }
196
+ for (suite = this.suite; suite; suite = suite.parentSuite) {
197
+ for (i = 0; i < suite.after_.length; i++) {
198
+ this.queue.add(new jasmine.Block(this.env, suite.after_[i], this));
199
+ }
200
+ }
201
+ for (i = 0; i < runner.after_.length; i++) {
202
+ this.queue.add(new jasmine.Block(this.env, runner.after_[i], this));
203
+ }
204
+ };
205
+
206
+ jasmine.Spec.prototype.explodes = function() {
207
+ throw 'explodes function should not have been called';
208
+ };
209
+
210
+ jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) {
211
+ if (obj == jasmine.undefined) {
212
+ throw "spyOn could not find an object to spy upon for " + methodName + "()";
213
+ }
214
+
215
+ if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
216
+ throw methodName + '() method does not exist';
217
+ }
218
+
219
+ if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) {
220
+ throw new Error(methodName + ' has already been spied upon');
221
+ }
222
+
223
+ var spyObj = jasmine.createSpy(methodName);
224
+
225
+ this.spies_.push(spyObj);
226
+ spyObj.baseObj = obj;
227
+ spyObj.methodName = methodName;
228
+ spyObj.originalValue = obj[methodName];
229
+
230
+ obj[methodName] = spyObj;
231
+
232
+ return spyObj;
233
+ };
234
+
235
+ jasmine.Spec.prototype.removeAllSpies = function() {
236
+ for (var i = 0; i < this.spies_.length; i++) {
237
+ var spy = this.spies_[i];
238
+ spy.baseObj[spy.methodName] = spy.originalValue;
239
+ }
240
+ this.spies_ = [];
241
+ };
242
+
@@ -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,15 @@
1
+ jasmine.WaitsBlock = function(env, timeout, spec) {
2
+ this.timeout = timeout;
3
+ jasmine.Block.call(this, env, null, spec);
4
+ };
5
+
6
+ jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
7
+
8
+ jasmine.WaitsBlock.prototype.execute = function (onComplete) {
9
+ if (jasmine.VERBOSE) {
10
+ this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
11
+ }
12
+ this.env.setTimeout(function () {
13
+ onComplete();
14
+ }, this.timeout);
15
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * A block which waits for some condition to become true, with timeout.
3
+ *
4
+ * @constructor
5
+ * @extends jasmine.Block
6
+ * @param {jasmine.Env} env The Jasmine environment.
7
+ * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
8
+ * @param {Function} latchFunction A function which returns true when the desired condition has been met.
9
+ * @param {String} message The message to display if the desired condition hasn't been met within the given time period.
10
+ * @param {jasmine.Spec} spec The Jasmine spec.
11
+ */
12
+ jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
13
+ this.timeout = timeout || env.defaultTimeoutInterval;
14
+ this.latchFunction = latchFunction;
15
+ this.message = message;
16
+ this.totalTimeSpentWaitingForLatch = 0;
17
+ jasmine.Block.call(this, env, null, spec);
18
+ };
19
+ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
20
+
21
+ jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
22
+
23
+ jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
24
+ if (jasmine.VERBOSE) {
25
+ this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
26
+ }
27
+ var latchFunctionResult;
28
+ try {
29
+ latchFunctionResult = this.latchFunction.apply(this.spec);
30
+ } catch (e) {
31
+ this.spec.fail(e);
32
+ onComplete();
33
+ return;
34
+ }
35
+
36
+ if (latchFunctionResult) {
37
+ onComplete();
38
+ } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
39
+ var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
40
+ this.spec.fail({
41
+ name: 'timeout',
42
+ message: message
43
+ });
44
+
45
+ this.abort = true;
46
+ onComplete();
47
+ } else {
48
+ this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
49
+ var self = this;
50
+ this.env.setTimeout(function() {
51
+ self.execute(onComplete);
52
+ }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
53
+ }
54
+ };