visionmedia-jspec 2.2.0 → 2.2.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.
data/History.rdoc CHANGED
@@ -1,4 +1,19 @@
1
1
 
2
+ === 2.2.1 / 2009-06-22
3
+
4
+ * Changed; reportToServer() now accepts url arg
5
+
6
+ * Fixed be_empty matcher; now considers {} empty, however { foo : bar } is not
7
+ * Fixed throw_error error messages for Opera
8
+ * Fixed throw_error in Rhino (Opera is broken now)
9
+ * Fixed stray console.log() call
10
+
11
+ * Fixed some tab issues.
12
+ When using the JSpec grammar option you should
13
+ use the 'soft tabs' feature of your IDE or text editor.
14
+ A patch for tabs is pending and should be available soon,
15
+ however be aware that a 'parse error' may occur otherwise.
16
+
2
17
  === 2.2.0 / 2009-06-18
3
18
 
4
19
  * Added link to JSpec in JSMag June 2009
data/README.rdoc CHANGED
@@ -134,7 +134,7 @@ JSpec.options.failuresOnly = true, and ?failuresOnly=1 will both work.
134
134
  - be_at_least >=
135
135
  - be_at_most <=
136
136
  - be_null == null
137
- - be_empty length of 0
137
+ - be_empty length < 0 or {}
138
138
  - be_true == true
139
139
  - be_false == false
140
140
  - be_type be type of x
@@ -206,7 +206,6 @@ For more examples view spec/spec.matchers.js
206
206
 
207
207
  * Core
208
208
 
209
- - wait delay execution of a spec for the duration set (async support)
210
209
  - an_instance_of used in conjunction with the 'receive' matcher
211
210
 
212
211
  * jQuery
@@ -247,19 +246,6 @@ common functionality. For example an Admin, would inherit all specs of User:
247
246
 
248
247
  NOTE: both User and Administrator's before hooks implement the 'user' variable
249
248
 
250
- == Async Support Using wait()
251
-
252
- When using jQuery with JSpec all requests are switched to sync, allowing specs
253
- to run naturally, however when testing functionality using setTimeout, setInterval etc
254
- JSpec supplies the wait() utility to delay a spec from running:
255
-
256
- it 'should wait for n milliseconds'
257
- wait(2, 'seconds')
258
- setTimeout(function(){
259
- true.should.be true
260
- }, 1500)
261
- end
262
-
263
249
  == Hooks
264
250
 
265
251
  Currently the following hooks are supported, and may be utilized any number of times as they
@@ -461,6 +447,11 @@ Initialize project with:
461
447
 
462
448
  Run with:
463
449
  $ jspec run --server
450
+
451
+ == Known Issues
452
+
453
+ * Tabs may cause a parse error. To prevent this use 'soft tabs' (setting in your IDE/Editor)
454
+ or use JSpec's grammar-less alternative (mentioned above).
464
455
 
465
456
  == More Information
466
457
 
data/bin/jspec CHANGED
@@ -10,7 +10,7 @@ require 'fileutils'
10
10
  RHINO = 'java org.mozilla.javascript.tools.shell.Main'
11
11
 
12
12
  program :name, 'JSpec'
13
- program :version, '2.2.0'
13
+ program :version, '2.2.1'
14
14
  program :description, 'JavaScript BDD Testing Framework'
15
15
  default_command :bind
16
16
 
data/jspec.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{jspec}
5
- s.version = "2.2.0"
5
+ s.version = "2.2.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["TJ Holowaychuk"]
9
- s.date = %q{2009-06-18}
9
+ s.date = %q{2009-06-22}
10
10
  s.default_executable = %q{jspec}
11
11
  s.description = %q{JavaScript BDD Testing Framework}
12
12
  s.email = %q{tj@vision-media.ca}
