jspec 2.11.13 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/History.md +714 -0
  2. data/Manifest +51 -36
  3. data/README.md +968 -0
  4. data/Rakefile +4 -53
  5. data/bin/jspec +93 -224
  6. data/jspec.gemspec +5 -5
  7. data/lib/images/sprites.png +0 -0
  8. data/lib/jspec.css +2 -2
  9. data/lib/jspec.growl.js +115 -0
  10. data/lib/jspec.jquery.js +1 -1
  11. data/lib/jspec.js +98 -101
  12. data/lib/jspec.shell.js +5 -2
  13. data/lib/jspec.timers.js +1 -1
  14. data/lib/jspec.xhr.js +12 -2
  15. data/spec/commands/example_command.rb +19 -0
  16. data/spec/dom.html +33 -0
  17. data/spec/node.js +32 -0
  18. data/spec/rhino.js +24 -0
  19. data/spec/ruby/bin/init_spec.rb +101 -0
  20. data/spec/ruby/bin/install_spec.rb +141 -0
  21. data/spec/ruby/bin/run_spec.rb +0 -0
  22. data/spec/ruby/bin/shell_spec.rb +13 -0
  23. data/spec/ruby/bin/spec_helper.rb +25 -0
  24. data/spec/ruby/bin/update_spec.rb +72 -0
  25. data/spec/server.html +29 -0
  26. data/spec/server.rb +1 -1
  27. data/spec/{env.js → support/env.js} +554 -664
  28. data/spec/support/jquery.js +4376 -0
  29. data/spec/{helpers.js → unit/helpers.js} +2 -0
  30. data/spec/{spec.fixtures.js → unit/spec.fixtures.js} +0 -1
  31. data/spec/{spec.grammar-less.js → unit/spec.grammar-less.js} +0 -0
  32. data/spec/{spec.grammar.js → unit/spec.grammar.js} +1 -11
  33. data/spec/{spec.jquery.js → unit/spec.jquery.js} +0 -17
  34. data/spec/{spec.jquery.xhr.js → unit/spec.jquery.xhr.js} +13 -2
  35. data/spec/unit/spec.js +187 -0
  36. data/spec/{spec.matchers.js → unit/spec.matchers.js} +141 -66
  37. data/spec/{spec.modules.js → unit/spec.modules.js} +0 -0
  38. data/spec/{spec.shared-behaviors.js → unit/spec.shared-behaviors.js} +0 -0
  39. data/spec/{spec.utils.js → unit/spec.utils.js} +123 -22
  40. data/spec/{spec.xhr.js → unit/spec.xhr.js} +11 -10
  41. data/{server → src}/browsers.rb +23 -0
  42. data/{server → src}/helpers.rb +2 -17
  43. data/src/installables.rb +229 -0
  44. data/src/project.rb +340 -0
  45. data/{server → src}/routes.rb +1 -1
  46. data/{server → src}/server.rb +0 -0
  47. data/support/js.jar +0 -0
  48. data/templates/default/History.md +5 -0
  49. data/templates/default/{README.rdoc → Readme.md} +3 -3
  50. data/templates/default/lib/{yourlib.core.js → yourlib.js} +0 -0
  51. data/templates/default/spec/commands/example_command.rb +19 -0
  52. data/templates/default/spec/{spec.dom.html → dom.html} +5 -3
  53. data/templates/default/spec/rhino.js +10 -0
  54. data/templates/default/spec/server.html +18 -0
  55. data/templates/default/spec/unit/spec.helper.js +0 -0
  56. data/templates/default/spec/{spec.core.js → unit/spec.js} +0 -0
  57. data/templates/rails/commands/example_commands.rb +19 -0
  58. data/templates/rails/{spec.dom.html → dom.html} +4 -2
  59. data/templates/rails/rhino.js +10 -0
  60. data/templates/rails/server.html +18 -0
  61. data/templates/rails/unit/spec.helper.js +0 -0
  62. data/templates/rails/{spec.application.js → unit/spec.js} +0 -0
  63. metadata +56 -41
  64. data/History.rdoc +0 -590
  65. data/README.rdoc +0 -842
  66. data/spec/async +0 -1
  67. data/spec/jquery.js +0 -19
  68. data/spec/spec.dom.html +0 -34
  69. data/spec/spec.js +0 -166
  70. data/spec/spec.node.js +0 -46
  71. data/spec/spec.rhino.js +0 -23
  72. data/spec/spec.server.html +0 -29
  73. data/templates/default/History.rdoc +0 -4
  74. data/templates/default/spec/spec.rhino.js +0 -8
  75. data/templates/default/spec/spec.server.html +0 -16
  76. data/templates/rails/spec.rhino.js +0 -8
  77. data/templates/rails/spec.server.html +0 -16
File without changes
@@ -153,14 +153,6 @@ describe 'Utility'
153
153
  })
154
154
  result.should.eql [1,2,3]
155
155
  end
156
-
157
- it 'should iterate words in a string'
158
- result = []
159
- each('some foo bar', function(value){
160
- result.push(value)
161
- })
162
- result.should.eql ['some', 'foo', 'bar']
163
- end
164
156
  end
165
157
 
166
158
  describe 'map()'
@@ -170,13 +162,6 @@ describe 'Utility'
170
162
  })
171
163
  result.should.eql [2,4,6]
172
164
  end
173
-
174
- it 'should inherit the ability to iterate words in a string'
175
- result = map('some foo bar', function(i, value){
176
- return i + '-' + value
177
- })
178
- result.should.eql ['0-some', '1-foo', '2-bar']
179
- end
180
165
  end
181
166
 
182
167
  describe 'inject()'
@@ -204,7 +189,7 @@ describe 'Utility'
204
189
  end
205
190
 
206
191
  it 'should return the value of the first matching expression'
207
- result = any('foo some bar', function(value){
192
+ result = any(['foo', 'some', 'bar'], function(value){
208
193
  return value.length > 3
209
194
  })
210
195
  result.should.eql 'some'
@@ -221,7 +206,7 @@ describe 'Utility'
221
206
 
222
207
  describe 'select()'
223
208
  it 'should return an array of values when the callback evaluates to true'
224
- result = select('some foo bar baz stuff', function(value){
209
+ result = select(['some', 'foo', 'bar', 'baz', 'stuff'], function(value){
225
210
  return value.length > 3
226
211
  })
227
212
  result.should.eql ['some', 'stuff']
@@ -234,14 +219,14 @@ describe 'Utility'
234
219
  end
235
220
  end
236
221
 
237
- describe 'argumentsToArray()'
238
- it 'should return an array of arguments'
239
- func = function(){ return argumentsToArray(arguments) }
222
+ describe 'toArray()'
223
+ it 'should convert an arraylike object to an array'
224
+ func = function(){ return toArray(arguments) }
240
225
  func('foo', 'bar').should.eql ['foo', 'bar']
241
226
  end
242
227
 
243
- it 'should return the offset of an arguments array'
244
- func = function(){ return argumentsToArray(arguments, 2) }
228
+ it 'should allow a slice offset'
229
+ func = function(){ return toArray(arguments, 2) }
245
230
  func('foo', 'bar', 'baz').should.eql ['baz']
246
231
  end
247
232
  end
@@ -259,4 +244,120 @@ describe 'Utility'
259
244
  end
260
245
  end
261
246
 
247
+ describe 'puts()'
248
+ describe 'with primitive scalar values'
249
+ it 'should output true'
250
+ puts(true).should.eql 'true'
251
+ end
252
+
253
+ it 'should output false'
254
+ puts(false).should.eql 'false'
255
+ end
256
+
257
+ it 'should output null'
258
+ puts(null).should.eql 'null'
259
+ end
260
+
261
+ it 'should output undefined'
262
+ puts().should.eql 'undefined'
263
+ end
264
+ end
265
+
266
+ describe 'with strings'
267
+ it 'should output within double quotes'
268
+ puts("string").should.eql '"string"'
269
+ end
270
+
271
+ it 'should escape double quotes'
272
+ puts('he said "hey"').should.eql '"he said \\"hey\\""'
273
+ end
274
+
275
+ it 'should output non-printables as \n \t etc'
276
+ puts("\n\t\n\t").should.eql '"\\n\\t\\n\\t"'
277
+ end
278
+ end
279
+
280
+ describe 'with arrays'
281
+ it 'should output an array literal'
282
+ puts([1, 2, 3]).should.eql '[ 1, 2, 3 ]'
283
+ end
284
+
285
+ it 'should output nested arrays'
286
+ puts([1, 2, [ 1, 2 ]]).should.eql '[ 1, 2, [ 1, 2 ] ]'
287
+ end
288
+
289
+ it 'should output empty arrays'
290
+ puts([]).should.eql '[ ]'
291
+ end
292
+ end
293
+
294
+ describe 'with integers'
295
+ it 'should output an integer literal'
296
+ puts(1).should.eql '1'
297
+ puts(10).should.eql '10'
298
+ end
299
+ end
300
+
301
+ describe 'with floats'
302
+ it 'should output a float literal'
303
+ puts(1.5).should.eql '1.5'
304
+ end
305
+ end
306
+
307
+ describe 'with regular expressions'
308
+ it 'should output a regexp literal'
309
+ puts(/test/).should.eql '/test/'
310
+ end
311
+
312
+ it 'should output flags as well'
313
+ puts(/test/gm).should.eql '/test/gm'
314
+ end
315
+ end
316
+
317
+ describe 'with hashes'
318
+ it 'should output an object literal'
319
+ puts({ foo: 'bar' }).should.eql '{ foo: "bar" }'
320
+ end
321
+
322
+ it 'should output nested objects'
323
+ puts({ foo: { bar: 'baz' }}).should.eql '{ foo: { bar: "baz" } }'
324
+ end
325
+
326
+ it 'should output empty objects'
327
+ puts({}).should.eql '{ }'
328
+ end
329
+ end
330
+
331
+ describe 'with an_instance_of'
332
+ it 'should output an instance of Constructor'
333
+ object = { an_instance_of: Array }
334
+ puts(object).should.eql 'an instance of Array'
335
+ end
336
+ end
337
+
338
+ describe 'with jQuery'
339
+ it 'should output selector when present'
340
+ object = { jquery: '1.3.2', selector: '.foo bar' }
341
+ puts(object).should.eql 'selector ".foo bar"'
342
+ end
343
+
344
+ it 'should output outerHTML otherwise'
345
+ puts($('<p>Foo</p>')).should.match(/<p>Foo<\/p>/i)
346
+ end
347
+ end
348
+
349
+ describe 'with elements'
350
+ it 'should output the outerHTML'
351
+ puts($('<p>Foo</p>').get(0)).should.match(/<p>Foo<\/p>/i)
352
+ end
353
+ end
354
+
355
+ describe 'circular references'
356
+ it 'should output <circular reference> with objects'
357
+ object = { a: 1 }
358
+ object.b = object
359
+ puts(object).should.eql '{ a: 1, b: <circular reference> }'
360
+ end
361
+ end
362
+ end
262
363
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  describe 'JSpec'
3
- describe 'Mock XHR'
3
+ describe 'Mock XMLHttpRequest'
4
4
  before
5
5
  responseFrom = function(path) {
6
6
  request = new XMLHttpRequest
@@ -27,7 +27,16 @@ describe 'JSpec'
27
27
  XMLHttpRequest.should.not.eql JSpec.XMLHttpRequest
28
28
  end
29
29
 
30
- describe 'mock response'
30
+ describe 'last_request()'
31
+ it 'should provide access to the previous request'
32
+ mock_request().and_return('foo')
33
+ responseFrom('async')
34
+ last_request().url.should.eql 'async'
35
+ last_request().status.should.eql 200
36
+ end
37
+ end
38
+
39
+ describe 'mock_request()'
31
40
  before_each
32
41
  mockRequest().and_return('bar', 'text/plain', 200, { 'x-foo' : 'bar' })
33
42
  request = new XMLHttpRequest
@@ -99,7 +108,6 @@ describe 'JSpec'
99
108
 
100
109
  it 'should not interrupt JSpec request related functionality'
101
110
  mockRequest().and_return('fail')
102
- (JSpec.tryLoading('async') || JSpec.tryLoading('spec/async')).should.eql 'cookies!'
103
111
  fixture('test').should.eql '<p>test</p>'
104
112
  fixture('test.json').should.include '{ user'
105
113
  end
@@ -144,13 +152,6 @@ describe 'JSpec'
144
152
  request.responseText.should.be_null
145
153
  end
146
154
  end
147
-
148
- describe 'with uri'
149
- it 'should mock only the uri specified'
150
- mockRequest('ilike').and_return('cookies')
151
- responseFrom('async').should.eql 'cookies'
152
- end
153
- end
154
155
  end
155
156
  end
156
157
  end
@@ -82,6 +82,29 @@ class Browser
82
82
  system "osascript -e '#{code}' 2>&1 >/dev/null"
83
83
  end
84
84
 
85
+ #--
86
+ # Default
87
+ #++
88
+
89
+ class Default < self
90
+ def self.matches_name? string
91
+ string =~ /default/i
92
+ end
93
+
94
+ def visit uri
95
+ system 'open', uri if macos?
96
+ system 'start', uri if windows?
97
+ end
98
+
99
+ def supported?
100
+ macos?
101
+ end
102
+
103
+ def to_s
104
+ 'Default'
105
+ end
106
+ end
107
+
85
108
  #--
86
109
  # Firefox
87
110
  #++
@@ -14,24 +14,9 @@ helpers do
14
14
  ##
15
15
  # Override Sinatra's #send_file to prevent caching.
16
16
 
17
- def send_file path, opts = {}
18
- stat = File.stat(path)
17
+ def send_file *args
19
18
  response['Cache-Control'] = 'no-cache'
20
- content_type media_type(opts[:type]) ||
21
- media_type(File.extname(path)) ||
22
- response['Content-Type'] ||
23
- 'application/octet-stream'
24
- response['Content-Length'] ||= (opts[:length] || stat.size).to_s
25
-
26
- if opts[:disposition] == 'attachment' || opts[:filename]
27
- attachment opts[:filename] || path
28
- elsif opts[:disposition] == 'inline'
29
- response['Content-Disposition'] = 'inline'
30
- end
31
-
32
- halt ::Sinatra::Application::StaticFile.open(path, 'rb')
33
- rescue Errno::ENOENT
34
- not_found
19
+ super
35
20
  end
36
21
 
37
22
  ##
@@ -0,0 +1,229 @@
1
+
2
+ require 'open-uri'
3
+
4
+ module JSpec
5
+ class Installable
6
+
7
+ ##
8
+ # Options array
9
+
10
+ attr_reader :options
11
+
12
+ ##
13
+ # Initialize with _options_
14
+
15
+ def initialize options = {}
16
+ @options = options
17
+ end
18
+
19
+ ##
20
+ # Called before installing.
21
+
22
+ def before; end
23
+
24
+ ##
25
+ # Called after installing.
26
+
27
+ def after; end
28
+
29
+ ##
30
+ # Message to display after installation.
31
+
32
+ def install_message; end
33
+
34
+ ##
35
+ # Weither or not to use the progress bar.
36
+
37
+ def use_progress_bar?; true end
38
+
39
+ #--
40
+ # URI based installations
41
+ #++
42
+
43
+ class URI < self
44
+
45
+ ##
46
+ # Release specified or the current release.
47
+
48
+ def release
49
+ options[:release] || self.class.current
50
+ end
51
+
52
+ ##
53
+ # Installation path.
54
+
55
+ def path
56
+ options[:to] + "/#{self.class.name.downcase.tr(' ', '.')}.js"
57
+ end
58
+
59
+ ##
60
+ # Installation uri.
61
+
62
+ def uri
63
+ self.class.uri.sub 'RELEASE', release
64
+ end
65
+
66
+ ##
67
+ # Install.
68
+
69
+ def install
70
+ File.open(path, 'w+') do |file|
71
+ file.write open(uri).read
72
+ end
73
+ end
74
+
75
+ ##
76
+ # Installation message.
77
+
78
+ def install_message
79
+ "#{self.class.name} #{release} installed to #{path}"
80
+ end
81
+
82
+ #--
83
+ # DSL
84
+ #++
85
+
86
+ class << self
87
+
88
+ ##
89
+ # Human readable name.
90
+
91
+ def name string = nil
92
+ string ? @name = string : @name
93
+ end
94
+
95
+ ##
96
+ # Current release _string_.
97
+
98
+ def current string = nil
99
+ string ? @current = string : @current
100
+ end
101
+
102
+ ##
103
+ # Installable uri _string_. use RELEASE as the release placeholder.
104
+
105
+ def uri string = nil
106
+ string ? @uri = string : @uri
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ #--
113
+ # Rhino
114
+ #++
115
+
116
+ class Rhino < URI
117
+ name 'Rhino'
118
+ uri 'ftp://ftp.mozilla.org/pub/mozilla.org/js/RELEASE.zip'
119
+
120
+ ##
121
+ # No thanks!
122
+
123
+ def use_progress_bar?
124
+ false
125
+ end
126
+
127
+ ##
128
+ # Extension destination.
129
+
130
+ def path
131
+ options[:to] + '/js.jar'
132
+ end
133
+
134
+ ##
135
+ # Warn that --release is not yet supported.
136
+
137
+ def release
138
+ warn 'Rhino does not yet support --release' if options[:release]
139
+ 'rhino1_7R2'
140
+ end
141
+
142
+ ##
143
+ # Install
144
+
145
+ def install
146
+ say "... fetching #{uri}"; `curl #{uri} -o /tmp/rhino.zip 2> /dev/null`
147
+ say "... decompressing"; `unzip /tmp/rhino.zip -d /tmp`
148
+ say "... installing to #{path}"; `mv /tmp/rhino1_7R2/js.jar #{path}`
149
+ end
150
+
151
+ end
152
+
153
+ #--
154
+ # Envjs
155
+ #++
156
+
157
+ class Envjs < URI
158
+ name 'Env.js'
159
+ uri 'http://github.com/thatcher/env-js/raw/master/dist/env.rhino.js'
160
+
161
+ ##
162
+ # Warn that --release is not yet supported.
163
+
164
+ def release
165
+ warn 'Envjs does not yet support --release' if options[:release]
166
+ 'edge'
167
+ end
168
+
169
+ ##
170
+ # Installation path.
171
+
172
+ def path
173
+ options[:to] + '/env.js'
174
+ end
175
+
176
+ end
177
+
178
+ #--
179
+ # jQuery
180
+ #++
181
+
182
+ class Jquery < URI
183
+ name 'jQuery'
184
+ current '1.3.2'
185
+ uri 'http://ajax.googleapis.com/ajax/libs/jquery/RELEASE/jquery.js'
186
+ end
187
+
188
+ #--
189
+ # jQuery UI.
190
+ #++
191
+
192
+ class Jqueryui < URI
193
+ name 'jQuery UI'
194
+ current '1.7.2'
195
+ uri 'http://ajax.googleapis.com/ajax/libs/jqueryui/RELEASE/jquery-ui.js'
196
+ end
197
+
198
+ #--
199
+ # Prototype
200
+ #++
201
+
202
+ class Prototype < URI
203
+ name 'Prototype'
204
+ current '1.6.1.0'
205
+ uri 'http://ajax.googleapis.com/ajax/libs/prototype/RELEASE/prototype.js'
206
+ end
207
+
208
+ #--
209
+ # MooTools
210
+ #++
211
+
212
+ class Mootools < URI
213
+ name 'MooTools'
214
+ current '1.2.3'
215
+ uri 'http://ajax.googleapis.com/ajax/libs/mootools/RELEASE/mootools.js'
216
+ end
217
+
218
+ #--
219
+ # Dojo
220
+ #++
221
+
222
+ class Dojo < URI
223
+ name 'Dojo'
224
+ current '1.3.2'
225
+ uri 'http://ajax.googleapis.com/ajax/libs/dojo/RELEASE/dojo/dojo.xd.js.uncompressed.js'
226
+ end
227
+
228
+ end
229
+ end