jasmine 0.11.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,23 @@
1
1
  jasmine-gem
2
2
  ============
3
3
 
4
- Jasmine Gem dynamically serves HTML suites for [Jasmine](http://github.com/pivotal/jasmine)
4
+ Jasmine Gem dynamically serves and runs suites for [Jasmine](http://github.com/pivotal/jasmine).
5
5
 
6
6
  To use:
7
7
 
8
- `(sudo) gem install jasmine`
8
+ `gem install jasmine`
9
9
 
10
10
  Post-installation:
11
11
 
12
- For Rails support, use
12
+ For Rails2 support, use
13
13
 
14
14
  `script/generate jasmine`
15
15
 
16
- For other projects, use
16
+ For Rails3 support, use
17
+
18
+ `bundle exec jasmine init`
19
+
20
+ For other Ruby projects (including Merb), use
17
21
 
18
22
  `jasmine init`
19
23
 
@@ -27,7 +31,7 @@ You may also
27
31
 
28
32
  `rake jasmine:ci`
29
33
 
30
- which will run your Jasmine suites using selenium and rspec. This task is suitable for running in continuous integration environments.
34
+ which will run your Jasmine suites using selenium and rspec. This task is suitable for running in continuous integration environments. There is currently a known issue using this rake task with RSpec2 beta.
31
35
 
32
36
  Simple Configuration:
33
37
 
@@ -35,3 +39,5 @@ Customize `spec/javascripts/support/jasmine.yml` to enumerate the source files,
35
39
  You may use dir glob strings.
36
40
 
37
41
  It is also possible to add overrides into the `spec/javascripts/support/jasmine_config.rb` file directly if you require further customization.
42
+
43
+ Copyright (c) 2008-2010 Pivotal Labs. This software is licensed under the MIT License.
@@ -17,6 +17,7 @@
17
17
 
18
18
  </head>
19
19
  <body>
20
+ <div id="REMOVE_THIS_LINE_FROM_BUILD"><p>You must be trying to look at examples in the Jasmine source tree.</p><p>Please download a distribution version of Jasmine at <a href="http://pivotal.github.com/jasmine/">http://pivotal.github.com/jasmine/</a>.</p></div>
20
21
  <script type="text/javascript">
21
22
  jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
22
23
  jasmine.getEnv().execute();
@@ -24,4 +25,3 @@
24
25
 
25
26
  </body>
26
27
  </html>
27
-
@@ -1,2 +1,2 @@
1
1
  require 'jasmine'
2
- load 'jasmine/tasks/jasmine.rake'
2
+ load 'jasmine/tasks/jasmine.rake'
@@ -17,6 +17,7 @@
17
17
 
18
18
  </head>
19
19
  <body>
20
+ <div id="REMOVE_THIS_LINE_FROM_BUILD"><p>You must be trying to look at examples in the Jasmine source tree.</p><p>Please download a distribution version of Jasmine at <a href="http://pivotal.github.com/jasmine/">http://pivotal.github.com/jasmine/</a>.</p></div>
20
21
  <script type="text/javascript">
21
22
  jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
22
23
  jasmine.getEnv().execute();
@@ -24,4 +25,3 @@
24
25
 
25
26
  </body>
26
27
  </html>
27
-
@@ -34,7 +34,7 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
34
34
  this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
35
35
  this.createDom('div', { className: 'banner' },
36
36
  this.createDom('div', { className: 'logo' },
37
- "Jasmine",
37
+ this.createDom('a', { href: 'http://pivotal.github.com/jasmine/', target: "_blank" }, "Jasmine"),
38
38
  this.createDom('span', { className: 'version' }, runner.env.versionString())),
39
39
  this.createDom('div', { className: 'options' },
40
40
  "Show ",
@@ -21,11 +21,16 @@ jasmine.unimplementedMethod_ = function() {
21
21
  jasmine.undefined = jasmine.___undefined___;
22
22
 
23
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.
24
+ * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
25
25
  *
26
26
  */
27
27
  jasmine.DEFAULT_UPDATE_INTERVAL = 250;
28
28
 
29
+ /**
30
+ * Default timeout interval in milliseconds for waitsFor() blocks.
31
+ */
32
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
33
+
29
34
  jasmine.getGlobal = function() {
30
35
  function getGlobal() {
31
36
  return this;
@@ -490,22 +495,24 @@ var runs = function(func) {
490
495
  };
491
496
 
492
497
  /**
493
- * Waits for a timeout before moving to the next runs()-defined block.
494
- * @param {Number} timeout
498
+ * Waits a fixed time period before moving to the next block.
499
+ *
500
+ * @deprecated Use waitsFor() instead
501
+ * @param {Number} timeout milliseconds to wait
495
502
  */
496
503
  var waits = function(timeout) {
497
504
  jasmine.getEnv().currentSpec.waits(timeout);
498
505
  };
499
506
 
500
507
  /**
501
- * Waits for the latchFunction to return true before proceeding to the next runs()-defined block.
508
+ * Waits for the latchFunction to return true before proceeding to the next block.
502
509
  *
503
- * @param {Number} timeout
504
510
  * @param {Function} latchFunction
505
- * @param {String} message
511
+ * @param {String} optional_timeoutMessage
512
+ * @param {Number} optional_timeout
506
513
  */
507
- var waitsFor = function(timeout, latchFunction, message) {
508
- jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message);
514
+ var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
515
+ jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
509
516
  };
510
517
 
511
518
  /**
@@ -660,6 +667,7 @@ jasmine.Env = function() {
660
667
  this.reporter = new jasmine.MultiReporter();
661
668
 
662
669
  this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
670
+ this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
663
671
  this.lastUpdate = 0;
664
672
  this.specFilter = function() {
665
673
  return true;
@@ -1135,7 +1143,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
1135
1143
  message: message
1136
1144
  });
1137
1145
  this.spec.addMatcherResult(expectationResult);
1138
- return result;
1146
+ return jasmine.undefined;
1139
1147
  };
1140
1148
  };
1141
1149
 
@@ -1153,6 +1161,7 @@ jasmine.Matchers.prototype.toBe = function(expected) {
1153
1161
  /**
1154
1162
  * toNotBe: compares the actual to the expected using !==
1155
1163
  * @param expected
1164
+ * @deprecated as of 1.0. Use not.toBe() instead.
1156
1165
  */
1157
1166
  jasmine.Matchers.prototype.toNotBe = function(expected) {
1158
1167
  return this.actual !== expected;
@@ -1170,6 +1179,7 @@ jasmine.Matchers.prototype.toEqual = function(expected) {
1170
1179
  /**
1171
1180
  * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
1172
1181
  * @param expected
1182
+ * @deprecated as of 1.0. Use not.toNotEqual() instead.
1173
1183
  */
1174
1184
  jasmine.Matchers.prototype.toNotEqual = function(expected) {
1175
1185
  return !this.env.equals_(this.actual, expected);
@@ -1188,6 +1198,7 @@ jasmine.Matchers.prototype.toMatch = function(expected) {
1188
1198
  /**
1189
1199
  * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
1190
1200
  * @param expected
1201
+ * @deprecated as of 1.0. Use not.toMatch() instead.
1191
1202
  */
1192
1203
  jasmine.Matchers.prototype.toNotMatch = function(expected) {
1193
1204
  return !(new RegExp(expected).test(this.actual));
@@ -1230,11 +1241,6 @@ jasmine.Matchers.prototype.toBeFalsy = function() {
1230
1241
  };
1231
1242
 
1232
1243
 
1233
- /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
1234
- jasmine.Matchers.prototype.wasCalled = function() {
1235
- return this.toHaveBeenCalled();
1236
- };
1237
-
1238
1244
  /**
1239
1245
  * Matcher that checks to see if the actual, a Jasmine spy, was called.
1240
1246
  */
@@ -1248,12 +1254,18 @@ jasmine.Matchers.prototype.toHaveBeenCalled = function() {
1248
1254
  }
1249
1255
 
1250
1256
  this.message = function() {
1251
- return "Expected spy " + this.actual.identity + " to have been called.";
1257
+ return [
1258
+ "Expected spy " + this.actual.identity + " to have been called.",
1259
+ "Expected spy " + this.actual.identity + " not to have been called."
1260
+ ];
1252
1261
  };
1253
1262
 
1254
1263
  return this.actual.wasCalled;
1255
1264
  };
1256
1265
 
1266
+ /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
1267
+ jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled;
1268
+
1257
1269
  /**
1258
1270
  * Matcher that checks to see if the actual, a Jasmine spy, was not called.
1259
1271
  *
@@ -1269,17 +1281,15 @@ jasmine.Matchers.prototype.wasNotCalled = function() {
1269
1281
  }
1270
1282
 
1271
1283
  this.message = function() {
1272
- return "Expected spy " + this.actual.identity + " to not have been called.";
1284
+ return [
1285
+ "Expected spy " + this.actual.identity + " to not have been called.",
1286
+ "Expected spy " + this.actual.identity + " to have been called."
1287
+ ];
1273
1288
  };
1274
1289
 
1275
1290
  return !this.actual.wasCalled;
1276
1291
  };
1277
1292
 
1278
- /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
1279
- jasmine.Matchers.prototype.wasCalledWith = function() {
1280
- return this.toHaveBeenCalledWith.apply(this, arguments);
1281
- };
1282
-
1283
1293
  /**
1284
1294
  * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
1285
1295
  *
@@ -1293,15 +1303,25 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
1293
1303
  }
1294
1304
  this.message = function() {
1295
1305
  if (this.actual.callCount == 0) {
1296
- return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
1306
+ // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
1307
+ return [
1308
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
1309
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
1310
+ ];
1297
1311
  } else {
1298
- return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall);
1312
+ return [
1313
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
1314
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
1315
+ ];
1299
1316
  }
1300
1317
  };
1301
1318
 
1302
1319
  return this.env.contains_(this.actual.argsForCall, expectedArgs);
1303
1320
  };
1304
1321
 
1322
+ /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
1323
+ jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith;
1324
+
1305
1325
  /** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */
1306
1326
  jasmine.Matchers.prototype.wasNotCalledWith = function() {
1307
1327
  var expectedArgs = jasmine.util.argsToArray(arguments);
@@ -1310,7 +1330,10 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() {
1310
1330
  }
1311
1331
 
1312
1332
  this.message = function() {
1313
- return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was";
1333
+ return [
1334
+ "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
1335
+ "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
1336
+ ]
1314
1337
  };
1315
1338
 
1316
1339
  return !this.env.contains_(this.actual.argsForCall, expectedArgs);
@@ -1329,6 +1352,7 @@ jasmine.Matchers.prototype.toContain = function(expected) {
1329
1352
  * Matcher that checks that the expected item is NOT an element in the actual Array.
1330
1353
  *
1331
1354
  * @param {Object} expected
1355
+ * @deprecated as of 1.0. Use not.toNotContain() instead.
1332
1356
  */
1333
1357
  jasmine.Matchers.prototype.toNotContain = function(expected) {
1334
1358
  return !this.env.contains_(this.actual, expected);
@@ -1362,9 +1386,11 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
1362
1386
  result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
1363
1387
  }
1364
1388
 
1389
+ var not = this.isNot ? "not " : "";
1390
+
1365
1391
  this.message = function() {
1366
1392
  if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
1367
- return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' ');
1393
+ return ["Expected function " + not + "to throw", expected ? expected.message || expected : " an exception", ", but it threw", exception.message || exception].join(' ');
1368
1394
  } else {
1369
1395
  return "Expected function to throw an exception.";
1370
1396
  }
@@ -1644,6 +1670,7 @@ jasmine.Queue = function(env) {
1644
1670
  this.running = false;
1645
1671
  this.index = 0;
1646
1672
  this.offset = 0;
1673
+ this.abort = false;
1647
1674
  };
1648
1675
 
1649
1676
  jasmine.Queue.prototype.addBefore = function(block) {
@@ -1678,7 +1705,7 @@ jasmine.Queue.prototype.next_ = function() {
1678
1705
  while (goAgain) {
1679
1706
  goAgain = false;
1680
1707
 
1681
- if (self.index < self.blocks.length) {
1708
+ if (self.index < self.blocks.length && !this.abort) {
1682
1709
  var calledSynchronously = true;
1683
1710
  var completedSynchronously = false;
1684
1711
 
@@ -1688,6 +1715,10 @@ jasmine.Queue.prototype.next_ = function() {
1688
1715
  return;
1689
1716
  }
1690
1717
 
1718
+ if (self.blocks[self.index].abort) {
1719
+ self.abort = true;
1720
+ }
1721
+
1691
1722
  self.offset = 0;
1692
1723
  self.index++;
1693
1724
 
@@ -1884,14 +1915,46 @@ jasmine.Spec.prototype.expect = function(actual) {
1884
1915
  return positive;
1885
1916
  };
1886
1917
 
1918
+ /**
1919
+ * Waits a fixed time period before moving to the next block.
1920
+ *
1921
+ * @deprecated Use waitsFor() instead
1922
+ * @param {Number} timeout milliseconds to wait
1923
+ */
1887
1924
  jasmine.Spec.prototype.waits = function(timeout) {
1888
1925
  var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
1889
1926
  this.addToQueue(waitsFunc);
1890
1927
  return this;
1891
1928
  };
1892
1929
 
1893
- jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) {
1894
- var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this);
1930
+ /**
1931
+ * Waits for the latchFunction to return true before proceeding to the next block.
1932
+ *
1933
+ * @param {Function} latchFunction
1934
+ * @param {String} optional_timeoutMessage
1935
+ * @param {Number} optional_timeout
1936
+ */
1937
+ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
1938
+ var latchFunction_ = null;
1939
+ var optional_timeoutMessage_ = null;
1940
+ var optional_timeout_ = null;
1941
+
1942
+ for (var i = 0; i < arguments.length; i++) {
1943
+ var arg = arguments[i];
1944
+ switch (typeof arg) {
1945
+ case 'function':
1946
+ latchFunction_ = arg;
1947
+ break;
1948
+ case 'string':
1949
+ optional_timeoutMessage_ = arg;
1950
+ break;
1951
+ case 'number':
1952
+ optional_timeout_ = arg;
1953
+ break;
1954
+ }
1955
+ }
1956
+
1957
+ var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
1895
1958
  this.addToQueue(waitsForFunc);
1896
1959
  return this;
1897
1960
  };
@@ -2114,41 +2177,56 @@ jasmine.WaitsBlock.prototype.execute = function (onComplete) {
2114
2177
  onComplete();
2115
2178
  }, this.timeout);
2116
2179
  };
2180
+ /**
2181
+ * A block which waits for some condition to become true, with timeout.
2182
+ *
2183
+ * @constructor
2184
+ * @extends jasmine.Block
2185
+ * @param {jasmine.Env} env The Jasmine environment.
2186
+ * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
2187
+ * @param {Function} latchFunction A function which returns true when the desired condition has been met.
2188
+ * @param {String} message The message to display if the desired condition hasn't been met within the given time period.
2189
+ * @param {jasmine.Spec} spec The Jasmine spec.
2190
+ */
2117
2191
  jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
2118
- this.timeout = timeout;
2192
+ this.timeout = timeout || env.defaultTimeoutInterval;
2119
2193
  this.latchFunction = latchFunction;
2120
2194
  this.message = message;
2121
2195
  this.totalTimeSpentWaitingForLatch = 0;
2122
2196
  jasmine.Block.call(this, env, null, spec);
2123
2197
  };
2124
-
2125
2198
  jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
2126
2199
 
2127
- jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
2200
+ jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
2128
2201
 
2129
- jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
2130
- var self = this;
2131
- self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
2202
+ jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
2203
+ this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
2132
2204
  var latchFunctionResult;
2133
2205
  try {
2134
- latchFunctionResult = self.latchFunction.apply(self.spec);
2206
+ latchFunctionResult = this.latchFunction.apply(this.spec);
2135
2207
  } catch (e) {
2136
- self.spec.fail(e);
2208
+ this.spec.fail(e);
2137
2209
  onComplete();
2138
2210
  return;
2139
2211
  }
2140
2212
 
2141
2213
  if (latchFunctionResult) {
2142
2214
  onComplete();
2143
- } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
2144
- var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
2145
- self.spec.fail({
2215
+ } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
2216
+ var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
2217
+ this.spec.fail({
2146
2218
  name: 'timeout',
2147
2219
  message: message
2148
2220
  });
2221
+
2222
+ this.abort = true;
2223
+ onComplete();
2149
2224
  } else {
2150
- self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
2151
- self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
2225
+ this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
2226
+ var self = this;
2227
+ this.env.setTimeout(function() {
2228
+ self.execute(onComplete);
2229
+ }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
2152
2230
  }
2153
2231
  };
2154
2232
  // Mock setTimeout, clearTimeout
@@ -2336,8 +2414,8 @@ jasmine.getGlobal().clearInterval = function(timeoutKey) {
2336
2414
 
2337
2415
 
2338
2416
  jasmine.version_= {
2339
- "major": 0,
2340
- "minor": 11,
2341
- "build": 1,
2342
- "revision": 1277514571
2417
+ "major": 1,
2418
+ "minor": 0,
2419
+ "build": 0,
2420
+ "revision": 1284494074
2343
2421
  };
@@ -1,6 +1,6 @@
1
1
  require 'socket'
2
2
  require 'erb'
3
- require 'json'
3
+ require 'json/pure'
4
4
 
5
5
  module Jasmine
6
6
  def self.root
@@ -44,10 +44,6 @@ module Jasmine
44
44
  end
45
45
  end
46
46
 
47
- def self.kill_process_group(process_group_id, signal="TERM")
48
- Process.kill signal, -process_group_id # negative pid means kill process group. (see man 2 kill)
49
- end
50
-
51
47
  def self.cachebust(files, root_dir="", replace=nil, replace_with=nil)
52
48
  require 'digest/md5'
53
49
  files.collect do |file_name|
@@ -18,17 +18,18 @@ module Jasmine
18
18
 
19
19
  def copy_unless_exists(relative_path, dest_path = nil)
20
20
  unless File.exist?(dest_path(relative_path))
21
- File.copy(template_path(relative_path), dest_path(dest_path || relative_path))
21
+ FileUtils.copy(template_path(relative_path), dest_path(dest_path || relative_path))
22
22
  end
23
23
  end
24
24
 
25
25
  def process(argv)
26
26
  if argv[0] == 'init'
27
- require 'ftools'
28
- File.makedirs('public/javascripts')
29
- File.makedirs('spec/javascripts')
30
- File.makedirs('spec/javascripts/support')
31
- File.makedirs('spec/javascripts/helpers')
27
+ require 'fileutils'
28
+
29
+ FileUtils.makedirs('public/javascripts')
30
+ FileUtils.makedirs('spec/javascripts')
31
+ FileUtils.makedirs('spec/javascripts/support')
32
+ FileUtils.makedirs('spec/javascripts/helpers')
32
33
 
33
34
  copy_unless_exists('jasmine-example/src/Player.js', 'public/javascripts/Player.js')
34
35
  copy_unless_exists('jasmine-example/src/Song.js', 'public/javascripts/Song.js')
@@ -51,7 +52,7 @@ module Jasmine
51
52
  require 'rake'
52
53
  unless Rake::Task.task_defined?('jasmine')
53
54
  File.open(dest_path('Rakefile'), write_mode) do |f|
54
- f.write(File.read(template_path('lib/tasks/jasmine.rake')))
55
+ f.write("\n" + File.read(template_path('lib/tasks/jasmine.rake')))
55
56
  end
56
57
  end
57
58
  end
@@ -3,13 +3,16 @@ module Jasmine
3
3
  require 'yaml'
4
4
  require 'erb'
5
5
 
6
- def initialize(options = {})
7
- require 'selenium_rc'
8
- @selenium_jar_path = SeleniumRC::Server.allocate.jar_path
6
+ def browser
7
+ ENV["JASMINE_BROWSER"] || 'firefox'
8
+ end
9
9
 
10
- @browser = ENV["JASMINE_BROWSER"] || 'firefox'
11
- @selenium_pid = nil
12
- @jasmine_server_pid = nil
10
+ def jasmine_host
11
+ ENV["JASMINE_HOST"] || 'http://localhost'
12
+ end
13
+
14
+ def external_selenium_server_port
15
+ ENV['SELENIUM_SERVER_PORT'] && ENV['SELENIUM_SERVER_PORT'].to_i > 0 ? ENV['SELENIUM_SERVER_PORT'].to_i : nil
13
16
  end
14
17
 
15
18
  def start_server(port = 8888)
@@ -19,45 +22,33 @@ module Jasmine
19
22
 
20
23
  def start
21
24
  start_servers
22
- @client = Jasmine::SeleniumDriver.new("localhost", @selenium_server_port, "*#{@browser}", "#{jasmine_host}:#{@jasmine_server_port}/")
25
+ @client = Jasmine::SeleniumDriver.new("localhost", @selenium_server_port, "*#{browser}", "#{jasmine_host}:#{@jasmine_server_port}/")
23
26
  @client.connect
24
27
  end
25
28
 
26
29
  def stop
27
30
  @client.disconnect
28
- stop_servers
29
- end
30
-
31
- def jasmine_host
32
- ENV["JASMINE_HOST"] || 'http://localhost'
33
31
  end
34
32
 
35
33
  def start_jasmine_server
36
34
  @jasmine_server_port = Jasmine::find_unused_port
37
- @jasmine_server_pid = fork do
38
- Process.setpgrp
35
+ Thread.new do
39
36
  start_server(@jasmine_server_port)
40
- exit! 0
41
37
  end
42
- puts "jasmine server started. pid is #{@jasmine_server_pid}"
43
38
  Jasmine::wait_for_listener(@jasmine_server_port, "jasmine server")
44
- end
45
-
46
- def external_selenium_server_port
47
- ENV['SELENIUM_SERVER_PORT'] && ENV['SELENIUM_SERVER_PORT'].to_i > 0 ? ENV['SELENIUM_SERVER_PORT'].to_i : nil
39
+ puts "jasmine server started."
48
40
  end
49
41
 
50
42
  def start_selenium_server
51
43
  @selenium_server_port = external_selenium_server_port
52
44
  if @selenium_server_port.nil?
53
45
  @selenium_server_port = Jasmine::find_unused_port
54
- @selenium_pid = fork do
55
- Process.setpgrp
56
- exec "java -jar #{@selenium_jar_path} -port #{@selenium_server_port} > /dev/null 2>&1"
57
- end
58
- puts "selenium started. pid is #{@selenium_pid}"
46
+ require 'selenium_rc'
47
+ SeleniumRC::Server.send(:include, SeleniumServerForkHackForRSpec)
48
+ SeleniumRC::Server.boot("localhost", @selenium_server_port, :args => ["> /dev/null"])
49
+ else
50
+ Jasmine::wait_for_listener(@selenium_server_port, "selenium server")
59
51
  end
60
- Jasmine::wait_for_listener(@selenium_server_port, "selenium server")
61
52
  end
62
53
 
63
54
  def start_servers
@@ -65,18 +56,6 @@ module Jasmine
65
56
  start_selenium_server
66
57
  end
67
58
 
68
- def stop_servers
69
- puts "shutting down the servers..."
70
- Jasmine::kill_process_group(@selenium_pid) if @selenium_pid
71
- if @jasmine_server_pid
72
- if Rack::Handler.default == Rack::Handler::WEBrick
73
- Jasmine::kill_process_group(@jasmine_server_pid, "INT")
74
- else
75
- Jasmine::kill_process_group(@jasmine_server_pid)
76
- end
77
- end
78
- end
79
-
80
59
  def run
81
60
  begin
82
61
  start
@@ -183,5 +162,20 @@ module Jasmine
183
162
  end
184
163
  end
185
164
 
165
+ module SeleniumServerForkHackForRSpec
166
+ # without this, Selenium's forked process will attempt to run specs a second time at exit;
167
+ # see http://www.ruby-forum.com/topic/212722
168
+ def self.included(base)
169
+ alias_method :fork_without_fix_for_rspec, :fork
170
+ alias_method :fork, :fork_with_fix_for_rspec
171
+ end
172
+
173
+ def fork_with_fix_for_rspec
174
+ fork_without_fix_for_rspec do
175
+ yield
176
+ at_exit { exit! }
177
+ end
178
+ end
179
+ end
186
180
  end
187
- end
181
+ end
@@ -32,7 +32,6 @@ module Jasmine
32
32
  "/__JASMINE_ROOT__/lib/jasmine.js",
33
33
  "/__JASMINE_ROOT__/lib/jasmine-html.js",
34
34
  "/__JASMINE_ROOT__/lib/json2.js",
35
- "/__JASMINE_ROOT__/lib/consolex.js",
36
35
  ]
37
36
  @jasmine_stylesheets = ["/__JASMINE_ROOT__/lib/jasmine.css"]
38
37
  end
@@ -8,12 +8,12 @@ describe Jasmine::Config do
8
8
  temp_dir_before
9
9
 
10
10
  Dir::chdir @tmp
11
- system 'rails rails-project'
11
+ `rails rails-project`
12
12
  Dir::chdir 'rails-project'
13
13
 
14
14
  FileUtils.cp_r(File.join(@root, 'generators'), 'vendor')
15
15
 
16
- system "./script/generate jasmine"
16
+ `./script/generate jasmine`
17
17
 
18
18
  Dir::chdir @old_dir
19
19
 
@@ -256,24 +256,4 @@ describe Jasmine::Config do
256
256
  config.start_selenium_server
257
257
  end
258
258
  end
259
-
260
- describe "#stop_servers" do
261
- it "should kill Selenium and Rack servers" do
262
- Rack::Handler.stub!(:default).and_return("Not WEBrick")
263
- config = Jasmine::Config.new
264
- config.instance_variable_set(:@selenium_pid, 100)
265
- config.instance_variable_set(:@jasmine_server_pid, 200)
266
- Jasmine.should_receive(:kill_process_group).with(100)
267
- Jasmine.should_receive(:kill_process_group).with(200)
268
- config.stop_servers
269
- end
270
-
271
- it "should send kill with SIGINT to WEBrick" do
272
- Rack::Handler.stub!(:default).and_return(Rack::Handler::WEBrick)
273
- config = Jasmine::Config.new
274
- config.instance_variable_set(:@jasmine_server_pid, 100)
275
- Jasmine.should_receive(:kill_process_group).with(100, "INT")
276
- config.stop_servers
277
- end
278
- end
279
259
  end
@@ -11,13 +11,16 @@ describe "Jasmine command line tool" do
11
11
  end
12
12
 
13
13
  it "should create files on init" do
14
- Jasmine::CommandLineTool.new.process ["init"]
14
+ output = capture_stdout do
15
+ Jasmine::CommandLineTool.new.process ["init"]
16
+ end
17
+ output.should =~ /Jasmine has been installed with example specs./
15
18
 
16
19
  my_jasmine_lib = File.expand_path(File.join(@root, "lib"))
17
20
  bootstrap = "$:.unshift('#{my_jasmine_lib}')"
18
21
 
19
22
  ENV['JASMINE_GEM_PATH'] = "#{@root}/lib"
20
- ci_output = `rake -E \"#{bootstrap}\" --trace jasmine:ci`
23
+ ci_output = `rake -E "#{bootstrap}" --trace jasmine:ci`
21
24
  ci_output.should =~ (/[1-9][0-9]* examples, 0 failures/)
22
25
  end
23
26
  end
@@ -11,12 +11,13 @@ describe "Jasmine rails generator" do
11
11
  end
12
12
 
13
13
  it "should create files on init" do
14
- system 'rails rails-project'
14
+ `rails rails-project`
15
15
  Dir::chdir 'rails-project'
16
16
 
17
17
  FileUtils.cp_r(File.join(@root, 'generators'), 'vendor')
18
18
 
19
- system "./script/generate jasmine"
19
+ output = `./script/generate jasmine`
20
+ output.should =~ /Jasmine has been installed with example specs./
20
21
 
21
22
  bootstrap = "$:.unshift('#{@root}/lib')"
22
23
  ENV['JASMINE_GEM_PATH'] = "#{@root}/lib"
@@ -1,5 +1,6 @@
1
1
  require "rubygems"
2
2
  require "bundler"
3
+ require 'stringio'
3
4
 
4
5
  Bundler.setup(:default, :test)
5
6
 
@@ -26,3 +27,14 @@ def temp_dir_after
26
27
  Dir::chdir @old_dir
27
28
  FileUtils.rm_r @tmp
28
29
  end
30
+
31
+ module Kernel
32
+ def capture_stdout
33
+ out = StringIO.new
34
+ $stdout = out
35
+ yield
36
+ return out.string
37
+ ensure
38
+ $stdout = STDOUT
39
+ end
40
+ end
metadata CHANGED
@@ -1,14 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
- - 0
8
- - 11
9
6
  - 1
10
7
  - 0
11
- version: 0.11.1.0
8
+ - 0
9
+ version: 1.0.0
12
10
  platform: ruby
13
11
  authors:
14
12
  - Rajan Agaskar
@@ -17,75 +15,95 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2010-06-25 00:00:00 -07:00
18
+ date: 2010-09-14 00:00:00 -07:00
21
19
  default_executable: jasmine
22
20
  dependencies:
23
21
  - !ruby/object:Gem::Dependency
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
22
+ type: :runtime
23
+ name: rake
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 8
31
+ - 7
32
+ version: 0.8.7
33
+ requirement: *id001
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ name: rspec
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
26
39
  requirements:
27
40
  - - ">="
28
41
  - !ruby/object:Gem::Version
29
- hash: 25
30
42
  segments:
31
43
  - 1
32
44
  - 1
33
45
  - 5
34
46
  version: 1.1.5
35
- type: :runtime
36
- name: rspec
37
- version_requirements: *id001
47
+ requirement: *id002
38
48
  prerelease: false
39
49
  - !ruby/object:Gem::Dependency
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
50
+ type: :runtime
51
+ name: rack
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
42
53
  requirements:
43
54
  - - ">="
44
55
  - !ruby/object:Gem::Version
45
- hash: 23
46
56
  segments:
47
57
  - 1
48
58
  - 0
49
59
  - 0
50
60
  version: 1.0.0
51
- type: :runtime
52
- name: rack
53
- version_requirements: *id002
61
+ requirement: *id003
54
62
  prerelease: false
55
63
  - !ruby/object:Gem::Dependency
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
64
+ type: :runtime
65
+ name: selenium-rc
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
58
67
  requirements:
59
68
  - - ">="
60
69
  - !ruby/object:Gem::Version
61
- hash: 11
62
70
  segments:
63
71
  - 2
64
72
  - 1
65
73
  - 0
66
74
  version: 2.1.0
67
- type: :runtime
68
- name: selenium-rc
69
- version_requirements: *id003
75
+ requirement: *id004
70
76
  prerelease: false
71
77
  - !ruby/object:Gem::Dependency
72
- requirement: &id004 !ruby/object:Gem::Requirement
73
- none: false
78
+ type: :runtime
79
+ name: selenium-client
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
74
81
  requirements:
75
82
  - - ">="
76
83
  - !ruby/object:Gem::Version
77
- hash: 61
78
84
  segments:
79
85
  - 1
80
86
  - 2
81
87
  - 17
82
88
  version: 1.2.17
89
+ requirement: *id005
90
+ prerelease: false
91
+ - !ruby/object:Gem::Dependency
83
92
  type: :runtime
84
- name: selenium-client
85
- version_requirements: *id004
93
+ name: json_pure
94
+ version_requirements: &id006 !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 1
100
+ - 4
101
+ - 3
102
+ version: 1.4.3
103
+ requirement: *id006
86
104
  prerelease: false
87
105
  description: Javascript BDD test framework
88
- email: ragaskar@gmail.com
106
+ email: jasmine-js@googlegroups.com
89
107
  executables:
90
108
  - jasmine
91
109
  extensions: []
@@ -105,7 +123,6 @@ files:
105
123
  - generators/jasmine/templates/spec/javascripts/support/jasmine.yml
106
124
  - generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb
107
125
  - jasmine/example/SpecRunner.html
108
- - jasmine/lib/consolex.js
109
126
  - jasmine/lib/jasmine-html.js
110
127
  - jasmine/lib/jasmine.css
111
128
  - jasmine/lib/jasmine.js
@@ -120,16 +137,8 @@ files:
120
137
  - lib/jasmine/spec_builder.rb
121
138
  - lib/jasmine/tasks/jasmine.rake
122
139
  - README.markdown
123
- - spec/config_spec.rb
124
- - spec/jasmine_command_line_tool_spec.rb
125
- - spec/jasmine_self_test_config.rb
126
- - spec/jasmine_self_test_spec.rb
127
- - spec/rails_generator_spec.rb
128
- - spec/server_spec.rb
129
- - spec/spec_helper.rb
130
- - bin/jasmine
131
140
  has_rdoc: true
132
- homepage: http://github.com/pivotal/jasmine-ruby
141
+ homepage: http://pivotal.github.com/jasmine
133
142
  licenses: []
134
143
 
135
144
  post_install_message:
@@ -138,30 +147,26 @@ rdoc_options:
138
147
  require_paths:
139
148
  - lib
140
149
  required_ruby_version: !ruby/object:Gem::Requirement
141
- none: false
142
150
  requirements:
143
151
  - - ">="
144
152
  - !ruby/object:Gem::Version
145
- hash: 3
146
153
  segments:
147
154
  - 0
148
155
  version: "0"
149
156
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
157
  requirements:
152
158
  - - ">="
153
159
  - !ruby/object:Gem::Version
154
- hash: 3
155
160
  segments:
156
161
  - 0
157
162
  version: "0"
158
163
  requirements: []
159
164
 
160
165
  rubyforge_project:
161
- rubygems_version: 1.3.7
166
+ rubygems_version: 1.3.6
162
167
  signing_key:
163
168
  specification_version: 3
164
- summary: Jasmine Ruby Runner
169
+ summary: Jasmine Runner for Ruby
165
170
  test_files:
166
171
  - spec/config_spec.rb
167
172
  - spec/jasmine_command_line_tool_spec.rb
@@ -1,28 +0,0 @@
1
- /** Console X
2
- * http://github.com/deadlyicon/consolex.js
3
- *
4
- * By Jared Grippe <jared@jaredgrippe.com>
5
- *
6
- * Copyright (c) 2009 Jared Grippe
7
- * Licensed under the MIT license.
8
- *
9
- * consolex avoids ever having to see javascript bugs in browsers that do not implement the entire
10
- * firebug console suit
11
- *
12
- */
13
- (function(window) {
14
- window.console || (window.console = {});
15
-
16
- var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
17
- "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
18
-
19
- function emptyFunction(){}
20
-
21
- for (var i = 0; i < names.length; ++i){
22
- window.console[names[i]] || (window.console[names[i]] = emptyFunction);
23
- if (typeof window.console[names[i]] !== 'function')
24
- window.console[names[i]] = (function(method) {
25
- return function(){ return Function.prototype.apply.apply(method, [console,arguments]); };
26
- })(window.console[names[i]]);
27
- }
28
- })(this);