data/lib/jspec.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  JSpec = {
7
7
 
8
- version : '2.2.0',
8
+ version : '2.2.1',
9
9
  suites : [],
10
10
  allSuites : [],
11
11
  matchers : {},
@@ -44,25 +44,6 @@
44
44
 
45
45
  an_instance_of : function(constructor) {
46
46
  return { an_instance_of : constructor }
47
- },
48
-
49
- /**
50
- * Sets the current spec's wait duration to _n_.
51
- *
52
- * wait(3000)
53
- * wait(1, 'second')
54
- * wait(3, 'seconds')
55
- *
56
- * @param {number} n
57
- * @param {string} unit
58
- * @api public
59
- */
60
-
61
- wait : function(n, unit) {
62
- JSpec.currentSpec.wait = {
63
- 'second' : n * 1000,
64
- 'seconds' : n * 1000
65
- }[unit] || n
66
47
  }
67
48
  },
68
49
 
@@ -1045,14 +1026,14 @@
1045
1026
 
1046
1027
  preprocess : function(input) {
1047
1028
  return input.
1048
- replace(/describe (.*?)$/gm, 'describe($1, function(){').
1049
- replace(/ it (.*?)$/gm, ' it($1, function(){').
1029
+ replace(/describe\s+(.*?)$/gm, 'describe($1, function(){').
1030
+ replace(/\sit\s+(.*?)$/gm, ' it($1, function(){').
1050
1031
  replace(/^(?: *)(before_each|after_each|before|after)(?= |\n|$)/gm, 'JSpec.currentSuite.addHook("$1", function(){').
1051
- replace(/end(?= |\n|$)/gm, '});').
1032
+ replace(/end(?=\s|$)/gm, '});').
1052
1033
  replace(/-\{/g, 'function(){').
1053
1034
  replace(/(\d+)\.\.(\d+)/g, function(_, a, b){ return range(a, b) }).
1054
1035
  replace(/\.should([_\.]not)?[_\.](\w+)(?: |$)(.*)$/gm, '.should$1_$2($3)').
1055
- replace(/([\/ ]*)(.+?)\.(should(?:[_\.]not)?)[_\.](\w+)\((.*)\)$/gm, '$1 expect($2).$3($4, $5)').
1036
+ replace(/([\/\s]*)(.+?)\.(should(?:[_\.]not)?)[_\.](\w+)\((.*)\)$/gm, '$1 expect($2).$3($4, $5)').
1056
1037
  replace(/, \)/gm, ')').
1057
1038
  replace(/should\.not/gm, 'should_not')
1058
1039
  },
@@ -1072,18 +1053,6 @@
1072
1053
  else while (--current >= end) values.push(current)
1073
1054
  return '[' + values + ']'
1074
1055
  },
1075
-
1076
- /**
1077
- * Call _callback_ when all specs have finished.
1078
- *
1079
- * @param {function} callback
1080
- * @api public
1081
- */
1082
-
1083
- whenFinished : function(callback) {
1084
- if (this.stats.specsFinished >= this.stats.specs) callback()
1085
- else setTimeout(function(){ JSpec.whenFinished(callback) }, 50)
1086
- },
1087
1056
 
1088
1057
  /**
1089
1058
  * Report on the results.
@@ -1092,11 +1061,9 @@
1092
1061
  */
1093
1062
 
1094
1063
  report : function() {
1095
- this.whenFinished(function() {
1096
- JSpec.options.formatter ?
1097
- new JSpec.options.formatter(JSpec, JSpec.options):
1098
- new JSpec.formatters.DOM(JSpec, JSpec.options)
1099
- })
1064
+ JSpec.options.formatter ?
1065
+ new JSpec.options.formatter(JSpec, JSpec.options):
1066
+ new JSpec.formatters.DOM(JSpec, JSpec.options)
1100
1067
  },
1101
1068
 
