visionmedia-jspec 2.8.2 → 2.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,13 @@
1
1
 
2
+ === 2.8.3 / 2009-07-30
3
+
4
+ * Added JSpec.evalHook()
5
+ * Added JSpec.paramsFor()
6
+ * Refactored jspec.xhr.js
7
+ * Fixed mock xhr HEAD method
8
+ * Fixed node.js print() newline issue
9
+ * Fixed specs preventing spec/spec.node.js from running
10
+
2
11
  === 2.8.2 / 2009-07-29
3
12
 
4
13
  * Added JSpec.tryLoading()
data/Manifest CHANGED
@@ -23,6 +23,7 @@ spec/fixtures/test.json
23
23
  spec/fixtures/test.xml
24
24
  spec/modules.js
25
25
  spec/spec.dom.html
26
+ spec/spec.fixtures.js
26
27
  spec/spec.grammar-less.js
27
28
  spec/spec.grammar.js
28
29
  spec/spec.jquery.js
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.8.2'
14
+ program :version, '2.8.3'
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.8.2"
5
+ s.version = "2.8.3"
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-29}
9
+ s.date = %q{2009-07-30}
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", "lib/jspec.xhr.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", "lib/jspec.xhr.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/server.rb", "spec/async", "spec/env.js", "spec/fixtures/test.html", "spec/fixtures/test.json", "spec/fixtures/test.xml", "spec/modules.js", "spec/spec.dom.html", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.jquery.js", "spec/spec.jquery.xhr.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", "spec/spec.xhr.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", "templates/rails/spec.application.js", "templates/rails/spec.dom.html", "templates/rails/spec.rhino.js", "templates/rails/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", "lib/jspec.xhr.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/server.rb", "spec/async", "spec/env.js", "spec/fixtures/test.html", "spec/fixtures/test.json", "spec/fixtures/test.xml", "spec/modules.js", "spec/spec.dom.html", "spec/spec.fixtures.js", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.jquery.js", "spec/spec.jquery.xhr.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", "spec/spec.xhr.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", "templates/rails/spec.application.js", "templates/rails/spec.dom.html", "templates/rails/spec.rhino.js", "templates/rails/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.8.2',
8
+ version : '2.8.3',
9
9
  cache : {},
10
10
  suites : [],
11
11
  modules : [],
@@ -646,10 +646,31 @@
646
646
  args = argumentsToArray(arguments, 1)
647
647
  return inject(JSpec.modules, [], function(results, module){
648
648
  if (typeof module[name] == 'function')
649
- results.push(module[name].apply(this, args))
649
+ results.push(JSpec.evalHook(module, name, args))
650
650
  })
651
651
  },
652
652
 
653
+ /**
654
+ * Eval _module_ hook _name_ with _args_. Evaluates in context
655
+ * to the module itself, JSpec, and JSpec.context.
656
+ *
657
+ * @param {Module} module
658
+ * @param {string} name
659
+ * @param {array} args
660
+ * @return {mixed}
661
+ * @api private
662
+ */
663
+
664
+ evalHook : function(module, name, args) {
665
+ var context = this.context || this.defaultContext
666
+ var contents = this.contentsOf(module[name])
667
+ var params = this.paramsFor(module[name])
668
+ params.unshift('context'); args.unshift(context)
669
+ hook('evaluatingHookBody', module, name, context)
670
+ try { return new Function(params.join(), 'with (this.utilities) { with (context) { with (JSpec) { ' + contents + ' }}}').apply(module, args) }
671
+ catch(e) { error('Error in hook ' + module.name + "." + name + ': ', e) }
672
+ },
673
+
653
674
  /**
654
675
  * Same as hook() however accepts only one _arg_ which is
655
676
  * considered immutable. This function passes the arg
@@ -665,7 +686,7 @@
665
686
  hookImmutable : function(name, arg) {
666
687
  return inject(JSpec.modules, arg, function(result, module){
667
688
  if (typeof module[name] == 'function')
668
- return module[name].call(this, result)
689
+ return JSpec.evalHook(module, name, [result])
669
690
  })
670
691
  },
671
692
 
@@ -1225,6 +1246,18 @@
1225
1246
  contentsOf : function(body) {
1226
1247
  return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]
1227
1248
  },
1249
+
1250
+ /**
1251
+ * Return param names for a function body.
1252
+ *
1253
+ * @param {function} body
1254
+ * @return {array}
1255
+ * @api public
1256
+ */
1257
+
1258
+ paramsFor : function(body) {
1259
+ return body.toString().match(/\((.*?)\)/)[1].match(/[\w]+/g) || []
1260
+ },
1228
1261
 
