jspec-steventux 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/History.md +763 -0
  2. data/Manifest +73 -0
  3. data/README.md +974 -0
  4. data/Rakefile +44 -0
  5. data/bin/jspec +178 -0
  6. data/jspec-steventux.gemspec +44 -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 +149 -0
  14. data/lib/jspec.growl.js +115 -0
  15. data/lib/jspec.jquery.js +72 -0
  16. data/lib/jspec.js +1756 -0
  17. data/lib/jspec.shell.js +39 -0
  18. data/lib/jspec.timers.js +90 -0
  19. data/lib/jspec.xhr.js +195 -0
  20. data/spec/commands/example_command.rb +19 -0
  21. data/spec/dom.html +33 -0
  22. data/spec/fixtures/test.html +1 -0
  23. data/spec/fixtures/test.json +1 -0
  24. data/spec/fixtures/test.xml +5 -0
  25. data/spec/node.js +17 -0
  26. data/spec/rhino.js +23 -0
  27. data/spec/ruby/bin/init_spec.rb +101 -0
  28. data/spec/ruby/bin/install_spec.rb +142 -0
  29. data/spec/ruby/bin/run_spec.rb +0 -0
  30. data/spec/ruby/bin/shell_spec.rb +13 -0
  31. data/spec/ruby/bin/spec_helper.rb +8 -0
  32. data/spec/ruby/bin/update_spec.rb +72 -0
  33. data/spec/server.html +29 -0
  34. data/spec/server.rb +2 -0
  35. data/spec/support/env.js +10118 -0
  36. data/spec/support/jquery.js +4376 -0
  37. data/spec/unit/helpers.js +64 -0
  38. data/spec/unit/spec.fixtures.js +17 -0
  39. data/spec/unit/spec.grammar-less.js +34 -0
  40. data/spec/unit/spec.grammar.js +241 -0
  41. data/spec/unit/spec.jquery.js +178 -0
  42. data/spec/unit/spec.jquery.xhr.js +84 -0
  43. data/spec/unit/spec.js +187 -0
  44. data/spec/unit/spec.matchers.js +577 -0
  45. data/spec/unit/spec.modules.js +51 -0
  46. data/spec/unit/spec.shared-behaviors.js +80 -0
  47. data/spec/unit/spec.utils.js +346 -0
  48. data/spec/unit/spec.xhr.js +157 -0
  49. data/src/browsers.rb +294 -0
  50. data/src/helpers.rb +67 -0
  51. data/src/installables.rb +229 -0
  52. data/src/project.rb +341 -0
  53. data/src/routes.rb +57 -0
  54. data/src/server.rb +99 -0
  55. data/support/js.jar +0 -0
  56. data/templates/default/History.md +5 -0
  57. data/templates/default/Readme.md +29 -0
  58. data/templates/default/lib/yourlib.js +2 -0
  59. data/templates/default/spec/commands/example_command.rb +19 -0
  60. data/templates/default/spec/dom.html +22 -0
  61. data/templates/default/spec/node.js +10 -0
  62. data/templates/default/spec/rhino.js +10 -0
  63. data/templates/default/spec/server.html +18 -0
  64. data/templates/default/spec/server.rb +4 -0
  65. data/templates/default/spec/unit/spec.helper.js +0 -0
  66. data/templates/default/spec/unit/spec.js +8 -0
  67. data/templates/rails/commands/example_commands.rb +19 -0
  68. data/templates/rails/dom.html +22 -0
  69. data/templates/rails/rhino.js +10 -0
  70. data/templates/rails/server.html +18 -0
  71. data/templates/rails/server.rb +4 -0
  72. data/templates/rails/unit/spec.helper.js +0 -0
  73. data/templates/rails/unit/spec.js +8 -0
  74. metadata +185 -0
