visionmedia-jspec 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,9 @@
1
1
 
2
+ === 2.5.1 / 2009-07-07
3
+
4
+ * Added intermediate node.js support
5
+ * Fixed; grammar now allows foo.bar.baz.stub() etc to convert to stub(foo.bar.baz)
6
+
2
7
  === 2.5.0 / 2009-07-03
3
8
 
4
9
  * Added contrib in README (thanks to anyone who has helped)
data/Manifest CHANGED
@@ -26,6 +26,7 @@ spec/spec.jquery.js
26
26
  spec/spec.js
27
27
  spec/spec.matchers.js
28
28
  spec/spec.modules.js
29
+ spec/spec.node.js
29
30
  spec/spec.rhino.js
30
31
  spec/spec.server.html
31
32
  spec/spec.shared-behaviors.js
@@ -12,6 +12,7 @@ and much more.
12
12
  * Framework / DOM independent
13
13
  * Modular via JSpec Module's and hooks
14
14
  * Rhino support
15
+ * Node.js support
15
16
  * Async support
16
17
  * Ruby JavaScript testing server
17
18
  * Nested describes
@@ -563,6 +564,18 @@ Run with:
563
564
  * Tabs may cause a parse error. To prevent this use 'soft tabs' (setting in your IDE/Editor)
564
565
  or use JSpec's grammar-less alternative (mentioned above).
565
566
 
567
+ * The preprocessor is not (yet) capable of multiline conversions. For example the following is invalid
568
+
569
+ object.stub('getContentsOfURL').and_return(function(url){
570
+ return 'html'
571
+ })
572
+
573
+ In cases such as this, you may always revert to utilizing JSpec in a grammar-less form as follows:
574
+
575
+ stub(object, 'getContentsOfURL').and_return(function(url){
576
+ return 'html'
577
+ })
578
+
566
579
  == More Information
567
580
 
568
581
  * Featured article in JSMag: http://www.jsmag.com/main.issues.description/id=21/
data/bin/jspec CHANGED
@@ -11,7 +11,7 @@ require 'fileutils'
11
11
  RHINO = 'java org.mozilla.javascript.tools.shell.Main'
12
12
 
13
13
  program :name, 'JSpec'
14
- program :version, '2.5.0'
14
+ program :version, '2.5.1'
15
15
  program :description, 'JavaScript BDD Testing Framework'
16
16
  default_command :bind
17
17
 
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{jspec}
5
- s.version = "2.5.0"
5
+ s.version = "2.5.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-07-03}
9
+ s.date = %q{2009-07-07}
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}
13
13
  s.executables = ["jspec"]
14
14
  s.extra_rdoc_files = ["bin/jspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/loading.gif", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "README.rdoc"]