1229
1262
  /**
1230
1263
  * Evaluate a JSpec capture body.
@@ -1353,7 +1386,6 @@
1353
1386
  JSpec.currentSpec.fail(message)
1354
1387
  },
1355
1388
 
1356
-
1357
1389
  /**
1358
1390
  * Report a passing assertion for the current spec.
1359
1391
  *
@@ -1,121 +1,173 @@
1
1
 
2
2
  // JSpec - XHR - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
3
3
 
4
- JSpec.defaultXMLHttpRequest = 'XMLHttpRequest' in this ? XMLHttpRequest : function(){}
5
- JSpec.XMLHttpRequest = function(){ this.requestHeaders = {} }
6
- JSpec.XMLHttpRequest.status = {
7
- 100 : 'Continue',
8
- 101 : 'Switching Protocols',
9
- 200 : 'OK',
10
- 201 : 'Created',
11
- 202 : 'Accepted',
12
- 203 : 'Non-Authoritative Information',
13
- 204 : 'No Content',
14
- 205 : 'Reset Content',
15
- 206 : 'Partial Content',
16
- 300 : 'Multiple Choice',
17
- 301 : 'Moved Permanently',
18
- 302 : 'Found',
19
- 303 : 'See Other',
20
- 304 : 'Not Modified',
21
- 305 : 'Use Proxy',
22
- 307 : 'Temporary Redirect',
23
- 400 : 'Bad Request',
24
- 401 : 'Unauthorized',
25
- 402 : 'Payment Required',
26
- 403 : 'Forbidden',
27
- 404 : 'Not Found',
28
- 405 : 'Method Not Allowed',
29
- 406 : 'Not Acceptable',
30
- 407 : 'Proxy Authentication Required',
31
- 408 : 'Request Timeout',
32
- 409 : 'Conflict',
33
- 410 : 'Gone',
34
- 411 : 'Length Required',
35
- 412 : 'Precondition Failed',
36
- 413 : 'Request Entity Too Large',
37
- 414 : 'Request-URI Too Long',
38
- 415 : 'Unsupported Media Type',
39
- 416 : 'Requested Range Not Satisfiable',
40
- 417 : 'Expectation Failed',
41
- 422 : 'Unprocessable Entity',
42
- 500 : 'Internal Server Error',
43
- 501 : 'Not Implemented',
44
- 502 : 'Bad Gateway',
45
- 503 : 'Service Unavailable',
46
- 504 : 'Gateway Timeout',
47
- 505 : 'HTTP Version Not Supported'
48
- }
4
+ (function(){
5
+
6
+ // --- Original XMLHttpRequest
7
+
8
+ var OriginalXMLHttpRequest = 'XMLHttpRequest' in this ?
9
+ XMLHttpRequest :
10
+ function(){}
11
+
12
+ // --- MockXMLHttpRequest
49
13
 
50
- JSpec.XMLHttpRequest.prototype = {
51
- status : 0,
52
- async : true,
53
- readyState : 0,
54
- responseText : '',
55
- abort : function(){},
56
- onreadystatechange : function(){},
14
+ var MockXMLHttpRequest = function() {
15
+ this.requestHeaders = {}
16
+ }
57
17
 
58
- getAllResponseHeaders : function(){
59
- return this.responseHeaders
60
- },
18
+ MockXMLHttpRequest.prototype = {
19
+ status : 0,
20
+ async : true,
21
+ readyState : 0,
22
+ responseText : '',
23
+ abort : function(){},
24
+ onreadystatechange : function(){},
25
+
26
+ /**
27
+ * Return response headers hash.
28
+ */
29
+
30
+ getAllResponseHeaders : function(){
31
+ return this.responseHeaders
32
+ },
33
+
34
+ /**
35
+ * Return case-insensitive value for header _name_.
36
+ */
37
+
38
+ getResponseHeader : function(name) {
39
+ return this.responseHeaders[name.toLowerCase()]
40
+ },
41
+
42
+ /**
43
+ * Set case-insensitive _value_ for header _name_.
44
+ */
45
+
46
+ setRequestHeader : function(name, value) {
47
+ this.requestHeaders[name.toLowerCase()] = value
48
+ },
49
+
50
+ /**
51
+ * Open mock request.
52
+ */
53
+
54
+ open : function(method, url, async, user, password) {
55
+ this.user = user
56
+ this.password = password
57
+ this.url = url
58
+ this.readyState = 1
59
+ this.method = method.toUpperCase()
60
+ if (async != undefined) this.async = async
61
+ if (this.async) this.onreadystatechange()
62
+ },
63
+
64
+ /**
65
+ * Send request _data_.
66
+ */
67
+
68
+ send : function(data) {
69
+ this.data = data
70
+ this.readyState = 4
71
+ if (this.method == 'HEAD') this.responseText = null
72
+ this.responseHeaders['content-length'] = (this.responseText || '').length
73
+ if(this.async) this.onreadystatechange()
74
+ }
75
+ }
61
76
 
