raus22-jspec 2.0.4

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.
Files changed (45) hide show
  1. data/History.rdoc +323 -0
  2. data/Manifest +44 -0
  3. data/README.rdoc +495 -0
  4. data/Rakefile +72 -0
  5. data/bin/jspec +137 -0
  6. data/jspec.gemspec +35 -0
  7. data/lib/images/bg.png +0 -0
  8. data/lib/images/hr.png +0 -0
  9. data/lib/images/loading.gif +0 -0
  10. data/lib/images/sprites.bg.png +0 -0
  11. data/lib/images/sprites.png +0 -0
  12. data/lib/images/vr.png +0 -0
  13. data/lib/jspec.css +145 -0
  14. data/lib/jspec.jquery.js +64 -0
  15. data/lib/jspec.js +1468 -0
  16. data/server/browsers.rb +16 -0
  17. data/server/server.rb +103 -0
  18. data/spec/async +1 -0
  19. data/spec/jquery-1.3.1.js +4241 -0
  20. data/spec/server.html +23 -0
  21. data/spec/spec.grammar-less.js +34 -0
  22. data/spec/spec.grammar.js +179 -0
  23. data/spec/spec.html +27 -0
  24. data/spec/spec.jquery.js +166 -0
  25. data/spec/spec.js +119 -0
  26. data/spec/spec.matchers.js +382 -0
  27. data/spec/spec.rhino.js +12 -0
  28. data/spec/spec.shared-behaviors.js +51 -0
  29. data/spec/spec.utils.js +138 -0
  30. data/templates/default/History.rdoc +4 -0
  31. data/templates/default/README.rdoc +29 -0
  32. data/templates/default/lib/yourlib.core.js +2 -0
  33. data/templates/default/spec/spec.core.js +8 -0
  34. data/templates/default/spec/spec.html +20 -0
  35. data/templates/rhino/History.rdoc +4 -0
  36. data/templates/rhino/README.rdoc +29 -0
  37. data/templates/rhino/lib/yourlib.core.js +2 -0
  38. data/templates/rhino/spec/spec.core.js +8 -0
  39. data/templates/rhino/spec/spec.js +7 -0
  40. data/templates/server/History.rdoc +4 -0
  41. data/templates/server/README.rdoc +29 -0
  42. data/templates/server/lib/yourlib.core.js +2 -0
  43. data/templates/server/spec/spec.core.js +8 -0
  44. data/templates/server/spec/spec.html +15 -0
  45. metadata +120 -0
@@ -0,0 +1,382 @@
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
+
30
+ it 'should hash compare arbitrary objects'
31
+ Foo = function(){}, Bar = function(){}
32
+ Bar.prototype = { doSomething : function(){ }}
33
+ foo = new Foo, foo2 = new Foo, bar = new Bar
34
+ foo.should.eql foo2
35
+ foo.should.not.eql bar
36
+ end
37
+
38
+ it 'should work with constructors'
39
+ Array.should.eql Array
40
+ Array.should.not.eql Object
41
+ end
42
+ end
43
+
44
+ describe 'equal'
45
+ it 'should perform strict comparisons'
46
+ 'test'.should.equal 'test'
47
+ '1'.should.not.equal 1
48
+ true.should.be true
49
+ '1'.should.not.be true
50
+ end
51
+ end
52
+
53
+ describe 'match'
54
+ it 'should match regular expressions'
55
+ 'foobar'.should.match(/foo/)
56
+ 'foobar'.should.not.match(/barfoo/)
57
+ end
58
+ end
59
+
60
+ describe 'be_empty'
61
+ it 'should consider any object responding to a length of 0 to be empty'
62
+ ''.should.be_empty
63
+ ' '.should.not.be_empty
64
+ [].should.be_empty
65
+ { length : 0 }.should.be_empty
66
+ end
67
+ end
68
+
69
+ describe 'be_null'
70
+ it 'should check if a value is null'
71
+ a = 0
72
+ b = null
73
+ null.should.be_null
74
+ 0.should.not.be_null
75
+ a.should.not.be_null
76
+ b.should.be_null
77
+ end
78
+ end
79
+
80
+ describe 'have_length'
81
+ it 'should compare the length of an object'
82
+ 'foo'.should.have_length 3
83
+ [1, 2].should.have_length 2
84
+ end
85
+ end
86
+
87
+ describe 'have_length_within'
88
+ it 'should check if an object has a length within the specified range'
89
+ 'foo'.should.have_length_within 2..4
90
+ 'f'.should.not.have_length_within 2..4
91
+ end
92
+ end
93
+
94
+ describe 'have_prop'
95
+ it 'should check if a property exists'
96
+ 'foo'.should.have_prop 'length'
97
+ end
98
+
99
+ it 'should check that a property has a specific value'
100
+ 'foo'.should.have_prop 'length', 3
101
+ { length : '3' }.should.have_prop 'length', 3
102
+ end
103
+
104
+ it 'should check object hashes'
105
+ { foo : 1..3 }.should.have_prop 'foo', 1..3
106
+ end
107
+
108
+ it 'should fail when the property does not exist'
109
+ 'foo'.should.not.have_prop 'foo'
110
+ 'foo'.should.not.have_prop 'foo', 'bar'
111
+ end
112
+
113
+ it 'should fail when it is a function'
114
+ 'foo'.should.not.have_prop 'toString'
115
+ end
116
+ end
117
+
118
+ describe 'have_property'
119
+ it 'should check if a property exists'
120
+ 'foo'.should.have_property 'length'
121
+ end
122
+
123
+ it 'should check that a property has a specific value'
124
+ 'foo'.should.have_property 'length', 3
125
+ { length : '3' }.should.not.have_property 'length', 3
126
+ end
127
+
128
+ it 'should fail when the property does not exist'
129
+ 'foo'.should.not.have_property 'foo'
130
+ 'foo'.should.not.have_property 'foo', 'bar'
131
+ end
132
+
133
+ it 'should fail when it is a function'
134
+ 'foo'.should.not.have_property 'toString'
135
+ end
136
+ end
137
+
138
+ describe 'respond_to'
139
+ it 'should check if an object contains a method'
140
+ 'test'.should.respond_to('toString')
141
+ 'test'.should.not.respond_to('rawr')
142
+ end
143
+ end
144
+
145
+ describe 'include'
146
+ it 'should check if an object includes a property'
147
+ { hey : 'there' }.should.include 'hey'
148
+ { hey : 'there' }.should.not.include 'foo'
149
+ end
150
+
151
+ it 'should check if a regular expression includes a string'
152
+ (/(foo)?bar/).should.include '(foo)'
153
+ end
154
+
155
+ it 'should check if a function body includes a string'
156
+ -{ return [foo, bar] }.should.include 'foo', 'bar'
157
+ end
158
+
159
+ it 'should check if an array contains element(s)'
160
+ [1,2,3].should.include 1
161
+ [1,2,3].should.include 1, 2, 3
162
+ [1].should.not.include 0
163
+ ['foo', 'bar'].should.include 'foo', 'bar'
164
+ ['foo', 'bar'].should.include 'bar', 'foo'
165
+ ['foo', 'bar'].should.not.include 'foo', 'rawr'
166
+ ['foo', 'bar'].should.not.include 'rawr', 'foo'
167
+ end
168
+
169
+ it 'should check hashes of array elements'
170
+ [1, [2]].should.include [2]
171
+ [1, [2]].should.include [2], 1
172
+ [1, { two : 'three' }].should.include { two : 'three' }
173
+ end
174
+ end
175
+
176
+ describe 'be_a'
177
+ it 'should compare the constructor of an object'
178
+ 'test'.should.be_a String
179
+ [].should.be_an Array
180
+ end
181
+ end
182
+
183
+ describe 'throw_error'
184
+ it 'should check if an error is thrown'
185
+ -{ throw 'error' }.should_throw_error
186
+ -{ return 'test' }.should_not_throw_error
187
+ end
188
+
189
+ it 'should check if an error with a specific message is thrown'
190
+ -{ throw 'some foo bar' }.should.throw_error('some foo bar')
191
+ -{ throw 'some foo bar' }.should.throw_error(/foo bar/)
192
+ -{ throw 'some foo bar' }.should.not.throw_error(/rawr/)
193
+ -{ throw 'some foo bar' }.should.not.throw_error('rawr')
194
+ end
195
+
196
+ it 'should check if an error of a specific constructor is thrown'
197
+ -{ throw new Error('foo') }.should.throw_error(Error)
198
+ -{ throw new TypeError('foo') }.should.throw_error(TypeError)
199
+ -{ throw 'foo' }.should.not.throw_error(Error)
200
+ end
201
+ end
202
+
203
+ describe 'be_an_instance_of'
204
+ it 'should check that an object is an instance of another'
205
+ MyObject = function(){}
206
+ myInstance = new MyObject()
207
+ {}.should.be_an_instance_of Object
208
+ [].should.be_an_instance_of Array
209
+ MyObject.should.be_an_instance_of Function
210
+ myInstance.should.be_an_instance_of MyObject
211
+ myInstance.should.be_an_instance_of Object
212
+ end
213
+ end
214
+
215
+ describe 'be_type'
216
+ it 'should compare the type of an object via typeof'
217
+ 'hey'.should.be_type 'string'
218
+ {}.should.be_type 'object'
219
+ end
220
+ end
221
+
222
+ describe 'be_within'
223
+ it 'should check if a number is within a range'
224
+ 5.should.be_within 1..10
225
+ 15.should.not.be_within 10..5
226
+ end
227
+ end
228
+
229
+ describe 'have'
230
+ it 'should check the length of a property'
231
+ person = { pets : ['izzy', 'niko'] }
232
+ person.should.have 2, 'pets'
233
+ person.should.not.have 3, 'pets'
234
+ end
235
+ end
236
+
237
+ describe 'have_at_least'
238
+ it 'should check if a object has at least n of a property'
239
+ person = { pets : ['izzy', 'niko'] }
240
+ person.should.have_at_least 1, 'pets'
241
+ person.should.have_at_least 2, 'pets'
242
+ person.should.not.have_at_least 3, 'pets'
243
+ end
244
+ end
245
+
246
+ describe 'have_at_most'
247
+ it 'should check if an object has at most n of a property'
248
+ person = { pets : ['izzy', 'niko'] }
249
+ person.should.have_at_most 2, 'pets'
250
+ person.should.have_at_most 3, 'pets'
251
+ person.should.not.have_at_most 1, 'pets'
252
+ end
253
+ end
254
+
255
+ describe 'be_within'
256
+ it 'should check that an object has within n..n of a property'
257
+ person = { pets : ['izzy', 'niko'] }
258
+ person.should.have_within 1..2, 'pets'
259
+ person.should.have_within 2..5, 'pets'
260
+ person.should.not.have_within 5..10, 'pets'
261
+ end
262
+ end
263
+
264
+ describe 'receive'
265
+ before_each
266
+ person = { toString : function(){ return 'person' }}
267
+ personWithPets = {
268
+ toString : function(){ return 'personWithPets' },
269
+ getPets : function() { return ['izzy'] },
270
+ addPet : function(name) { return ['izzy', name] },
271
+ addPets : function(a, b) { return ['izzy', a, b] }
272
+ }
273
+ end
274
+
275
+ it 'should fail when the method does not exist'
276
+ person.should.receive('getPets')
277
+ end
278
+
279
+ it 'should fail when the method is never invoked'
280
+ personWithPets.should.receive('getPets')
281
+ end
282
+
283
+ it 'should pass when the method is invoked'
284
+ personWithPets.should.receive('getPets')
285
+ personWithPets.getPets()
286
+ end
287
+
288
+ it 'should pass and original method should still return its result'
289
+ personWithPets.should.receive('getPets')
290
+ personWithPets.getPets().should.eql ['izzy']
291
+ end
292
+
293
+ it 'should pass when the proper value is returned'
294
+ personWithPets.should.receive('getPets').and_return(['izzy'])
295
+ personWithPets.getPets()
296
+ end
297
+
298
+ it 'should fail when improper value is returned'
299
+ personWithPets.should.receive('getPets').and_return(['niko'])
300
+ personWithPets.getPets()
301
+ end
302
+
303
+ it 'should fail when not invoked the expected number of times'
304
+ personWithPets.should.receive('getPets', 'twice').and_return(['izzy'])
305
+ personWithPets.getPets()
306
+ end
307
+
308
+ it 'should fail when not invoked many times'
309
+ personWithPets.should.receive('getPets', 3).and_return(['izzy'])
310
+ personWithPets.getPets()
311
+ personWithPets.getPets()
312
+ end
313
+
314
+ it 'should pass when invoked the expected number of times'
315
+ personWithPets.should.receive('getPets', 'twice').and_return(['izzy'])
316
+ personWithPets.getPets()
317
+ personWithPets.getPets()
318
+ end
319
+
320
+ it 'should fail when not invoked with specific arguments'
321
+ personWithPets.should.receive('addPet', 'once').with_args('suki')
322
+ personWithPets.addPet('niko')
323
+ end
324
+
325
+ it 'should pass when a method is invoked with specific arguments'
326
+ personWithPets.should.receive('addPet', 'once').with_args('suki')
327
+ personWithPets.addPet('suki')
328
+ end
329
+
330
+ it 'should fail when expecting multiple arguments'
331
+ personWithPets.should.receive('addPets').with_args('suki', 'max')
332
+ personWithPets.addPets('suki')
333
+ end
334
+
335
+ it 'should pass with multiple arguments'
336
+ personWithPets.should.receive('addPets').with_args('suki', 'max')
337
+ personWithPets.addPets('suki', 'max')
338
+ end
339
+
340
+ it 'should pass with arguments and return value'
341
+ personWithPets.should.receive('addPet').with_args('suki').and_return(['izzy', 'suki'])
342
+ personWithPets.addPet('suki')
343
+ end
344
+
345
+ it 'should fail when argument is of the wrong type'
346
+ personWithPets.should.receive('addPet').with_args(an_instance_of(String))
347
+ personWithPets.addPet(['suki'])
348
+ end
349
+
350
+ it 'should pass when argument is the correct type'
351
+ personWithPets.should.receive('addPet').with_args(an_instance_of(String))
352
+ personWithPets.addPet('suki')
353
+ end
354
+
355
+ it 'should fail when return type is incorrect'
356
+ personWithPets.should.receive('addPet').and_return(an_instance_of(String))
357
+ personWithPets.addPet('suki')
358
+ end
359
+
360
+ it 'should pass when return type is correct'
361
+ personWithPets.should.receive('addPet').and_return(an_instance_of(Array))
362
+ personWithPets.addPet('suki')
363
+ end
364
+
365
+ it 'should fail when checking the type of multiple args and return types'
366
+ personWithPets.should.receive('addPets').with_args(an_instance_of(String), an_instance_of(Array)).and_return(an_instance_of(Array))
367
+ personWithPets.addPets('suki', 'max')
368
+ end
369
+
370
+ it 'should pass when checking the type of multiple args and return types'
371
+ personWithPets.should.receive('addPets').with_args(an_instance_of(String), an_instance_of(String)).and_return(an_instance_of(Array))
372
+ personWithPets.addPets('suki', 'max')
373
+ end
374
+
375
+ it 'should pass when checking for method calls to core prototypes'
376
+ array = ['foo', 'bar']
377
+ array.should.receive('toString').and_return('foo,bar')
378
+ 'array: ' + array
379
+ end
380
+ end
381
+
382
+ end
@@ -0,0 +1,12 @@
1
+
2
+ load('lib/jspec.js')
3
+ load('spec/spec.grammar-less.js')
4
+
5
+ JSpec
6
+ .exec('spec/spec.grammar.js')
7
+ .exec('spec/spec.js')
8
+ .exec('spec/spec.matchers.js')
9
+ .exec('spec/spec.utils.js')
10
+ .exec('spec/spec.shared-behaviors.js')
11
+ .run({ formatter : JSpec.formatters.Terminal, failuresOnly : true })
12
+ .report()
@@ -0,0 +1,51 @@
1
+
2
+ describe 'Shared Behaviors'
3
+ describe 'User'
4
+ before
5
+ User = function(name) { this.name = name }
6
+ user = new User('joe')
7
+ end
8
+
9
+ it 'should have a name'
10
+ user.should.have_property 'name'
11
+ end
12
+
13
+ describe 'Administrator'
14
+ should_behave_like('User')
15
+
16
+ before
17
+ Admin = function(name) { this.name = name }
18
+ Admin.prototype.may = function(perm){ return true }
19
+ user = new Admin('tj')
20
+ end
21
+
22
+ it 'should have access to all permissions'
23
+ user.may('edit pages').should.be_true
24
+ end
25
+
26
+ describe 'Super Administrator'
27
+ should_behave_like('Administrator')
28
+
29
+ before
30
+ SuperAdmin = function(name) { this.name = name }
31
+ SuperAdmin.prototype.may = function(perm){ return true }
32
+ user = new SuperAdmin('tj')
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe 'findSuite'
39
+ it 'should find a suite by full description'
40
+ JSpec.findSuite('Shared Behaviors User Administrator').should.be_a JSpec.Suite
41
+ end
42
+
43
+ it 'should find a suite by name'
44
+ JSpec.findSuite('User').should.be_a JSpec.Suite
45
+ end
46
+
47
+ it 'should return null when not found'
48
+ JSpec.findSuite('Rawr').should.be_null
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,138 @@
1
+
2
+ describe 'Utility'
3
+ describe 'wait'
4
+ it 'should wait for n milliseconds'
5
+ wait(2000)
6
+ setTimeout(function(){
7
+ true.should.be true
8
+ }, 1500)
9
+ end
10
+
11
+ it 'should wait for n seconds'
12
+ wait(3, 'seconds')
13
+ setTimeout(function(){
14
+ true.should.be true
15
+ }, 2500)
16
+ end
17
+ end
18
+
19
+ describe 'query'
20
+ it 'should return a pairs value'
21
+ query('suite', '?suite=Positive%20specs').should.equal 'Positive specs'
22
+ end
23
+
24
+ it 'should return null when key is not present'
25
+ query('foo', '?suite=Positive%20specs').should.be_null
26
+ end
27
+ end
28
+
29
+ describe 'strip'
30
+ it 'should strip whitespace by default'
31
+ strip(" foo \n\n").should.equal 'foo'
32
+ end
33
+
34
+ it 'should strip the characters passed'
35
+ strip('[foo]', '\\[\\]').should.equal 'foo'
36
+ end
37
+ end
38
+
39
+ describe 'each'
40
+ it 'should iterate an array'
41
+ result = []
42
+ each([1,2,3], function(value){
43
+ result.push(value)
44
+ })
45
+ result.should.eql [1,2,3]
46
+ end
47
+
48
+ it 'should iterate words in a string'
49
+ result = []
50
+ each('some foo bar', function(value){
51
+ result.push(value)
52
+ })
53
+ result.should.eql ['some', 'foo', 'bar']
54
+ end
55
+ end
56
+
57
+ describe 'map'
58
+ it 'should return an array of mapped values'
59
+ result = map([1,2,3], function(value){
60
+ return value * 2
61
+ })
62
+ result.should.eql [2,4,6]
63
+ end
64
+
65
+ it 'should inherit the ability to iterate words in a string'
66
+ result = map('some foo bar', function(i, value){
67
+ return i + '-' + value
68
+ })
69
+ result.should.eql ['0-some', '1-foo', '2-bar']
70
+ end
71
+ end
72
+
73
+ describe 'inject'
74
+ it 'should provide a memo object while iterating, not expecting returning of memo for composits'
75
+ result = inject([1,2,3], [], function(memo, value){
76
+ memo.push(value)
77
+ })
78
+ result.should.eql [1,2,3]
79
+ end
80
+
81
+ it 'should require returning of memo for scalar variables'
82
+ result = inject([1,2,3], false, function(memo, value){
83
+ return memo ? memo : value == 2
84
+ })
85
+ result.should.be_true
86
+ end
87
+ end
88
+
89
+ describe 'any'
90
+ it 'should return null when no matches are found'
91
+ result = any('some foo bar', function(value){
92
+ return value.length > 5
93
+ })
94
+ result.should.be_null
95
+ end
96
+
97
+ it 'should return the value of the first matching expression'
98
+ result = any('foo some bar', function(value){
99
+ return value.length > 3
100
+ })
101
+ result.should.eql 'some'
102
+ end
103
+ end
104
+
105
+ describe 'select'
106
+ it 'should return an array of values when the callback evaluates to true'
107
+ result = select('some foo bar baz stuff', function(value){
108
+ return value.length > 3
109
+ })
110
+ result.should.eql ['some', 'stuff']
111
+ end
112
+ end
113
+
114
+ describe 'last'
115
+ it 'should return the last element in an array'
116
+ last(['foo', 'bar']).should.eql 'bar'
117
+ end
118
+ end
119
+
120
+ describe 'argumentsToArray'
121
+ it 'should return an array of arguments'
122
+ func = function(){ return argumentsToArray(arguments) }
123
+ func('foo', 'bar').should.eql ['foo', 'bar']
124
+ end
125
+
126
+ it 'should return the offset of an arguments array'
127
+ func = function(){ return argumentsToArray(arguments, 2) }
128
+ func('foo', 'bar', 'baz').should.eql ['baz']
129
+ end
130
+ end
131
+
132
+ describe 'does'
133
+ it 'should assert without reporting'
134
+ does('foo', 'eql', 'foo')
135
+ JSpec.currentSpec.assertions.should.have_length 0
136
+ end
137
+ end
138
+ end