1102
1069
  /**
@@ -1116,20 +1083,6 @@
1116
1083
  return this
1117
1084
  },
1118
1085
 
1119
- /**
1120
- * When the current spec's wait duration has passed
1121
- * the _callback_ will be called.
1122
- *
1123
- * @param {function} callback
1124
- * @api public
1125
- */
1126
-
1127
- whenCurrentSpecIsFinished : function(callback) {
1128
- if (this.currentSpec && this.currentSpec.wait)
1129
- setTimeout(callback, this.currentSpec.wait)
1130
- else callback()
1131
- },
1132
-
1133
1086
  /**
1134
1087
  * Run a suite.
1135
1088
  *
@@ -1143,11 +1096,9 @@
1143
1096
  suite.ran = true
1144
1097
  suite.hook('before')
1145
1098
  each(suite.specs, function(spec) {
1146
- JSpec.whenCurrentSpecIsFinished(function(){
1147
- suite.hook('before_each')
1148
- JSpec.runSpec(spec)
1149
- suite.hook('after_each')
1150
- })
1099
+ suite.hook('before_each')
1100
+ JSpec.runSpec(spec)
1101
+ suite.hook('after_each')
1151
1102
  })
1152
1103
  if (suite.hasSuites()) {
1153
1104
  each(suite.suites, function(suite) {
@@ -1248,16 +1199,15 @@
1248
1199
  },
1249
1200
 
1250
1201
  /**
1251
- * Report back to server with statistics.
1202
+ * Report to server with statistics.
1252
1203
  *
1204
+ * @param {string} url
1253
1205
  * @api private
1254
1206
  */
1255
1207
 