62
- getResponseHeader : function(name) {
63
- return this.responseHeaders[name.toLowerCase()]
64
- },
77
+ // --- Response status codes
65
78
 
66
- setRequestHeader : function(name, value) {
67
- this.requestHeaders[name.toLowerCase()] = value
68
- },
79
+ JSpec.statusCodes = {
80
+ 100 : 'Continue',
81
+ 101 : 'Switching Protocols',
82
+ 200 : 'OK',
83
+ 201 : 'Created',
84
+ 202 : 'Accepted',
85
+ 203 : 'Non-Authoritative Information',
86
+ 204 : 'No Content',
87
+ 205 : 'Reset Content',
88
+ 206 : 'Partial Content',
89
+ 300 : 'Multiple Choice',
90
+ 301 : 'Moved Permanently',
91
+ 302 : 'Found',
92
+ 303 : 'See Other',
93
+ 304 : 'Not Modified',
94
+ 305 : 'Use Proxy',
95
+ 307 : 'Temporary Redirect',
96
+ 400 : 'Bad Request',
97
+ 401 : 'Unauthorized',
98
+ 402 : 'Payment Required',
99
+ 403 : 'Forbidden',
100
+ 404 : 'Not Found',
101
+ 405 : 'Method Not Allowed',
102
+ 406 : 'Not Acceptable',
103
+ 407 : 'Proxy Authentication Required',
104
+ 408 : 'Request Timeout',
105
+ 409 : 'Conflict',
106
+ 410 : 'Gone',
107
+ 411 : 'Length Required',
108
+ 412 : 'Precondition Failed',
109
+ 413 : 'Request Entity Too Large',
110
+ 414 : 'Request-URI Too Long',
111
+ 415 : 'Unsupported Media Type',
112
+ 416 : 'Requested Range Not Satisfiable',
113
+ 417 : 'Expectation Failed',
114
+ 422 : 'Unprocessable Entity',
115
+ 500 : 'Internal Server Error',
116
+ 501 : 'Not Implemented',
117
+ 502 : 'Bad Gateway',
118
+ 503 : 'Service Unavailable',
119
+ 504 : 'Gateway Timeout',
120
+ 505 : 'HTTP Version Not Supported'
121
+ }
69
122
 
70
- open : function(method, url, async, user, password) {
71
- this.user = user
72
- this.password = password
73
- this.url = url
74
- this.readyState = 1
75
- this.method = method.toUpperCase()
76
- if (async != undefined) this.async = async
77
- if (this.async) this.onreadystatechange()
78
- },
123
+ /**
124
+ * Mock XMLHttpRequest requests.
125
+ *
126
+ * mockRequest().and_return('some data', 'text/plain', 200, { 'X-SomeHeader' : 'somevalue' })
127
+ *
128
+ * @return {hash}
129
+ * @api public
130
+ */
79
131
 
