visionmedia-jspec 2.8.1 → 2.8.2

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.
@@ -1,4 +1,10 @@
1
1
 
2
+ === 2.8.2 / 2009-07-29
3
+
4
+ * Added JSpec.tryLoading()
5
+ * Added JSpec.request used to reference the original XMLHttpRequest; used to fix [#149]
6
+ * Fixed Mock XHR issue messing up JSpec request related utilities such as fixture() [#149]
7
+
2
8
  === 2.8.1 / 2009-07-27
3
9
 
4
10
  * Added Lawrence Pit as a contributor
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.1'
14
+ program :version, '2.8.2'
15
15
  program :description, 'JavaScript BDD Testing Framework'
16
16
  default_command :bind
17
17
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{jspec}
5
- s.version = "2.8.1"
5
+ s.version = "2.8.2"
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-27}
9
+ s.date = %q{2009-07-29}
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}
@@ -5,13 +5,14 @@
5
5
 
6
6
  JSpec = {
7
7
 
8
- version : '2.8.1',
8
+ version : '2.8.2',
9
9
  cache : {},
10
10
  suites : [],
11
11
  modules : [],
12
12
  allSuites : [],
13
13
  matchers : {},
14
14
  stubbed : [],
15
+ request : 'XMLHttpRequest' in this ? XMLHttpRequest : null,
15
16
  stats : { specs : 0, assertions : 0, failures : 0, passes : 0, specsFinished : 0, suitesFinished : 0 },
16
17
  options : { profile : false },
17
18
 
@@ -67,17 +68,13 @@
67
68
 
68
69
  fixture : function(path) {
69
70
  if (JSpec.cache[path]) return JSpec.cache[path]
70
- function tryLoading(path) {
71
- try { return JSpec.load(path) }
72
- catch (e) {}
73
- }
74
71
  return JSpec.cache[path] =
75
- tryLoading(path) ||
76
- tryLoading('fixtures/' + path) ||
77
- tryLoading('fixtures/' + path + '.html') ||
78
- tryLoading('spec/' + path) ||
79
- tryLoading('spec/fixtures/' + path) ||
80
- tryLoading('spec/fixtures/' + path + '.html')
72
+ JSpec.tryLoading(path) ||
73
+ JSpec.tryLoading('fixtures/' + path) ||
74
+ JSpec.tryLoading('fixtures/' + path + '.html') ||
75
+ JSpec.tryLoading('spec/' + path) ||
76
+ JSpec.tryLoading('spec/fixtures/' + path) ||
77
+ JSpec.tryLoading('spec/fixtures/' + path + '.html')
81
78
  }
82
79
  },
83
80
 
@@ -1466,14 +1463,12 @@
1466
1463
  /**
1467
1464
  * Instantiate an XMLHttpRequest.
1468
1465
  *
1469
- * @return {ActiveXObject, XMLHttpRequest}
1466
+ * @return {XMLHttpRequest, ActiveXObject}
1470
1467
  * @api private
1471
1468
  */
1472
1469
 
1473
1470
  xhr : function() {
1474
- return 'XMLHttpRequest' in main ?
1475
- new XMLHttpRequest:
1476
- new ActiveXObject("Microsoft.XMLHTTP")
1471
+ return new (JSpec.request || ActiveXObject("Microsoft.XMLHTTP"))
1477
1472
  },
1478
1473
 
1479
1474
  /**
@@ -1484,7 +1479,21 @@
1484
1479
  */
1485
1480
 
1486
1481
  hasXhr : function() {
1487
- return 'XMLHttpRequest' in main || 'ActiveXObject' in main
1482
+ return JSpec.request || 'ActiveXObject' in main
1483
+ },
1484
+
1485
+ /**
1486
+ * Try loading _file_ returning the contents
1487
+ * string or null. Chain to locate / read a file.
1488
+ *
1489
+ * @param {string} file
1490
+ * @return {string}
1491
+ * @api public
1492
+ */
1493
+
1494
+ tryLoading : function(file) {
1495
+ try { return JSpec.load(file) }
1496
+ catch (e) {}
1488
1497
  },
1489
1498
 
1490
1499
  /**
@@ -9,6 +9,13 @@ describe 'jQuery'
9
9
  })
10
10
  end
11
11
 
12
+ it 'should work with a json fixture'
13
+ mockRequest().and_return(fixture('test.json'))
14
+ $.getJSON('foo', function(response){
15
+ response.users.tj.email.should.eql 'tj@vision-media.ca'
16
+ })
17
+ end
18
+
12
19
  it 'should not invoke callback when response status is 4xx'
13
20
  mockRequest().and_return('foo', 'text/plain', 404)
14
21
  $.getJSON('foo', function(){
@@ -268,6 +268,7 @@ describe 'Utility'
268
268
  JSpec.cache['test'].should.eql contents
269
269
  JSpec.cache['test'] = 'foo'
270
270
  fixture('test').should.eql 'foo'
271
+ delete JSpec.cache['test']
271
272
  end
272
273
  end
273
274
  end
@@ -16,14 +16,14 @@ describe 'JSpec'
16
16
  describe 'mock response'
17
17
  before_each
18
18
  mockRequest().and_return('bar', 'text/plain', 200, { 'x-foo' : 'bar' })
19
- request = JSpec.xhr()
19
+ request = new XMLHttpRequest
20
20
  request.open('GET', 'path', false, 'foo', 'bar')
21
21
  request.send('foo=bar')
22
22
  end
23
23
 
24
24
  it 'should allow setting respose status'
25
25
  mockRequest().and_return('bar', 'text/plain', 404)
26
- request = JSpec.xhr()
26
+ request = new XMLHttpRequest
27
27
  request.open('GET', 'path', false)
28
28
  request.send(null)
29
29
  request.status.should.eql 404
@@ -31,7 +31,7 @@ describe 'JSpec'
31
31
  end
32
32
 
33
33
  it 'should default readyState to 0'
34
- request = JSpec.xhr()
34
+ request = new XMLHttpRequest
35
35
  request.readyState.should.eql 0
36
36
  end
37
37
 
@@ -83,10 +83,17 @@ describe 'JSpec'
83
83
  request.getResponseHeader('X-Foo').should.eql 'bar'
84
84
  end
85
85
 
86
+ it 'should not interrupt JSpec request related functionality'
87
+ mockRequest().and_return('fail')
88
+ (JSpec.tryLoading('async') || JSpec.tryLoading('spec/async')).should.eql 'cookies!'
89
+ fixture('test').should.eql '<p>test</p>'
90
+ fixture('test.json').should.include '{ user'
91
+ end
92
+
86
93
  describe '.onreadystatechange()'
87
94
  before_each
88
95
  mockRequest().and_return('bar', 'text/plain', 200)
89
- request = JSpec.xhr()
96
+ request = new XMLHttpRequest
90
97
  end
91
98
 
92
99
  it 'should be called when opening request in context to the request'
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.1
4
+ version: 2.8.2
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-27 00:00:00 -07:00
12
+ date: 2009-07-29 00:00:00 -07:00
13
13
  default_executable: jspec
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency