visionmedia-jspec 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +232 -0
- data/Manifest +26 -0
- data/README.rdoc +406 -0
- data/Rakefile +70 -0
- data/bin/jspec +64 -0
- data/jspec.gemspec +36 -0
- data/lib/images/bg.png +0 -0
- data/lib/images/hr.png +0 -0
- data/lib/images/sprites.bg.png +0 -0
- data/lib/images/sprites.png +0 -0
- data/lib/images/vr.png +0 -0
- data/lib/jspec.css +129 -0
- data/lib/jspec.jquery.js +68 -0
- data/lib/jspec.js +912 -0
- data/spec/async +1 -0
- data/spec/jquery-1.3.1.js +4241 -0
- data/spec/spec.core.dom.js +12 -0
- data/spec/spec.core.js +323 -0
- data/spec/spec.grammar.js +127 -0
- data/spec/spec.html +24 -0
- data/spec/spec.jquery.js +162 -0
- data/templates/default/History.rdoc +4 -0
- data/templates/default/README.rdoc +29 -0
- data/templates/default/lib/yourlib.core.js +35 -0
- data/templates/default/spec/spec.core.js +8 -0
- data/templates/default/spec/spec.html +20 -0
- metadata +101 -0
data/spec/spec.core.js
ADDED
@@ -0,0 +1,323 @@
|
|
1
|
+
|
2
|
+
describe 'Matchers'
|
3
|
+
|
4
|
+
describe 'eql'
|
5
|
+
it 'should work with strings'
|
6
|
+
'test'.should.eql 'test'
|
7
|
+
'test'.should.not.eql 'foo'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should work with numbers'
|
11
|
+
11.should.eql 11
|
12
|
+
10.should.not.eql 11
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should loosely compare numbers as strings'
|
16
|
+
'11'.should.eql 11
|
17
|
+
'10'.should.not.eql 11
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should hash compare arrays'
|
21
|
+
[1, 2].should.eql [1, 2]
|
22
|
+
[1, 2].should.not.eql [1, 3]
|
23
|
+
[1, 2, [3], { foo : 'bar' }].should.eql [1, 2, [3], { foo : 'bar' }]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should hash compare objects'
|
27
|
+
{ foo : 'bar' }.should.eql { foo : 'bar' }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'equal'
|
32
|
+
it 'should perform strict comparisons'
|
33
|
+
'test'.should.equal 'test'
|
34
|
+
'1'.should.not.equal 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'match'
|
39
|
+
it 'should match regular expressions'
|
40
|
+
'foobar'.should.match(/foo/)
|
41
|
+
'foobar'.should.not.match(/barfoo/)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'be_empty'
|
46
|
+
it 'should consider any object responding to a length of 0 to be empty'
|
47
|
+
''.should.be_empty
|
48
|
+
' '.should.not.be_empty
|
49
|
+
[].should.be_empty
|
50
|
+
{ length : 0 }.should.be_empty
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'be_null'
|
55
|
+
it 'should check if a value is null'
|
56
|
+
null.should.be_null
|
57
|
+
0.should.not.be_null
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'have_length'
|
62
|
+
it 'should compare the length of an object'
|
63
|
+
'foo'.should.have_length 3
|
64
|
+
[1, 2].should.have_length 2
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'have_length_within'
|
69
|
+
it 'should check if an object has a length within the specified range'
|
70
|
+
'foo'.should.have_length_within 2..4
|
71
|
+
'f'.should.not.have_length_within 2..4
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'have_prop'
|
76
|
+
it 'should check if a property exists'
|
77
|
+
'foo'.should.have_prop 'length'
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should check that a property has a specific value'
|
81
|
+
'foo'.should.have_prop 'length', 3
|
82
|
+
{ length : '3' }.should.have_prop 'length', 3
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should check object hashes'
|
86
|
+
{ foo : 1..3 }.should.have_prop 'foo', 1..3
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should fail when the property does not exist'
|
90
|
+
'foo'.should.not.have_prop 'foo'
|
91
|
+
'foo'.should.not.have_prop 'foo', 'bar'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should fail when it is a function'
|
95
|
+
'foo'.should.not.have_prop 'toString'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'have_property'
|
100
|
+
it 'should check if a property exists'
|
101
|
+
'foo'.should.have_property 'length'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should check that a property has a specific value'
|
105
|
+
'foo'.should.have_property 'length', 3
|
106
|
+
{ length : '3' }.should.not.have_property 'length', 3
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should fail when the property does not exist'
|
110
|
+
'foo'.should.not.have_property 'foo'
|
111
|
+
'foo'.should.not.have_property 'foo', 'bar'
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should fail when it is a function'
|
115
|
+
'foo'.should.not.have_property 'toString'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'respond_to'
|
120
|
+
it 'should check if an object contains a method'
|
121
|
+
'test'.should.respond_to('toString')
|
122
|
+
'test'.should.not.respond_to('rawr')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'include'
|
127
|
+
it 'should check if an object includes a property'
|
128
|
+
{ hey : 'there' }.should.include 'hey'
|
129
|
+
{ hey : 'there' }.should.not.include 'foo'
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should check if a regular expression includes a string'
|
133
|
+
/(foo)?bar/.should.include '(foo)'
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should check if a function body includes a string'
|
137
|
+
-{ return [foo, bar] }.should.include 'foo', 'bar'
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should check if an array contains element(s)'
|
141
|
+
[1,2,3].should.include 1
|
142
|
+
[1,2,3].should.include 1, 2, 3
|
143
|
+
[1].should.not.include 0
|
144
|
+
['foo', 'bar'].should.include 'foo', 'bar'
|
145
|
+
['foo', 'bar'].should.include 'bar', 'foo'
|
146
|
+
['foo', 'bar'].should.not.include 'foo', 'rawr'
|
147
|
+
['foo', 'bar'].should.not.include 'rawr', 'foo'
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should check hashes of array elements'
|
151
|
+
[1, [2]].should.include [2]
|
152
|
+
[1, [2]].should.include [2], 1
|
153
|
+
[1, { two : 'three' }].should.include { two : 'three' }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'be_a'
|
158
|
+
it 'should compare the constructor of an object'
|
159
|
+
'test'.should.be_a String
|
160
|
+
[].should.be_an Array
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe 'throw_error'
|
165
|
+
it 'should check if an error is thrown'
|
166
|
+
-{ throw 'error' }.should_throw_error
|
167
|
+
-{ return 'test' }.should_not_throw_error
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should check if an error with a specific message is thrown'
|
171
|
+
-{ throw 'some foo bar' }.should.throw_error('some foo bar')
|
172
|
+
-{ throw 'some foo bar' }.should.throw_error(/foo bar/)
|
173
|
+
-{ throw 'some foo bar' }.should.not.throw_error(/rawr/)
|
174
|
+
-{ throw 'some foo bar' }.should.not.throw_error('rawr')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe 'be_type'
|
179
|
+
it 'should compare the type of an object via typeof'
|
180
|
+
'hey'.should.be_type 'string'
|
181
|
+
{}.should.be_type 'object'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'be_within'
|
186
|
+
it 'should check if a number is within a range'
|
187
|
+
5.should.be_within 1..10
|
188
|
+
15.should.not.be_within 10..5
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe 'have'
|
193
|
+
it 'should check the length of a property'
|
194
|
+
person = { pets : ['izzy', 'niko'] }
|
195
|
+
person.should.have 2, 'pets'
|
196
|
+
person.should.not.have 3, 'pets'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe 'have_at_least'
|
201
|
+
it 'should check if a object has at least n of a property'
|
202
|
+
person = { pets : ['izzy', 'niko'] }
|
203
|
+
person.should.have_at_least 1, 'pets'
|
204
|
+
person.should.have_at_least 2, 'pets'
|
205
|
+
person.should.not.have_at_least 3, 'pets'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe 'have_at_most'
|
210
|
+
it 'should check if an object has at most n of a property'
|
211
|
+
person = { pets : ['izzy', 'niko'] }
|
212
|
+
person.should.have_at_most 2, 'pets'
|
213
|
+
person.should.have_at_most 3, 'pets'
|
214
|
+
person.should.not.have_at_most 1, 'pets'
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe 'be_within'
|
219
|
+
it 'should check that an object has within n..n of a property'
|
220
|
+
person = { pets : ['izzy', 'niko'] }
|
221
|
+
person.should.have_within 1..2, 'pets'
|
222
|
+
person.should.have_within 2..5, 'pets'
|
223
|
+
person.should.not.have_within 5..10, 'pets'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
describe 'Negative specs'
|
230
|
+
|
231
|
+
it 'should fail'
|
232
|
+
'test'.should.not_eql 'test'
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should fail with one faulty assertion'
|
236
|
+
'test'.should.equal 'test'
|
237
|
+
'test'.should.equal 'foo'
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'should fail and print array with square braces'
|
241
|
+
[1,2].should.equal [1,3]
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'should fail and print nested array'
|
245
|
+
[1, ['foo']].should.equal [1, ['bar', ['whatever', 1.0, { foo : 'bar', bar : { 1 : 2 } }]]]
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'should fail and print html elements'
|
249
|
+
elem = document.createElement('a')
|
250
|
+
elem.setAttribute('href', 'http://vision-media.ca')
|
251
|
+
elem.should.not.eql elem
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'should fail with selector for jQuery objects'
|
255
|
+
elem = { jquery : '1.3.1', selector : '.foobar' }
|
256
|
+
elem.should.eql 'foo'
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'should fail with negative message'
|
260
|
+
'1'.should.not.be_true
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'should fail with positive message'
|
264
|
+
false.should.be_true
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should fail with function body'
|
268
|
+
-{ rawr }.should.not.throw_error
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'should fail with message of first failure'
|
272
|
+
true.should.be_true
|
273
|
+
'bar'.should.match(/foo/gm)
|
274
|
+
'bar'.should.include 'foo'
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'should fail with list'
|
278
|
+
['foo', 'bar'].should.include 'foo', 'car'
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
describe 'Utility'
|
284
|
+
describe 'query'
|
285
|
+
it 'should return a pairs value'
|
286
|
+
JSpec.query('suite', '?suite=Positive%20specs').should.equal 'Positive specs'
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'should return null when key is not present'
|
290
|
+
JSpec.query('foo', '?suite=Positive%20specs').should.be_null
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
describe 'strip'
|
295
|
+
it 'should strip whitespace by default'
|
296
|
+
JSpec.strip(" foo \n\n").should.equal 'foo'
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'should strip the characters passed'
|
300
|
+
JSpec.strip('[foo]', '\\[\\]').should.equal 'foo'
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe 'Contexts'
|
306
|
+
before
|
307
|
+
JSpec.context = { iLike : 'cookies' }
|
308
|
+
end
|
309
|
+
|
310
|
+
after
|
311
|
+
JSpec.context = null
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'should be replacable'
|
315
|
+
.iLike.should.equal 'cookies'
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe 'Misc'
|
320
|
+
it 'requires implementation'
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
@@ -0,0 +1,127 @@
|
|
1
|
+
|
2
|
+
describe 'Grammar'
|
3
|
+
|
4
|
+
it 'should allow "it" spec literal'
|
5
|
+
true.should.be_true
|
6
|
+
end
|
7
|
+
|
8
|
+
n = 10
|
9
|
+
it 'should allow literal javascript outside of blocks'
|
10
|
+
n.should.eql 10
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should allow parens to be optional when no args are passed'
|
14
|
+
true.should.be_true
|
15
|
+
true.should.be_true()
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should allow parens to be optional with args'
|
19
|
+
'foobar'.should.include 'foo'
|
20
|
+
'rawr'.should.not_include 'foo'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should allow literals without defining variables variables'
|
24
|
+
{}.should.be_an Object
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should allow alternative closure literal'
|
28
|
+
-{ throw 'test' }.should.throw_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should allow . this. literal'
|
32
|
+
this.foo = 'bar'
|
33
|
+
.foo.should.eql 'bar'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should allow inclusive range literal n..n'
|
37
|
+
1..5.should.eql [1,2,3,4,5]
|
38
|
+
3..4.should.eql [3,4]
|
39
|
+
1..1.should.eql [1]
|
40
|
+
3..1.should.eql [3,2,1]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should allow snakecase style assertions'
|
44
|
+
'foo'.should_equal('foo')
|
45
|
+
'foo'.should_equal 'foo'
|
46
|
+
'bar'.should_not_equal('foo')
|
47
|
+
'bar'.should_not_equal 'foo'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should allow dot style assertions'
|
51
|
+
'foo'.should.equal('foo')
|
52
|
+
'foo'.should.equal 'foo'
|
53
|
+
'bar'.should.not.equal('foo')
|
54
|
+
'bar'.should.not.equal 'foo'
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'with nested describe'
|
58
|
+
it 'should work'
|
59
|
+
true.should.be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should still allow literal javascript outside of blocks'
|
63
|
+
n.should.eql 10
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'nested again'
|
67
|
+
it 'should still work'
|
68
|
+
true.should.be_true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'before / after blocks'
|
74
|
+
var n, o
|
75
|
+
|
76
|
+
before
|
77
|
+
n = 1
|
78
|
+
end
|
79
|
+
|
80
|
+
after
|
81
|
+
n = 0
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should work'
|
85
|
+
n.should.eql 1
|
86
|
+
n++
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should persist'
|
90
|
+
n.should.eql 2
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'with nested describe'
|
94
|
+
it 'should be accessable'
|
95
|
+
n.should.eql 0
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'before_each / after_each blocks'
|
101
|
+
before_each
|
102
|
+
n = 1
|
103
|
+
end
|
104
|
+
|
105
|
+
after_each
|
106
|
+
o = 2
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should work'
|
110
|
+
n.should.eql 1
|
111
|
+
n = 2
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should not persist'
|
115
|
+
n.should.eql 1
|
116
|
+
o.should.eql 2
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'with nested describe'
|
120
|
+
it 'should be accessable'
|
121
|
+
n.should.eql 1
|
122
|
+
o.should.eql 2
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|