@@ -0,0 +1,157 @@
1
+
2
+ describe 'JSpec'
3
+ describe 'Mock XMLHttpRequest'
4
+ before
5
+ responseFrom = function(path) {
6
+ request = new XMLHttpRequest
7
+ request.open('POST', path, false)
8
+ request.send(null)
9
+ return request.responseText
10
+ }
11
+ end
12
+
13
+ it 'should provide snake DSL methods'
14
+ mock_request.should.equal mockRequest
15
+ unmock_request.should.equal unmockRequest
16
+ end
17
+
18
+ it 'should mock XMLHttpRequests if unmockRequest() is called or the spec block has finished'
19
+ original = XMLHttpRequest
20
+ mockRequest().and_return('test')
21
+ XMLHttpRequest.should.not.equal original
22
+ unmockRequest()
23
+ XMLHttpRequest.should.equal original
24
+ end
25
+
26
+ it 'should restore original XMLHttpRequest constructor after each spec'
27
+ XMLHttpRequest.should.not.eql JSpec.XMLHttpRequest
28
+ end
29
+
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()'
40
+ before_each
41
+ mockRequest().and_return('bar', 'text/plain', 200, { 'x-foo' : 'bar' })
42
+ request = new XMLHttpRequest
43
+ request.open('GET', 'path', false, 'foo', 'bar')
44
+ request.send('foo=bar')
45
+ end
46
+
47
+ it 'should allow setting response status'
48
+ mockRequest().and_return('bar', 'text/plain', 404)
49
+ request = new XMLHttpRequest
50
+ request.open('GET', 'path', false)
51
+ request.send(null)
52
+ request.status.should.eql 404
53
+ request.statusText.should.eql 'Not Found'
54
+ end
55
+
56
+ it 'should default readyState to 0'
57
+ request = new XMLHttpRequest
58
+ request.readyState.should.eql 0
59
+ end
60
+
61
+ it 'should populate user'
62
+ request.user.should.eql 'foo'
63
+ end
64
+
65
+ it 'should populate password'
66
+ request.password.should.eql 'bar'
67
+ end
68
+
69
+ it 'should populate method'
70
+ request.method.should.eql 'GET'
71
+ end
72
+
73
+ it 'should populate readyState'
74
+ request.readyState.should.eql 4
75
+ end
76
+
77
+ it 'should populate url'
78
+ request.url.should.eql 'path'
79
+ end
80
+
81
+ it 'should populate status'
82
+ request.status.should.eql 200
83
+ end
84
+
85
+ it 'should populate statusText'
86
+ request.statusText.should.eql 'OK'
87
+ end
88
+
89
+ it 'should populate content type response header'
90
+ request.getResponseHeader('Content-Type').should.eql 'text/plain'
91
+ end
92
+
93
+ it 'should populate Content-Length response header'
94
+ request.getResponseHeader('Content-Length').should.eql 3
95
+ end
96
+
97
+ it 'should populate data'
98
+ request.data.should.eql 'foo=bar'
99
+ end
100
+
101
+ it 'should populate responseText'
102
+ request.responseText.should.eql 'bar'
103
+ end
104
+
105
+ it 'should populate headers'
106
+ request.getResponseHeader('X-Foo').should.eql 'bar'
107
+ end
108
+
109
+ it 'should not interrupt JSpec request related functionality'
110
+ mockRequest().and_return('fail')
111
+ fixture('test').should.eql '<p>test</p>'
112
+ fixture('test.json').should.include '{ user'
113
+ end
114
+
115
+ describe '.onreadystatechange()'
116
+ before_each
117
+ mockRequest().and_return('bar', 'text/plain', 200)
118
+ request = new XMLHttpRequest
119
+ end
120
+
121
+ it 'should be called when opening request in context to the request'
122
+ request.onreadystatechange = function(){
123
+ this.readyState.should.eql 1
124
+ }
125
+ request.open('GET', 'path')
126
+ end
127
+
128
+ it 'should be called when sending request'
129
+ request.open('GET', 'path')
130
+ request.onreadystatechange = function(){
131
+ this.readyState.should.eql 4
132
+ }
133
+ request.send(null)
134
+ end
135
+ end
136
+
137
+ describe '.setRequestHeader()'
138
+ it 'should set request headers'
139
+ mockRequest().and_return('bar', 'text/plain', 200)
140
+ request.open('GET', 'path', false, 'foo', 'bar')
141
+ request.setRequestHeader('Accept', 'foo')
142
+ request.send(null)
143
+ request.requestHeaders['accept'].should.eql 'foo'
144
+ end
145
+ end
146
+
147
+ describe 'HEAD'
148
+ it 'should respond with headers only'
149
+ mockRequest().and_return('bar', 'text/plain', 200)
150
+ request.open('HEAD', 'path', false)
151
+ request.send(null)
152
+ request.responseText.should.be_null
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,294 @@
1
+
2
+ require 'rbconfig'
3
+
4
+ #--
5
+ # Browser
6
+ #++
7
+
8
+ class Browser
9
+
10
+ ##
11
+ # Check if the user agent _string_ matches this browser.
12
+
13
+ def self.matches_agent? string; end
14
+
15
+ ##
16
+ # Check if the browser matches the name _string_.
17
+
18
+ def self.matches_name? string; end
19
+
20
+ ##
21
+ # Subclasses.
22
+
23
+ def self.subclasses
24
+ @subclasses ||= []
25
+ end
26
+
27
+ ##
28
+ # Stack subclasses.
29
+
30
+ def self.inherited subclass
31
+ subclasses << subclass
32
+ end
33
+
34
+ ##
35
+ # Whether or not the browser is supported.
36
+
37
+ def supported?; true end
38
+
39
+ ##
40
+ # Browser setup.
41
+
42
+ def setup; end
43
+
44
+ ##
45
+ # Browser teardown.
46
+
47
+ def teardown; end
48
+
49
+ ##
50
+ # Linux Browser teardown
51
+ def teardown_linux
52
+ psout = IO.popen "ps -ef | grep #{self.to_s.downcase} | grep -v grep"
53
+ psout.readlines.each { |psline|
54
+ pid = psline.split(/[\s]+/)[1].to_i
55
+ Process.kill 9, pid
56
+ }
57
+ end
58
+
59
+
60
+ ##
61
+ # Host environment.
62
+
63
+ def host
64
+ Config::CONFIG['host_os']
65
+ end
66
+
67
+ ##
68
+ # Check if we are using macos.
69
+
70
+ def macos?
71
+ host.include? 'darwin'
72
+ end
73
+
74
+ ##
75
+ # Check if we are using windows.
76
+
77
+ def windows?
78
+ host =~ /mswin|mingw/
79
+ end
80
+
81
+ ##
82
+ # Check if we are using linux.
83
+
84
+ def linux?
85
+ host.include? 'linux'
86
+ end
87
+
88
+ ##
89
+ # Run applescript _code_.
90
+
91
+ def applescript code
92
+ raise "Can't run AppleScript on #{host}" unless macos?
93
+ system "osascript -e '#{code}' 2>&1 >/dev/null"
94
+ end
95
+
96
+ #--
97
+ # Default
98
+ #++
99
+
100
+ class Default < self
101
+ def self.matches_name? string
102
+ string =~ /default/i
103
+ end
104
+
105
+ def visit uri
106
+ system 'open', uri if macos?
107
+ system 'start', uri if windows?
108
+ system 'xdg-open', uri if linux?
109
+ end
110
+
111
+ def to_s
112
+ 'Default'
113
+ end
114
+ end
115
+
116
+ #--
117
+ # Firefox
118
+ #++
119
+
120
+ class Firefox < self
121
+ def self.matches_agent? string
122
+ string =~ /firefox/i
123
+ end
124
+
125
+ def self.matches_name? string
126
+ string =~ /ff|firefox|mozilla/i
127
+ end
128
+
129
+ def visit uri
130
+ system "open -g -a Firefox '#{uri}'" if macos?
131
+ system "firefox #{uri}" if linux?
132
+ system "#{File.join(ENV['ProgramFiles'] || 'c:\Program Files', '\Mozilla Firefox\firefox.exe')} #{uri}" if windows?
133
+ end
134
+
135
+ def teardown
136
+ teardown_linux if linux?
137
+ end
138
+
139
+ def to_s
140
+ 'Firefox'
141
+ end
142
+ end
143
+
144
+ #--
145
+ # Safari
146
+ #++
147
+
148
+ class Safari < self
149
+ def self.matches_agent? string
150
+ string =~ /safari/i && string !~ /chrome/i
151
+ end
152
+
153
+ def self.matches_name? string
154
+ string =~ /safari/i
155
+ end
156
+
157
+ def supported?
158
+ macos?
159
+ end
160
+
161
+ def setup
162
+ applescript 'tell application "Safari" to make new document'
163
+ end
164
+
165
+ def visit uri
166
+ applescript 'tell application "Safari" to set URL of front document to "' + uri + '"'
167
+ end
168
+
169
+ def matches_agent? string
170
+ string =~ /safari/i
171
+ end
172
+
173
+ def to_s
174
+ 'Safari'
175
+ end
176
+ end
177
+
178
+ #--
179
+ # Chrome
180
+ #++
181
+
182
+ class Chrome < self
183
+ def self.matches_agent? string
184
+ string =~ /chrome/i
185
+ end
186
+
187
+ def self.matches_name? string
188
+ string =~ /google|chrome/i
189
+ end
190
+
191
+ def supported?
192
+ macos? or linux?
193
+ end
194
+
195
+ def visit uri
196
+ system "open -g -a 'Google Chrome' #{uri}" if macos?
197
+ system "google-chrome #{uri}" if linux?
198
+ end
199
+
200
+ def to_s
201
+ 'Chrome'
202
+ end
203
+ end
204
+
205
+ #--
206
+ # WebKit
207
+ #++
208
+
209
+ class WebKit < self
210
+ def self.matches_agent? string
211
+ string =~ / AppleWebKit\/[\d\.]+\+/i
212
+ end
213
+
214
+ def self.matches_name? string
215
+ string =~ /webkit|wk/i
216
+ end
217
+
218
+ def supported?
219
+ macos?
220
+ end
221
+
222
+ def setup
223
+ applescript 'tell application "WebKit" to make new document'
224
+ end
225
+
226
+ def visit uri
227
+ applescript 'tell application "WebKit" to set URL of front document to "' + uri + '"'
228
+ end
229
+
230
+ def to_s
231
+ 'WebKit Nightly'
232
+ end
233
+ end
234
+
235
+ #--
236
+ # Internet Explorer
237
+ #++
238
+
239
+ class IE < self
240
+ def self.matches_agent? string
241
+ string =~ /microsoft/i
242
+ end
243
+
244
+ def self.matches_name? string
245
+ string =~ /ie|explorer/i
246
+ end
247
+
248
+ def supported?
249
+ windows?
250
+ end
251
+
252
+ def setup
253
+ require 'win32ole'
254
+ end
255
+
256
+ def visit uri
257
+ ie = WIN32OLE.new 'InternetExplorer.Application'
258
+ ie.visible = true
259
+ ie.Navigate uri
260
+ while ie.ReadyState != 4 do
261
+ sleep 1
262
+ end
263
+ end
264
+
265
+ def to_s
266
+ 'Internet Explorer'
267
+ end
268
+ end
269
+
270
+ #--
271
+ # Opera
272
+ #++
273
+
274
+ class Opera < self
275
+ def self.matches_agent? string
276
+ string =~ /opera/i
277
+ end
278
+
279
+ def self.matches_name? string
280
+ string =~ /opera/i
281
+ end
282
+
283
+ def visit uri
284
+ system "open -g -a Opera #{uri}" if macos?
285
+ system "c:\Program Files\Opera\Opera.exe #{uri}" if windows?
286
+ system "opera #{uri}" if linux?
287
+ end
288
+
289
+ def to_s
290
+ 'Opera'
291
+ end
292
+ end
293
+
294
+ end