15
- s.files = ["bin/jspec", "History.rdoc", "jspec.gemspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/loading.gif", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/server.rb", "spec/async", "spec/env.js", "spec/jquery-1.3.1.js", "spec/modules.js", "spec/spec.dom.html", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.jquery.js", "spec/spec.js", "spec/spec.matchers.js", "spec/spec.modules.js", "spec/spec.rhino.js", "spec/spec.server.html", "spec/spec.shared-behaviors.js", "spec/spec.utils.js", "templates/default/History.rdoc", "templates/default/lib/yourlib.core.js", "templates/default/README.rdoc", "templates/default/spec/spec.core.js", "templates/default/spec/spec.dom.html", "templates/default/spec/spec.rhino.js", "templates/default/spec/spec.server.html"]
15
+ s.files = ["bin/jspec", "History.rdoc", "jspec.gemspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/loading.gif", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/server.rb", "spec/async", "spec/env.js", "spec/jquery-1.3.1.js", "spec/modules.js", "spec/spec.dom.html", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.jquery.js", "spec/spec.js", "spec/spec.matchers.js", "spec/spec.modules.js", "spec/spec.node.js", "spec/spec.rhino.js", "spec/spec.server.html", "spec/spec.shared-behaviors.js", "spec/spec.utils.js", "templates/default/History.rdoc", "templates/default/lib/yourlib.core.js", "templates/default/README.rdoc", "templates/default/spec/spec.core.js", "templates/default/spec/spec.dom.html", "templates/default/spec/spec.rhino.js", "templates/default/spec/spec.server.html"]
16
16
  s.homepage = %q{http://visionmedia.github.com/jspec}
17
17
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jspec", "--main", "README.rdoc"]
18
18
  s.require_paths = ["lib"]
@@ -5,7 +5,7 @@
5
5
 
6
6
  JSpec = {
7
7
 
8
- version : '2.5.0',
8
+ version : '2.5.1',
9
9
  suites : [],
10
10
  modules : [],
11
11
  allSuites : [],
@@ -1072,8 +1072,9 @@
1072
1072
  object[type + method] = object[method]
1073
1073
  object[method] = function(){}
1074
1074
  return {
1075
- and_return : function(result) {
1076
- object[method] = function(){ return result }
1075
+ and_return : function(value) {
1076
+ if (typeof value == 'function') object[method] = value
1077
+ else object[method] = function(){ return value }
1077
1078
  }
1078
1079
  }
1079
1080
  },
@@ -1217,7 +1218,7 @@
1217
1218
  preprocess : function(input) {
1218
1219
  input = hookImmutable('preprocessing', input)
1219
1220
  return input.
1220
- replace(/(\w+)\.(stub|destub)\((.*?)\)$/gm, '$2($1, $3)').
1221
+ replace(/([\w\.]+)\.(stub|destub)\((.*?)\)$/gm, '$2($1, $3)').
1221
1222
  replace(/describe\s+(.*?)$/gm, 'describe($1, function(){').
1222
1223
  replace(/\sit\s+(.*?)$/gm, ' it($1, function(){').
1223
1224
  replace(/^(?: *)(before_each|after_each|before|after)(?= |\n|$)/gm, 'JSpec.currentSuite.addHook("$1", function(){').
@@ -1444,14 +1445,15 @@
1444
1445
  },
1445
1446
 
1446
1447
  /**
1447
- * Load a files contents.
1448
+ * Load a _file_'s contents.
1448
1449
  *
1449
1450
  * @param {string} file
1451
+ * @param {function} callback
1450
1452
  * @return {string}
1451
1453
  * @api public
1452
1454
  */
1453
1455
 
1454
- load : function(file) {
1456
+ load : function(file, callback) {
1455
1457
  if (any(hook('loading', file), haveStopped)) return
1456
1458
  if (this.hasXhr()) {
1457
1459
  var request = this.xhr()
@@ -1460,9 +1462,9 @@
1460
1462
  if (request.readyState == 4) return request.responseText
1461
1463
  }
1462
1464
  else if ('readFile' in main)
1463
- return readFile(file)
1465
+ return callback ? readFile(file, callback) : readFile(file)
1464
1466
  else
1465
- error('cannot load ' + file)
1467
+ error("failed to load `" + file + "'")
1466
1468
  },
1467
1469
 
1468
1470
  /**
@@ -1475,7 +1477,12 @@
1475
1477
 
1476
1478
  exec : function(file) {
1477
1479
  if (any(hook('executing', file), haveStopped)) return this
1478
- eval('with (JSpec){' + this.preprocess(this.load(file)) + '}')
1480
+ if ('node' in main)
1481
+ this.load(file, function(contents){
1482
+ eval('with (JSpec){ ' + JSpec.preprocess(contents) + ' }')
1483
+ })
1484
+ else
1485
+ eval('with (JSpec){' + this.preprocess(this.load(file)) + '}')
1479
1486
  return this
1480
1487
  }
1481
1488
  }
@@ -10,7 +10,7 @@ describe 'jQuery'
10
10
  dom.should.have_text 'test'
11
11
  end
12
12
  end
13
-
13
+
14
14
  describe 'element() / elements()'
15
15
  it 'should alias jQuery'
16
16
  element.should.be jQuery
@@ -0,0 +1,44 @@
1
+
2
+ __loading__ = []
3
+ __loadDelay__ = 1000
4
+
5
+ readFile = function(path, callback) {
6
+ __loading__.push(path)
7
+ var promise = node.fs.cat(path, "utf8")
8
+ promise.addErrback(function(){ throw "failed to read file `" + path + "'" })
9
+ promise.addCallback(function(contents){
10
+ setTimeout(function(){
11
+ if (__loading__[0] == path)
12
+ __loading__.shift(), callback(contents)
13
+ else
14
+ setTimeout(arguments.callee, 50)
15
+ }, 50)
16
+ })
17
+ }
18
+
19
+ load = function(path) {
20
+ readFile(path, function(contents){
21
+ eval(contents)
22
+ })
23
+ }
24
+
25
+ load('lib/jspec.js')
26
+ load('spec/modules.js')
27
+ load('spec/spec.grammar-less.js')
28
+
29
+ setTimeout(function(){
30
+ JSpec
31
+ .exec('spec/spec.grammar.js')
32
+ .exec('spec/spec.js')
33
+ .exec('spec/spec.matchers.js')
34
+ .exec('spec/spec.utils.js')
35
+ .exec('spec/spec.shared-behaviors.js')
36
+ .exec('spec/spec.modules.js')
37
+ setTimeout(function(){
38
+ JSpec.run({ formatter : JSpec.formatters.Terminal, failuresOnly : true })
39
+ setTimeout(function() {
40
+ JSpec.report()
41
+ }, __loadDelay__ / 3)
42
+ }, __loadDelay__ / 3)
43
+ }, __loadDelay__ / 3)
44
+
@@ -61,6 +61,24 @@ describe 'Utility'
61
61
  destub(object)
62
62
  object[' super cool '].should.be_null
63
63
  end
64
+
65
+ it 'should stub sub properties using the JSpec grammar'
66
+ object = { foo : { bar : {}}}
67
+ object.foo.bar.stub('kitten').and_return('meow')
68
+ object.foo.bar.kitten().should.eql 'meow'
69
+ object.foo.bar.destub()
70
+ object.foo.bar.should.not.respond_to('kitten')
71
+ end
72
+
73
+ it 'should allow functions to be passed as a method'
74
+ stub(object, 'post').and_return(function(url, callback){
75
+ if (url == 'http://jspec.info')
76
+ callback('is awesome')
77
+ })
78
+ object.post('http://jspec.info', function(text){
79
+ text.should_eql 'is awesome'
80
+ })
81
+ end
64
82
  end
65
83
 
66
84
  describe 'destub()'
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.5.0
4
+ version: 2.5.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-07-03 00:00:00 -07:00
12
+ date: 2009-07-07 00:00:00 -07:00
13
13
  default_executable: jspec
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -79,6 +79,7 @@ files:
79
79
  - spec/spec.js
80
80
  - spec/spec.matchers.js
81
81
  - spec/spec.modules.js
82
+ - spec/spec.node.js
82
83
  - spec/spec.rhino.js
83
84
  - spec/spec.server.html
84
85
  - spec/spec.shared-behaviors.js