1256
- reportToServer : function() {
1257
- this.whenFinished(function(){
1258
- JSpec.post('http://localhost:4444', 'passes=' + JSpec.stats.passes + '&failures=' + JSpec.stats.failures)
1259
- if ('close' in main) main.close()
1260
- })
1208
+ reportToServer : function(url) {
1209
+ JSpec.post(url || 'http://localhost:4444', 'passes=' + JSpec.stats.passes + '&failures=' + JSpec.stats.failures)
1210
+ if ('close' in main) main.close()
1261
1211
  },
1262
1212
 
1263
1213
  /**
@@ -1359,7 +1309,6 @@
1359
1309
  be_an : "alias be_a",
1360
1310
  be_an_instance_of : "actual instanceof expected",
1361
1311
  be_null : "actual == null",
1362
- be_empty : "actual.length == 0",
1363
1312
  be_true : "actual == true",
1364
1313
  be_false : "actual == false",
1365
1314
  be_type : "typeof actual == expected",
@@ -1381,6 +1330,13 @@
1381
1330
  JSpec.currentSpec.assertions.push(proxy)
1382
1331
  return proxy
1383
1332
  }},
1333
+
1334
+ be_empty : function(actual) {
1335
+ if (actual.constructor == Object && actual.length == undefined)
1336
+ for (var key in actual)
1337
+ return false;
1338
+ return !actual.length
1339
+ },
1384
1340
 
1385
1341
  include : function(actual) {
1386
1342
  for (state = true, i = 1; i < arguments.length; i++) {
@@ -1411,11 +1367,10 @@
1411
1367
  catch (e) {
1412
1368
  this.e = e
1413
1369
  var assert = function(arg) {
1414
- console.log(e.constructor);
1415
1370
  switch (arg.constructor) {
1416
1371
  case RegExp : return arg.test(e)
1417
- case Function : return e.constructor == arg
1418
1372
  case String : return arg == (e.message || e.toString())
1373
+ case Function : return (e.name || 'Error') == arg.name
1419
1374
  }
1420
1375
  }
1421
1376
  return message ? assert(expected) && assert(message) :
@@ -1428,13 +1383,10 @@
1428
1383
  if (expected[i] == undefined) return 'exception'
1429
1384
  switch (expected[i].constructor) {
1430
1385
  case RegExp : return 'exception matching ' + puts(expected[i])
1431
- case Function : return expected[i].name
1432
1386
  case String : return 'exception of ' + puts(expected[i])
1387
+ case Function : return expected[i].name || 'Error'
1433
1388
  }
1434
1389
  }
1435
- if (expected[1] == Error && expected[2] == 'oh no!') {
1436
- console.log(expected);
1437
- }
1438
1390
  exception = message_for(1) + (expected[2] ? ' and ' + message_for(2) : '')
1439
1391
  return 'expected ' + exception + (negate ? ' not ' : '' ) +
1440
1392
  ' to be thrown, but ' + (this.e ? 'got ' + puts(this.e) : 'nothing was')
@@ -1472,4 +1424,5 @@
1472
1424
  }
1473
1425
  })
1474
1426
 
1475
- })()
1427
+ })()
1428
+
data/spec/spec.grammar.js CHANGED
@@ -1,11 +1,12 @@
1
1
 
2
2
  describe 'Grammar'
3
3
 
4
- it 'should allow "it" spec literal'
4
+ it 'should allow "it" spec literal'
5
5
  true.should.be_true
6
6
  end
7
7
 
8
8
  n = 10
9
+
9
10
  it 'should allow literal javascript outside of blocks'
10
11
  n.should.eql 10
11
12
  end
data/spec/spec.js CHANGED
@@ -61,7 +61,7 @@ describe 'Negative specs'
61
61
  -{ throw new TypeError('oh no') }.should.throw_error(Error)
62
62
  end
63
63
 
64
- it 'should should fail saying multiple arg messages'
64
+ it 'should fail saying multiple arg messages'
65
65
  -{ throw new TypeError('oh no') }.should.throw_error(TypeError, /foo/)
66
66
  end
67
67
 
@@ -58,11 +58,16 @@ describe 'Matchers'
58
58
  end
59
59
 
60
60
  describe 'be_empty'
61
- it 'should consider any object responding to a length of 0 to be empty'
61
+ it 'should consider any object with zero length to be empty'
62
62
  ''.should.be_empty
63
63
  ' '.should.not.be_empty
64
64
  [].should.be_empty
65
65
  { length : 0 }.should.be_empty
66
+ {}.should.be_empty
67
+ 'cookies'.should.not.be_empty
68
+ [0].should.not.be_empty
69
+ { length : 1 }.should.not.be_empty
70
+ { foo : 'bar' }.should.not.be_empty
66
71
  end
67
72
  end
68
73
 
@@ -196,7 +201,8 @@ describe 'Matchers'
196
201
  it 'should check if an error of a specific constructor is thrown'
197
202
  -{ throw new Error('foo') }.should.throw_error(Error)
198
203
  -{ throw new TypeError('foo') }.should.throw_error(TypeError)
199
- -{ throw 'foo' }.should.not.throw_error(Error)
204
+ -{ throw 'foo' }.should.throw_error Error
205
+ -{ throw 'foo' }.should.not.throw_error TypeError
200
206
  end
201
207
 
202
208
  it 'should check if an error with a specific constructor and message is thrown'
data/spec/spec.utils.js CHANGED
@@ -1,21 +1,5 @@
1
1
 
2
2
  describe 'Utility'
3
- describe 'wait'
4
- it 'should wait for n milliseconds'
5
- wait(2000)
6
- setTimeout(function(){
7
- true.should.be true
8
- }, 1500)
9
- end
10
-
11
- it 'should wait for n seconds'
12
- wait(3, 'seconds')
13
- setTimeout(function(){
14
- true.should.be true
15
- }, 2500)
16
- end
17
- end
18
-
19
3
  describe 'query'
20
4
  it 'should return a pairs value'
21
5
  query('suite', '?suite=Positive%20specs').should.equal 'Positive specs'
@@ -135,4 +119,10 @@ describe 'Utility'
135
119
  JSpec.currentSpec.assertions.should.have_length 0
136
120
  end
137
121
  end
122
+
123
+ describe 'contentsOf'
124
+ it 'should return a function body'
125
+ JSpec.contentsOf(-{ return 'foo' }).should.include 'return', 'foo'
126
+ end
127
+ end
138
128
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visionmedia-jspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-18 00:00:00 -07:00
12
+ date: 2009-06-22 00:00:00 -07:00
13
13
  default_executable: jspec
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency