jspec 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +9 -0
- data/README.md +11 -5
- data/bin/jspec +1 -1
- data/jspec.gemspec +2 -2
- data/lib/jspec.jquery.js +10 -3
- data/lib/jspec.js +36 -12
- data/lib/jspec.xhr.js +34 -21
- data/spec/unit/spec.jquery.js +16 -0
- metadata +3 -3
data/History.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
|
2
|
+
4.2.0 / 2010-04-07
|
3
|
+
==================
|
4
|
+
|
5
|
+
* Merge branch 'master' of git://github.com/vipulb/jspec into xml
|
6
|
+
* Added support for mock requests to parse xml
|
7
|
+
* Added have_event_handlers matcher
|
8
|
+
* Adding be_animated matcher
|
9
|
+
* Add option "disableColors" to disable coloring in terminal reporter
|
10
|
+
|
2
11
|
4.1.0 / 2010-03-25
|
3
12
|
==================
|
4
13
|
|
data/README.md
CHANGED
@@ -238,12 +238,14 @@ The following options may be passed to _JSpec.run()_.
|
|
238
238
|
- have_value
|
239
239
|
- have_class
|
240
240
|
- have_classes
|
241
|
+
- have_event_handlers
|
241
242
|
- be_visible
|
242
243
|
- be_hidden
|
243
244
|
- be_enabled
|
244
245
|
- be_disabled
|
245
246
|
- be_selected
|
246
247
|
- be_checked
|
248
|
+
- be_animated
|
247
249
|
|
248
250
|
## Growl Support
|
249
251
|
|
@@ -327,7 +329,7 @@ To destub a method simply call `destub()` at any time:
|
|
327
329
|
|
328
330
|
destub(person, 'toString')
|
329
331
|
|
330
|
-
If you would like to
|
332
|
+
If you would like to wipe an object clear of stubs simply pass it
|
331
333
|
to `destub()` without an additional method argument:
|
332
334
|
|
333
335
|
destub(person)
|
@@ -460,7 +462,11 @@ The mock_request().and_return signature is as follows:
|
|
460
462
|
mock_request().and_return(<data>, [content-type], [response-status-code], [headers-hash])
|
461
463
|
|
462
464
|
At the moment `mock_request()` itself does not accept any arguments, however in the future
|
463
|
-
this will be used to target specific
|
465
|
+
this will be used to target specific URIs for mocking.
|
466
|
+
|
467
|
+
Also, if the content-type of response is specified as XML, as specified in the XMLHttpRequest
|
468
|
+
draft specification at : http://www.w3.org/TR/XMLHttpRequest/, the responseXML attribute of the response
|
469
|
+
will be an XML document generated by parsing the response body.
|
464
470
|
|
465
471
|
**NOTE**: works with Rhino as well
|
466
472
|
|
@@ -519,7 +525,7 @@ requests to sync, which preserves execution order, and reports correctly.
|
|
519
525
|
})
|
520
526
|
end
|
521
527
|
|
522
|
-
##
|
528
|
+
## Grammar Pre-processor
|
523
529
|
|
524
530
|
The pre-processing capability of JSpec is extremely powerful. Your JavaScript
|
525
531
|
code is not necessarily what it seems. For example when you seemingly invoke a
|
@@ -563,7 +569,7 @@ Any text placed after **__END__** is considered irrelevant and
|
|
563
569
|
is striped out before evaluation. This is sometimes useful for
|
564
570
|
document or code reference while writing specs.
|
565
571
|
|
566
|
-
For example when
|
572
|
+
For example when writing regression specs it is sometimes useful
|
567
573
|
to paste the issue ticket's comment(s) below this area for reference.
|
568
574
|
|
569
575
|
## Formatters
|
@@ -987,7 +993,7 @@ your _spec/server.rb_ file may support additional browsers.
|
|
987
993
|
## Contributors
|
988
994
|
|
989
995
|
Many ideas and bug reports were contributed by
|
990
|
-
the following developers,
|
996
|
+
the following developers, thank you for making
|
991
997
|
JSpec more enjoyable, and bug free. If I have
|
992
998
|
missed you on this list please let me know
|
993
999
|
(aka the fellow who donated [jspec.info](http://jspec.info))
|
data/bin/jspec
CHANGED
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 = "4.
|
5
|
+
s.version = "4.2.0"
|
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{2010-
|
9
|
+
s.date = %q{2010-04-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}
|
data/lib/jspec.jquery.js
CHANGED
@@ -24,7 +24,7 @@ JSpec
|
|
24
24
|
|
25
25
|
// --- Matchers
|
26
26
|
|
27
|
-
matchers : {
|
27
|
+
matchers : {
|
28
28
|
have_tag : "jQuery(expected, actual).length === 1",
|
29
29
|
have_one : "alias have_tag",
|
30
30
|
have_tags : "jQuery(expected, actual).length > 1",
|
@@ -36,7 +36,8 @@ JSpec
|
|
36
36
|
have_value : "jQuery(actual).val() === expected",
|
37
37
|
be_enabled : "!jQuery(actual).attr('disabled')",
|
38
38
|
have_class : "jQuery(actual).hasClass(expected)",
|
39
|
-
|
39
|
+
be_animated : "jQuery(actual).queue().length > 0",
|
40
|
+
|
40
41
|
be_visible : function(actual) {
|
41
42
|
return jQuery(actual).css('display') != 'none' &&
|
42
43
|
jQuery(actual).css('visibility') != 'hidden' &&
|
@@ -46,7 +47,7 @@ JSpec
|
|
46
47
|
be_hidden : function(actual) {
|
47
48
|
return !JSpec.does(actual, 'be_visible')
|
48
49
|
},
|
49
|
-
|
50
|
+
|
50
51
|
have_classes : function(actual) {
|
51
52
|
return !JSpec.any(JSpec.toArray(arguments, 1), function(arg){
|
52
53
|
return !JSpec.does(actual, 'have_class', arg)
|
@@ -58,6 +59,12 @@ JSpec
|
|
58
59
|
jQuery(actual).attr(attr)
|
59
60
|
},
|
60
61
|
|
62
|
+
have_event_handlers : function(actual, expected) {
|
63
|
+
return jQuery(actual).data('events') ?
|
64
|
+
jQuery(actual).data('events').hasOwnProperty(expected) :
|
65
|
+
false
|
66
|
+
},
|
67
|
+
|
61
68
|
'be disabled selected checked' : function(attr) {
|
62
69
|
return 'jQuery(actual).attr("' + attr + '")'
|
63
70
|
},
|
data/lib/jspec.js
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
;(function(){
|
5
5
|
|
6
6
|
JSpec = {
|
7
|
-
version : '4.
|
7
|
+
version : '4.2.0',
|
8
8
|
assert : true,
|
9
9
|
cache : {},
|
10
10
|
suites : [],
|
@@ -894,17 +894,21 @@
|
|
894
894
|
*/
|
895
895
|
|
896
896
|
color : function(string, color) {
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
897
|
+
if (option('disableColors')) {
|
898
|
+
return string
|
899
|
+
} else {
|
900
|
+
return "\u001B[" + {
|
901
|
+
bold : 1,
|
902
|
+
black : 30,
|
903
|
+
red : 31,
|
904
|
+
green : 32,
|
905
|
+
yellow : 33,
|
906
|
+
blue : 34,
|
907
|
+
magenta : 35,
|
908
|
+
cyan : 36,
|
909
|
+
white : 37
|
910
|
+
}[color] + 'm' + string + "\u001B[0m"
|
911
|
+
}
|
908
912
|
},
|
909
913
|
|
910
914
|
/**
|
@@ -1070,6 +1074,26 @@
|
|
1070
1074
|
}
|
1071
1075
|
},
|
1072
1076
|
|
1077
|
+
/**
|
1078
|
+
* Parse an XML String and return a 'document'.
|
1079
|
+
*
|
1080
|
+
* @param {string} text
|
1081
|
+
* @return {document}
|
1082
|
+
* @api public
|
1083
|
+
*/
|
1084
|
+
|
1085
|
+
parseXML : function(text) {
|
1086
|
+
var xmlDoc
|
1087
|
+
if (window.DOMParser)
|
1088
|
+
xmlDoc = (new DOMParser()).parseFromString(text, "text/xml")
|
1089
|
+
else {
|
1090
|
+
xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
|
1091
|
+
xmlDoc.async = "false"
|
1092
|
+
xmlDoc.loadXML(text)
|
1093
|
+
}
|
1094
|
+
return xmlDoc
|
1095
|
+
},
|
1096
|
+
|
1073
1097
|
/**
|
1074
1098
|
* Escape HTML.
|
1075
1099
|
*
|
data/lib/jspec.xhr.js
CHANGED
@@ -2,28 +2,29 @@
|
|
2
2
|
// JSpec - XHR - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
3
3
|
|
4
4
|
(function(){
|
5
|
-
|
5
|
+
|
6
6
|
var lastRequest
|
7
|
-
|
7
|
+
|
8
8
|
// --- Original XMLHttpRequest
|
9
|
-
|
10
|
-
var OriginalXMLHttpRequest = 'XMLHttpRequest' in this ?
|
9
|
+
|
10
|
+
var OriginalXMLHttpRequest = 'XMLHttpRequest' in this ?
|
11
11
|
XMLHttpRequest :
|
12
12
|
function(){}
|
13
13
|
var OriginalActiveXObject = 'ActiveXObject' in this ?
|
14
14
|
ActiveXObject :
|
15
15
|
undefined
|
16
|
-
|
16
|
+
|
17
17
|
// --- MockXMLHttpRequest
|
18
18
|
|
19
19
|
var MockXMLHttpRequest = function() {
|
20
20
|
this.requestHeaders = {}
|
21
21
|
}
|
22
|
-
|
22
|
+
|
23
23
|
MockXMLHttpRequest.prototype = {
|
24
24
|
status: 0,
|
25
25
|
async: true,
|
26
26
|
readyState: 0,
|
27
|
+
responseXML: null,
|
27
28
|
responseText: '',
|
28
29
|
abort: function(){},
|
29
30
|
onreadystatechange: function(){},
|
@@ -35,7 +36,7 @@
|
|
35
36
|
getAllResponseHeaders : function(){
|
36
37
|
return this.responseHeaders
|
37
38
|
},
|
38
|
-
|
39
|
+
|
39
40
|
/**
|
40
41
|
* Return case-insensitive value for header _name_.
|
41
42
|
*/
|
@@ -43,7 +44,7 @@
|
|
43
44
|
getResponseHeader : function(name) {
|
44
45
|
return this.responseHeaders[name.toLowerCase()]
|
45
46
|
},
|
46
|
-
|
47
|
+
|
47
48
|
/**
|
48
49
|
* Set case-insensitive _value_ for header _name_.
|
49
50
|
*/
|
@@ -51,7 +52,7 @@
|
|
51
52
|
setRequestHeader : function(name, value) {
|
52
53
|
this.requestHeaders[name.toLowerCase()] = value
|
53
54
|
},
|
54
|
-
|
55
|
+
|
55
56
|
/**
|
56
57
|
* Open mock request.
|
57
58
|
*/
|
@@ -65,7 +66,7 @@
|
|
65
66
|
if (async != undefined) this.async = async
|
66
67
|
if (this.async) this.onreadystatechange()
|
67
68
|
},
|
68
|
-
|
69
|
+
|
69
70
|
/**
|
70
71
|
* Send request _data_.
|
71
72
|
*/
|
@@ -77,14 +78,26 @@
|
|
77
78
|
if (this.method == 'HEAD') this.responseText = null
|
78
79
|
this.responseHeaders['content-length'] = (this.responseText || '').length
|
79
80
|
if(this.async) this.onreadystatechange()
|
81
|
+
this.populateResponseXML()
|
80
82
|
lastRequest = function(){
|
81
83
|
return self
|
82
84
|
}
|
83
|
-
}
|
85
|
+
},
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Parse request body and populate responseXML if response-type is xml
|
89
|
+
* Based on the standard specification : http://www.w3.org/TR/XMLHttpRequest/
|
90
|
+
*/
|
91
|
+
populateResponseXML: function() {
|
92
|
+
var type = this.getResponseHeader("content-type")
|
93
|
+
if (!type || !this.responseText || !type.match(/(text\/xml|application\/xml|\+xml$)/g))
|
94
|
+
return
|
95
|
+
this.responseXML = JSpec.parseXML(this.responseText)
|
96
|
+
}
|
84
97
|
}
|
85
|
-
|
98
|
+
|
86
99
|
// --- Response status codes
|
87
|
-
|
100
|
+
|
88
101
|
JSpec.statusCodes = {
|
89
102
|
100: 'Continue',
|
90
103
|
101: 'Switching Protocols',
|
@@ -128,7 +141,7 @@
|
|
128
141
|
504: 'Gateway Timeout',
|
129
142
|
505: 'HTTP Version Not Supported'
|
130
143
|
}
|
131
|
-
|
144
|
+
|
132
145
|
/**
|
133
146
|
* Mock XMLHttpRequest requests.
|
134
147
|
*
|
@@ -137,7 +150,7 @@
|
|
137
150
|
* @return {hash}
|
138
151
|
* @api public
|
139
152
|
*/
|
140
|
-
|
153
|
+
|
141
154
|
function mockRequest() {
|
142
155
|
return { and_return : function(body, type, status, headers) {
|
143
156
|
XMLHttpRequest = MockXMLHttpRequest
|
@@ -153,18 +166,18 @@
|
|
153
166
|
})
|
154
167
|
}}
|
155
168
|
}
|
156
|
-
|
169
|
+
|
157
170
|
/**
|
158
171
|
* Unmock XMLHttpRequest requests.
|
159
172
|
*
|
160
173
|
* @api public
|
161
174
|
*/
|
162
|
-
|
175
|
+
|
163
176
|
function unmockRequest() {
|
164
177
|
XMLHttpRequest = OriginalXMLHttpRequest
|
165
178
|
ActiveXObject = OriginalActiveXObject
|
166
179
|
}
|
167
|
-
|
180
|
+
|
168
181
|
JSpec.include({
|
169
182
|
name: 'Mock XHR',
|
170
183
|
|
@@ -180,9 +193,9 @@
|
|
180
193
|
afterSpec : function() {
|
181
194
|
unmockRequest()
|
182
195
|
},
|
183
|
-
|
196
|
+
|
184
197
|
// --- DSLs
|
185
|
-
|
198
|
+
|
186
199
|
DSLs : {
|
187
200
|
snake : {
|
188
201
|
mock_request: mockRequest,
|
@@ -192,4 +205,4 @@
|
|
192
205
|
}
|
193
206
|
|
194
207
|
})
|
195
|
-
})()
|
208
|
+
})()
|
data/spec/unit/spec.jquery.js
CHANGED
@@ -113,6 +113,14 @@ describe 'jQuery'
|
|
113
113
|
$('select', elem).should.not.have_classes 'foo', 'save'
|
114
114
|
end
|
115
115
|
end
|
116
|
+
|
117
|
+
describe 'have_event_handlers'
|
118
|
+
it 'should check if an element has handlers for a given event'
|
119
|
+
elem.should.not.have_event_handlers 'click'
|
120
|
+
elem.bind('click', function(){})
|
121
|
+
elem.should.have_event_handlers 'click'
|
122
|
+
end
|
123
|
+
end
|
116
124
|
|
117
125
|
describe 'be_visible'
|
118
126
|
it 'should check that an element is not hidden or set to display of none'
|
@@ -139,6 +147,14 @@ describe 'jQuery'
|
|
139
147
|
end
|
140
148
|
end
|
141
149
|
|
150
|
+
describe 'be_animated'
|
151
|
+
it 'should check if an element is currently animated'
|
152
|
+
elem.should.not.be_animated
|
153
|
+
elem.fadeIn(1000)
|
154
|
+
elem.should.be_animated
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
142
158
|
describe 'have_ATTR'
|
143
159
|
it 'should check if an attribute exists'
|
144
160
|
'<input type="checkbox"/>'.should.have_type
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 4
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 4.
|
9
|
+
version: 4.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- TJ Holowaychuk
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-07 00:00:00 -07:00
|
18
18
|
default_executable: jspec
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|