80
- send : function(data) {
81
- this.data = data
82
- this.readyState = 4
83
- if (this.method == 'HEAD') this.body = null
84
- this.responseHeaders['content-length'] = (this.responseText || '').length
85
- if(this.async) this.onreadystatechange()
132
+ function mockRequest() {
133
+ return { and_return : function(body, type, status, headers) {
134
+ XMLHttpRequest = MockXMLHttpRequest
135
+ status = status || 200
136
+ headers = headers || {}
137
+ headers['content-type'] = type
138
+ JSpec.extend(XMLHttpRequest.prototype, {
139
+ responseText : body,
140
+ responseHeaders : headers,
141
+ status : status,
142
+ statusText : JSpec.statusCodes[status]
143
+ })
144
+ }}
86
145
  }
87
- }
88
-
89
- function unmockRequest() {
90
- XMLHttpRequest = JSpec.defaultXMLHttpRequest
91
- }
92
-
93
- JSpec.include({
146
+
147
+ /**
148
+ * Unmock XMLHttpRequest requests.
149
+ *
150
+ * @api public
151
+ */
152
+
153
+ function unmockRequest() {
154
+ XMLHttpRequest = OriginalXMLHttpRequest
155
+ }
156
+
157
+ JSpec.include({
94
158
 
95
- // --- Utilities
159
+ // --- Utilities
96
160
 
97
- utilities : {
98
- mockRequest : function(){
99
- return { and_return : function(body, type, status, headers) {
100
- XMLHttpRequest = JSpec.XMLHttpRequest
101
- status = status || 200
102
- headers = headers || {}
103
- headers['content-type'] = type
104
- JSpec.extend(XMLHttpRequest.prototype, {
105
- responseText : body,
106
- responseHeaders : headers,
107
- status : status,
108
- statusText : XMLHttpRequest.status[status]
109
- })
110
- }}
161
+ utilities : {
162
+ mockRequest : mockRequest,
163
+ unmockRequest : unmockRequest
111
164
  },
112
- unmockRequest : unmockRequest
113
- },
114
165
 
115
- // --- Hooks
166
+ // --- Hooks
116
167
 
117
- afterSpec : function() {
118
- unmockRequest()
119
- }
168
+ afterSpec : function() {
169
+ this.utilities.unmockRequest()
170
+ }
120
171
 
121
- })
172
+ })
173
+ })()
@@ -1,5 +1,6 @@
1
1
 
2
2
  ExampleModule = {
3
+ name : 'ExampleModule',
3
4
  utilities : {
4
5
  doFoo : function(){ return 'foo' },
5
6
  doBar : function(){ return 'bar' }
@@ -7,13 +8,14 @@ ExampleModule = {
7
8
  randomHook : function(a, b) {
8
9
  return [a, b]
9
10
  },
10
- beforeSpec : function() { addedBeforeSpec = true, addedBeforeSpecHook = false },
11
- afterSpec : function() { addedAfterSpec = true, addedAfterSpecHook = false },
12
- beforeSuite : function() { addedBeforeSuite = true },
13
- afterSuite : function() {
14
- addedAfterSuite = true
15
- addedBeforeSuite = addedBeforeSpec = addedAfterSpec = false
16
- },
11
+ beforeSpec : function() { addedBeforeSpec = true; doFoo() },
12
+ afterSpec : function() { addedAfterSpec = true },
13
+ beforeSuite : function() { addedBeforeSuite = true },
14
+ afterSuite : function() { addedAfterSuite = true },
15
+ checkJSpecContext : function(){ return each },
16
+ checkContext : function() { return fixture('test') },
17
+ checkModuleContext : function() { return this.name },
18
+ checkUtilityContext : function() { return doFoo() },
17
19
  matchers : {
18
20
  be_foo_bar : function() {
19
21
  return true
@@ -14,6 +14,7 @@
14
14
  .exec('spec.js')
15
15
  .exec('spec.matchers.js')
16
16
  .exec('spec.utils.js')
17
+ .exec('spec.fixtures.js')
17
18
  .exec('spec.shared-behaviors.js')
18
19
  .exec('spec.jquery.js')
19
20
  .exec('spec.modules.js')
@@ -0,0 +1,18 @@
1
+
2
+ describe 'Utility'
3
+ describe 'fixture()'
4
+ it 'should return a files contents'
5
+ fixture('fixtures/test.html').should.eql '<p>test</p>'
6
+ fixture('test.html').should.eql '<p>test</p>'
7
+ fixture('test').should.eql '<p>test</p>'
8
+ end
9
+
10
+ it 'should cache contents'
11
+ contents = fixture('test')
12
+ JSpec.cache['test'].should.eql contents
13
+ JSpec.cache['test'] = 'foo'
14
+ fixture('test').should.eql 'foo'
15
+ delete JSpec.cache['test']
16
+ end
17
+ end
18
+ end
@@ -2,41 +2,38 @@
2
2
  describe 'JSpec'
3
3
  describe 'module'
4
4
  describe 'hooks'
5
- before_each
6
- addedBeforeSpecHook = true
5
+ it 'should run beforeSpec'
6
+ addedBeforeSpec.should.be_true
7
7
  end
8
8
 
9
- after_each
10
- addedAfterSpecHook = true
9
+ it 'should run afterSpec'
10
+ addedAfterSpec.should.be_true
11
11
  end
12
12
 
13
- it 'should run in context with beforeSpec'
14
- addedBeforeSpec.should.be_true
15
- addedAfterSpec.should.be_false
16
- addedAfterSpecHook.should.be_false
13
+ describe 'with suites'
14
+ it 'should run beforeSuite'
15
+ addedBeforeSuite.should.be_true
16
+ end
17
17
  end
18
18
 
19
- it 'should run beforeSpec BEFORE the before_each blocks'
20
- addedBeforeSpecHook.should.be_true
19
+ it 'should run afterSuite'
20
+ addedAfterSuite.should.be_true
21
21
  end
22
-
23
- it 'should run in context with afterSpec'
24
- addedBeforeSpec.should.be_true
25
- addedAfterSpec.should.be_true
22
+
23
+ it 'should run in context with JSpec'
24
+ hook('checkJSpecContext')[0].should.equal JSpec.each
26
25
  end
27
26
 
28
- it 'should run afterSpec BEFORE after_each blocks'
29
- addedAfterSpecHook.should.be_true
27
+ it 'should run in context to JSpecs default context'
28
+ hook('checkContext')[0].should.eql fixture('test')
30
29
  end
31
-
32
- it 'should run in context with beforeSuite'
33
- addedBeforeSuite.should.be_true
30
+
31
+ it 'should run in context to the module itself'
32
+ hook('checkModuleContext')[0].should.eql 'ExampleModule'
34
33
  end
35
-
36
- describe 'another suite'
37
- it 'should run in context with afterSuite'
38
- addedAfterSuite.should.be_true
39
- end
34
+
35
+ it 'should run in context to the modules utilities'
36
+ hook('checkUtilityContext')[0].should.eql 'foo'
40
37
  end
41
38
  end
42
39
 
@@ -2,6 +2,9 @@
2
2
  __loading__ = []
3
3
  __loadDelay__ = 1000
4
4
 
5
+ originalPrint = print
6
+ print = puts
7
+
5
8
  readFile = function(path, callback) {
6
9
  __loading__.push(path)
7
10
  var promise = node.fs.cat(path, "utf8")
@@ -33,9 +36,8 @@ setTimeout(function(){
33
36
  .exec('spec/spec.matchers.js')
34
37
  .exec('spec/spec.utils.js')
35
38
  .exec('spec/spec.shared-behaviors.js')
36
- .exec('spec/spec.modules.js')
37
39
  setTimeout(function(){
38
- JSpec.run({ formatter : JSpec.formatters.Terminal, failuresOnly : true })
40
+ JSpec.run({ formatter : JSpec.formatters.Terminal, failuresOnly : false })
39
41
  setTimeout(function() {
40
42
  JSpec.report()
41
43
  }, __loadDelay__ / 3)
@@ -9,6 +9,7 @@ JSpec
9
9
  .exec('spec/spec.js')
10
10
  .exec('spec/spec.matchers.js')
11
11
  .exec('spec/spec.utils.js')
12
+ .exec('spec/spec.fixtures.js')
12
13
  .exec('spec/spec.shared-behaviors.js')
13
14
  .exec('spec/spec.modules.js')
14
15
  .exec('spec/spec.xhr.js')
@@ -13,6 +13,7 @@
13
13
  .exec('spec.js')
14
14
  .exec('spec.matchers.js')
15
15
  .exec('spec.utils.js')
16
+ .exec('spec.fixtures.js')
16
17
  .exec('spec.shared-behaviors.js')
17
18
  .exec('spec.jquery.js')
18
19
  .exec('spec.modules.js')
@@ -256,19 +256,21 @@ describe 'Utility'
256
256
  end
257
257
  end
258
258
 
259
- describe 'fixture()'
260
- it 'should return a files contents'
261
- fixture('fixtures/test.html').should.eql '<p>test</p>'
262
- fixture('test.html').should.eql '<p>test</p>'
263
- fixture('test').should.eql '<p>test</p>'
259
+ describe 'paramsFor()'
260
+ it 'should return an array of function parameter names'
261
+ JSpec.paramsFor(function(foo, bar){}).should.eql ['foo', 'bar']
264
262
  end
265
263
 
266
- it 'should cache contents'
267
- contents = fixture('test')
268
- JSpec.cache['test'].should.eql contents
269
- JSpec.cache['test'] = 'foo'
270
- fixture('test').should.eql 'foo'
271
- delete JSpec.cache['test']
264
+ it 'should return only the params for the root function'
265
+ foo = function(bar){
266
+ function baz(test) {}
267
+ var something = function(foo, bar){}
268
+ }
269
+ JSpec.paramsFor(foo).should.eql ['bar']
270
+ end
271
+
272
+ it 'should return empty array when no params are present'
273
+ JSpec.paramsFor(function(){}).should.eql []
272
274
  end
273
275
  end
274
276
  end
@@ -1,15 +1,24 @@
1
1
 
2
2
  describe 'JSpec'
3
3
  describe '.mockRequest'
4
+ before
5
+ responseFrom = function(path) {
6
+ request = new XMLHttpRequest
7
+ request.open('POST', path, false)
8
+ request.send(null)
9
+ return request.responseText
10
+ }
11
+ end
12
+
4
13
  it 'should mock XMLHttpRequests if unmockRequest() is called or the spec block has finished'
14
+ original = XMLHttpRequest
5
15
  mockRequest().and_return('test')
6
- XMLHttpRequest.should.eql JSpec.XMLHttpRequest
16
+ XMLHttpRequest.should.not.equal original
7
17
  unmockRequest()
8
- XMLHttpRequest.should.not.eql JSpec.XMLHttpRequest
18
+ XMLHttpRequest.should.equal original
9
19
  end
10
20
 
11
21
  it 'should restore original XMLHttpRequest constructor after each spec'
12
- XMLHttpRequest.should.eql JSpec.defaultXMLHttpRequest
13
22
  XMLHttpRequest.should.not.eql JSpec.XMLHttpRequest
14
23
  end
15
24
 
@@ -21,7 +30,7 @@ describe 'JSpec'
21
30
  request.send('foo=bar')
22
31
  end
23
32
 
24
- it 'should allow setting respose status'
33
+ it 'should allow setting response status'
25
34
  mockRequest().and_return('bar', 'text/plain', 404)
26
35
  request = new XMLHttpRequest
27
36
  request.open('GET', 'path', false)
@@ -127,7 +136,14 @@ describe 'JSpec'
127
136
  mockRequest().and_return('bar', 'text/plain', 200)
128
137
  request.open('HEAD', 'path', false)
129
138
  request.send(null)
130
- request.body.should.be_null
139
+ request.responseText.should.be_null
140
+ end
141
+ end
142
+
143
+ describe 'with uri'
144
+ it 'should mock only the uri specified'
145
+ mockRequest('ilike').and_return('cookies')
146
+ responseFrom('async').should.eql 'cookies'
131
147
  end
132
148
  end
133
149
  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.8.2
4
+ version: 2.8.3
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-29 00:00:00 -07:00
12
+ date: 2009-07-30 00:00:00 -07:00
13
13
  default_executable: jspec
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,7 @@ files:
77
77
  - spec/fixtures/test.xml
78
78
  - spec/modules.js
79
79
  - spec/spec.dom.html
80
+ - spec/spec.fixtures.js
80
81
  - spec/spec.grammar-less.js
81
82
  - spec/spec.grammar.js
82
83
  - spec/spec.jquery.js