newjs 1.5.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/History.txt +11 -0
  2. data/Manifest.txt +162 -14
  3. data/{README.txt → README.rdoc} +1 -1
  4. data/Rakefile +25 -3
  5. data/app_generators/newjs_iphone/templates/Html/test/assets/jsunittest.js +41 -13
  6. data/app_generators/newjs_iphone/templates/Html/test/assets/unittest.css +4 -0
  7. data/features/development.feature +13 -0
  8. data/features/imported_files_for_generators.feature +19 -0
  9. data/features/steps/common.rb +205 -0
  10. data/features/steps/env.rb +6 -0
  11. data/javascript_test_generators/functional_test/functional_test_generator.rb +9 -1
  12. data/javascript_test_generators/functional_test/templates/test/assets/jshoulda.js +186 -0
  13. data/javascript_test_generators/functional_test/templates/test/test.html.erb +15 -1
  14. data/javascript_test_generators/unit_test/templates/test/assets/jshoulda.js +186 -0
  15. data/javascript_test_generators/unit_test/templates/test/test.html.erb +18 -20
  16. data/javascript_test_generators/unit_test/templates/test/test_jshoulda.html.erb +45 -0
  17. data/javascript_test_generators/unit_test/unit_test_generator.rb +11 -3
  18. data/lib/newjs.rb +3 -2
  19. data/newjs_iphone_generators/page/USAGE +5 -0
  20. data/newjs_iphone_generators/page/page_generator.rb +36 -0
  21. data/newjs_iphone_generators/page/templates/src/name.css.erb +0 -0
  22. data/newjs_iphone_generators/page/templates/src/name.html.erb +13 -0
  23. data/newjs_iphone_generators/page/templates/src/name.js.erb +4 -0
  24. data/newjs_iphone_generators/page/templates/test/fixtures/name.js.erb +5 -0
  25. data/newjs_iphone_generators/page/templates/test/unit/name_test.html.erb +61 -0
  26. data/rack_generators/javascript_test/USAGE +5 -0
  27. data/rack_generators/javascript_test/javascript_test_generator.rb +88 -0
  28. data/rack_generators/javascript_test/templates/assets/jshoulda.js +186 -0
  29. data/rack_generators/javascript_test/templates/assets/jsunittest.js +1004 -0
  30. data/rack_generators/javascript_test/templates/assets/unittest.css +54 -0
  31. data/rack_generators/javascript_test/templates/ext/jquery.js +3408 -0
  32. data/{app_generators/newjs_iphone/templates/Html/test/assets → rack_generators/javascript_test/templates/ext}/prototype.js +56 -122
  33. data/rack_generators/javascript_test/templates/library.js.erb +3 -0
  34. data/rack_generators/javascript_test/templates/test.html.erb +59 -0
  35. data/rack_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
  36. data/rails_generators/javascript_test/javascript_test_generator.rb +15 -3
  37. data/rails_generators/javascript_test/templates/assets/jshoulda.js +186 -0
  38. data/rails_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
  39. data/script/console +10 -0
  40. data/script/destroy +1 -1
  41. data/tasks/vendor/update/jshoulda.rake +18 -0
  42. data/tasks/vendor/update/jsunittest.rake +18 -0
  43. data/test/test_functional_test_generator.rb +13 -0
  44. data/test/test_generator_helper.rb +10 -1
  45. data/test/test_page_generator.rb +50 -0
  46. data/test/test_rack_javascript_test.rb +166 -0
  47. data/test/{test_javascript_test_generator.rb → test_rails_javascript_test_generator.rb} +15 -1
  48. data/test/test_unit_test_generator.rb +13 -0
  49. data/vendor/jshoulda/History.txt +108 -0
  50. data/vendor/jshoulda/License.txt +20 -0
  51. data/vendor/jshoulda/README.mdown +34 -0
  52. data/vendor/jshoulda/Rakefile +120 -0
  53. data/vendor/jshoulda/config/javascript_test_autotest.yml.sample +15 -0
  54. data/vendor/jshoulda/dist/jshoulda-0.0.1.js +62 -0
  55. data/vendor/jshoulda/dist/jshoulda-0.0.2.js +72 -0
  56. data/vendor/jshoulda/dist/jshoulda-0.0.3.js +72 -0
  57. data/vendor/jshoulda/dist/jshoulda-1.0.1.js +74 -0
  58. data/vendor/jshoulda/dist/jshoulda-1.0.js +72 -0
  59. data/vendor/jshoulda/dist/jshoulda-1.1.js +110 -0
  60. data/vendor/jshoulda/dist/jshoulda-1.2.1.js +186 -0
  61. data/vendor/jshoulda/dist/jshoulda-1.2.js +141 -0
  62. data/vendor/jshoulda/dist/jshoulda-1.2.x.js +142 -0
  63. data/vendor/jshoulda/dist/jshoulda.js +186 -0
  64. data/vendor/jshoulda/jshoulda/test/basic_test.html +42 -0
  65. data/vendor/jshoulda/lib/jstest.rb +382 -0
  66. data/vendor/jshoulda/lib/protodoc.rb +36 -0
  67. data/vendor/jshoulda/script/destroy +14 -0
  68. data/vendor/jshoulda/script/generate +14 -0
  69. data/vendor/jshoulda/script/js_autotest +1 -0
  70. data/vendor/jshoulda/script/rstakeout +97 -0
  71. data/vendor/jshoulda/site/asset_defaults.yaml +6 -0
  72. data/vendor/jshoulda/site/config.yaml +3 -0
  73. data/vendor/jshoulda/site/content/content.html +27 -0
  74. data/vendor/jshoulda/site/content/content.yaml +4 -0
  75. data/vendor/jshoulda/site/content/tutorial/tutorial.html +268 -0
  76. data/vendor/jshoulda/site/content/tutorial/tutorial.yaml +4 -0
  77. data/vendor/jshoulda/site/css/blackboard.css +88 -0
  78. data/vendor/jshoulda/site/css/jshoulda_site.css +33 -0
  79. data/vendor/jshoulda/site/css/unittest.css +42 -0
  80. data/vendor/jshoulda/site/example/minimal.html +55 -0
  81. data/vendor/jshoulda/site/js/editable.js +42 -0
  82. data/vendor/jshoulda/site/layouts/default/default.html +29 -0
  83. data/vendor/jshoulda/site/layouts/default/default.yaml +4 -0
  84. data/vendor/jshoulda/site/layouts/home_test/home_test.js +18 -0
  85. data/vendor/jshoulda/site/layouts/home_test/home_test.yaml +4 -0
  86. data/vendor/jshoulda/site/lib/analytics.rb +12 -0
  87. data/vendor/jshoulda/site/lib/default.rb +2 -0
  88. data/vendor/jshoulda/site/lib/example.rb +10 -0
  89. data/vendor/jshoulda/site/lib/hash.rb +11 -0
  90. data/vendor/jshoulda/site/lib/highlight.rb +17 -0
  91. data/vendor/jshoulda/site/page_defaults.yaml +10 -0
  92. data/vendor/jshoulda/site/templates/default/default.html +1 -0
  93. data/vendor/jshoulda/site/templates/default/default.yaml +4 -0
  94. data/vendor/jshoulda/src/HEADER +8 -0
  95. data/vendor/jshoulda/src/jshoulda.js +177 -0
  96. data/vendor/jshoulda/src/jshoulda.js.erb +3 -0
  97. data/vendor/jshoulda/tasks/bundle.rake +12 -0
  98. data/vendor/jshoulda/tasks/demo.rake +9 -0
  99. data/vendor/jshoulda/tasks/deploy.rake +29 -0
  100. data/{tasks → vendor/jshoulda/tasks}/environment.rake +0 -0
  101. data/vendor/jshoulda/tasks/javascript_test_autotest_tasks.rake +45 -0
  102. data/vendor/jshoulda/tasks/site.rake +74 -0
  103. data/vendor/jshoulda/test/assets/jsunittest.js +1004 -0
  104. data/vendor/jshoulda/test/assets/prototype.js +4324 -0
  105. data/{app_generators/newjs_iphone/templates/Html/test/assets/unittest.js → vendor/jshoulda/test/assets/prototype_unittest.js} +15 -9
  106. data/vendor/jshoulda/test/assets/unittest.css +50 -0
  107. data/vendor/jshoulda/test/unit/factory_test.html +82 -0
  108. data/vendor/jshoulda/test/unit/jshoulda2_test.html +85 -0
  109. data/vendor/jshoulda/test/unit/jshoulda_prototype_test.html +87 -0
  110. data/vendor/jshoulda/test/unit/jshoulda_test.html +86 -0
  111. data/vendor/jshoulda/test/unit/merge_methods_test.html +77 -0
  112. data/vendor/jshoulda/test/unit/names_and_count.html +68 -0
  113. data/vendor/jshoulda/test/unit/no_config_test.html +57 -0
  114. data/vendor/jshoulda/test/unit/styles_test.html +77 -0
  115. data/vendor/jshoulda/test/unit/unify_runners.html +69 -0
  116. data/vendor/jshoulda/test/unit/unnamed_context_test.html +67 -0
  117. data/vendor/jsunittest/Capfile +4 -0
  118. data/vendor/jsunittest/History.txt +37 -0
  119. data/{License.txt → vendor/jsunittest/License.txt} +0 -0
  120. data/vendor/jsunittest/README.txt +21 -0
  121. data/vendor/jsunittest/Rakefile +118 -0
  122. data/vendor/jsunittest/config/deploy.rb +20 -0
  123. data/vendor/jsunittest/config/website.yml.sample +2 -0
  124. data/vendor/jsunittest/dist/jsunittest-0.7.2.js +1004 -0
  125. data/vendor/jsunittest/dist/jsunittest.js +1004 -0
  126. data/vendor/jsunittest/dist/unittest.css +54 -0
  127. data/vendor/jsunittest/lib/jstest.rb +390 -0
  128. data/vendor/jsunittest/lib/protodoc.rb +36 -0
  129. data/vendor/jsunittest/script/destroy +14 -0
  130. data/vendor/jsunittest/script/generate +14 -0
  131. data/vendor/jsunittest/script/js_autotest +1 -0
  132. data/vendor/jsunittest/script/rstakeout +97 -0
  133. data/vendor/jsunittest/script/txt2html +75 -0
  134. data/vendor/jsunittest/src/HEADER +8 -0
  135. data/vendor/jsunittest/src/ajax.js +121 -0
  136. data/vendor/jsunittest/src/assertions.js +244 -0
  137. data/vendor/jsunittest/src/common.js +191 -0
  138. data/vendor/jsunittest/src/jsunittest.js +1004 -0
  139. data/vendor/jsunittest/src/logger.js +86 -0
  140. data/vendor/jsunittest/src/message_template.js +17 -0
  141. data/vendor/jsunittest/src/orig/unittest.js +484 -0
  142. data/vendor/jsunittest/src/prototype/event.js +72 -0
  143. data/vendor/jsunittest/src/prototype/template.js +33 -0
  144. data/vendor/jsunittest/src/runner.js +120 -0
  145. data/vendor/jsunittest/src/test_case.js +106 -0
  146. data/vendor/jsunittest/tasks/deploy.rake +29 -0
  147. data/vendor/jsunittest/tasks/environment.rake +7 -0
  148. data/vendor/jsunittest/tasks/javascript_test_autotest_tasks.rake +44 -0
  149. data/vendor/jsunittest/tasks/tmbundle.rake +24 -0
  150. data/vendor/jsunittest/tasks/website.rake +53 -0
  151. data/vendor/jsunittest/test/assets/example_test.html +50 -0
  152. data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/prototype.js +0 -0
  153. data/vendor/jsunittest/test/assets/unittest.css +54 -0
  154. data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/unittest.js +0 -0
  155. data/vendor/jsunittest/test/functional/jsunittest_test.html +209 -0
  156. data/vendor/jsunittest/test/unit/assertions_test.html +202 -0
  157. data/vendor/jsunittest/test/unit/common_test.html +61 -0
  158. data/vendor/jsunittest/test/unit/logger_test.html +98 -0
  159. data/vendor/jsunittest/test/unit/message_template_test.html +44 -0
  160. data/vendor/jsunittest/test/unit/runner_test.html +77 -0
  161. data/vendor/jsunittest/test/unit/template_test.html +57 -0
  162. data/vendor/jsunittest/test/unit/test_case_test.html +97 -0
  163. data/vendor/jsunittest/website/dist/jsunittest-0.7.2.js +1004 -0
  164. data/vendor/jsunittest/website/dist/jsunittest-getting-started.tar.gz +0 -0
  165. data/vendor/jsunittest/website/dist/jsunittest-getting-started.zip +0 -0
  166. data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/jsunittest.js +1004 -0
  167. data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/unittest.css +54 -0
  168. data/vendor/jsunittest/website/dist/jsunittest-getting-started/example_test.html +50 -0
  169. data/vendor/jsunittest/website/dist/jsunittest.js +1004 -0
  170. data/vendor/jsunittest/website/images/logo_bundle.png +0 -0
  171. data/vendor/jsunittest/website/images/passing_prototypejs_unittest_tests.jpg +0 -0
  172. data/vendor/jsunittest/website/index.html +94 -0
  173. data/vendor/jsunittest/website/index.txt +80 -0
  174. data/vendor/jsunittest/website/javascripts/rounded_corners_lite.inc.js +285 -0
  175. data/vendor/jsunittest/website/stylesheets/screen.css +138 -0
  176. data/vendor/jsunittest/website/template.html.erb +46 -0
  177. data/vendor/jsunittest/website/tmbundle/JavaScript Unit Testing.tmbundle.tar.gz +0 -0
  178. metadata +189 -24
  179. data/config/hoe.rb +0 -75
  180. data/config/requirements.rb +0 -17
  181. data/lib/newjs/version.rb +0 -9
  182. data/tasks/deployment.rake +0 -34
  183. data/tasks/jsunittest/update.rake +0 -18
  184. data/tasks/website.rake +0 -17
@@ -0,0 +1,54 @@
1
+ body, div, p, h1, h2, h3, ul, ol, span, a, table, td, form, img, li {
2
+ font-family: sans-serif;
3
+ }
4
+
5
+ body {
6
+ font-size:0.8em;
7
+ }
8
+
9
+ #log {
10
+ padding-bottom: 1em;
11
+ border-bottom: 2px solid #000;
12
+ margin-bottom: 2em;
13
+ }
14
+
15
+ .logsummary {
16
+ margin-top: 1em;
17
+ margin-bottom: 1em;
18
+ padding: 1ex;
19
+ border: 1px solid #000;
20
+ font-weight: bold;
21
+ }
22
+
23
+ .logtable {
24
+ width:100%;
25
+ border-collapse: collapse;
26
+ border: 1px dotted #666;
27
+ }
28
+
29
+ .logtable td, .logtable th {
30
+ text-align: left;
31
+ padding: 3px 8px;
32
+ border: 1px dotted #666;
33
+ }
34
+
35
+ .logtable .passed {
36
+ background-color: #cfc;
37
+ }
38
+
39
+ .logtable .failed, .logtable .error {
40
+ background-color: #fcc;
41
+ }
42
+
43
+ .logtable .warning {
44
+ background-color: #FC6;
45
+ }
46
+
47
+ .logtable td div.action_buttons {
48
+ display: inline;
49
+ }
50
+
51
+ .logtable td div.action_buttons input {
52
+ margin: 0 5px;
53
+ font-size: 10px;
54
+ }
@@ -0,0 +1,390 @@
1
+ require 'rake/tasklib'
2
+ require 'thread'
3
+ require 'webrick'
4
+ require 'fileutils'
5
+ include FileUtils
6
+
7
+ class Browser
8
+ def supported?; true; end
9
+ def setup ; end
10
+ def open(url) ; end
11
+ def teardown ; end
12
+
13
+ def host
14
+ require 'rbconfig'
15
+ Config::CONFIG['host']
16
+ end
17
+
18
+ def macos?
19
+ host.include?('darwin')
20
+ end
21
+
22
+ def windows?
23
+ host.include?('mswin')
24
+ end
25
+
26
+ def linux?
27
+ host.include?('linux')
28
+ end
29
+
30
+ def applescript(script)
31
+ raise "Can't run AppleScript on #{host}" unless macos?
32
+ system "osascript -e '#{script}' 2>&1 >/dev/null"
33
+ end
34
+ end
35
+
36
+ class FirefoxBrowser < Browser
37
+ def initialize(path=File.join(ENV['ProgramFiles'] || 'c:\Program Files', '\Mozilla Firefox\firefox.exe'))
38
+ @path = path
39
+ end
40
+
41
+ def visit(url)
42
+ system("open -a Firefox '#{url}'") if macos?
43
+ system("#{@path} #{url}") if windows?
44
+ system("firefox #{url}") if linux?
45
+ end
46
+
47
+ def to_s
48
+ "Firefox"
49
+ end
50
+ end
51
+
52
+ class SafariBrowser < Browser
53
+ def supported?
54
+ macos?
55
+ end
56
+
57
+ def setup
58
+ applescript('tell application "Safari" to make new document')
59
+ end
60
+
61
+ def visit(url)
62
+ applescript('tell application "Safari" to set URL of front document to "' + url + '"')
63
+ end
64
+
65
+ def teardown
66
+ #applescript('tell application "Safari" to close front document')
67
+ end
68
+
69
+ def to_s
70
+ "Safari"
71
+ end
72
+ end
73
+
74
+ class IEBrowser < Browser
75
+ def setup
76
+ require 'win32ole' if windows?
77
+ end
78
+
79
+ def supported?
80
+ windows?
81
+ end
82
+
83
+ def visit(url)
84
+ if windows?
85
+ ie = WIN32OLE.new('InternetExplorer.Application')
86
+ ie.visible = true
87
+ ie.Navigate(url)
88
+ while ie.ReadyState != 4 do
89
+ sleep(1)
90
+ end
91
+ end
92
+ end
93
+
94
+ def to_s
95
+ "Internet Explorer"
96
+ end
97
+ end
98
+
99
+ class KonquerorBrowser < Browser
100
+ @@configDir = File.join((ENV['HOME'] || ''), '.kde', 'share', 'config')
101
+ @@globalConfig = File.join(@@configDir, 'kdeglobals')
102
+ @@konquerorConfig = File.join(@@configDir, 'konquerorrc')
103
+
104
+ def supported?
105
+ linux?
106
+ end
107
+
108
+ # Forces KDE's default browser to be Konqueror during the tests, and forces
109
+ # Konqueror to open external URL requests in new tabs instead of a new
110
+ # window.
111
+ def setup
112
+ cd @@configDir, :verbose => false do
113
+ copy @@globalConfig, "#{@@globalConfig}.bak", :preserve => true, :verbose => false
114
+ copy @@konquerorConfig, "#{@@konquerorConfig}.bak", :preserve => true, :verbose => false
115
+ # Too lazy to write it in Ruby... Is sed dependency so bad?
116
+ system "sed -ri /^BrowserApplication=/d '#{@@globalConfig}'"
117
+ system "sed -ri /^KonquerorTabforExternalURL=/s:false:true: '#{@@konquerorConfig}'"
118
+ end
119
+ end
120
+
121
+ def teardown
122
+ cd @@configDir, :verbose => false do
123
+ copy "#{@@globalConfig}.bak", @@globalConfig, :preserve => true, :verbose => false
124
+ copy "#{@@konquerorConfig}.bak", @@konquerorConfig, :preserve => true, :verbose => false
125
+ end
126
+ end
127
+
128
+ def visit(url)
129
+ system("kfmclient openURL #{url}")
130
+ end
131
+
132
+ def to_s
133
+ "Konqueror"
134
+ end
135
+ end
136
+
137
+ class OperaBrowser < Browser
138
+ def initialize(path='c:\Program Files\Opera\Opera.exe')
139
+ @path = path
140
+ end
141
+
142
+ def setup
143
+ if windows?
144
+ puts %{
145
+ MAJOR ANNOYANCE on Windows.
146
+ You have to shut down Opera manually after each test
147
+ for the script to proceed.
148
+ Any suggestions on fixing this is GREATLY appreciated!
149
+ Thank you for your understanding.
150
+ }
151
+ end
152
+ end
153
+
154
+ def visit(url)
155
+ applescript('tell application "Opera" to GetURL "' + url + '"') if macos?
156
+ system("#{@path} #{url}") if windows?
157
+ system("opera #{url}") if linux?
158
+ end
159
+
160
+ def to_s
161
+ "Opera"
162
+ end
163
+ end
164
+
165
+ # shut up, webrick :-)
166
+ class ::WEBrick::HTTPServer
167
+ def access_log(config, req, res)
168
+ # nop
169
+ end
170
+ end
171
+
172
+ class ::WEBrick::BasicLog
173
+ def log(level, data)
174
+ # nop
175
+ end
176
+ end
177
+
178
+ class WEBrick::HTTPResponse
179
+ alias send send_response
180
+ def send_response(socket)
181
+ send(socket) unless fail_silently?
182
+ end
183
+
184
+ def fail_silently?
185
+ @fail_silently
186
+ end
187
+
188
+ def fail_silently
189
+ @fail_silently = true
190
+ end
191
+ end
192
+
193
+ class WEBrick::HTTPRequest
194
+ def to_json
195
+ headers = []
196
+ each { |k, v| headers.push "#{k.inspect}: #{v.inspect}" }
197
+ headers = "{" << headers.join(', ') << "}"
198
+ %({ "headers": #{headers}, "body": #{body.inspect}, "method": #{request_method.inspect} })
199
+ end
200
+ end
201
+
202
+ class WEBrick::HTTPServlet::AbstractServlet
203
+ def prevent_caching(res)
204
+ res['ETag'] = nil
205
+ res['Last-Modified'] = Time.now + 100**4
206
+ res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
207
+ res['Pragma'] = 'no-cache'
208
+ res['Expires'] = Time.now - 100**4
209
+ end
210
+ end
211
+
212
+ class BasicServlet < WEBrick::HTTPServlet::AbstractServlet
213
+ def do_GET(req, res)
214
+ prevent_caching(res)
215
+ res['Content-Type'] = "text/plain"
216
+
217
+ req.query.each do |k, v|
218
+ res[k] = v unless k == 'responseBody'
219
+ end
220
+ res.body = req.query["responseBody"]
221
+
222
+ raise WEBrick::HTTPStatus::OK
223
+ end
224
+
225
+ def do_POST(req, res)
226
+ do_GET(req, res)
227
+ end
228
+ end
229
+
230
+ class SlowServlet < BasicServlet
231
+ def do_GET(req, res)
232
+ sleep(2)
233
+ super
234
+ end
235
+ end
236
+
237
+ class DownServlet < BasicServlet
238
+ def do_GET(req, res)
239
+ res.fail_silently
240
+ end
241
+ end
242
+
243
+ class InspectionServlet < BasicServlet
244
+ def do_GET(req, res)
245
+ prevent_caching(res)
246
+ res['Content-Type'] = "application/json"
247
+ res.body = req.to_json
248
+ raise WEBrick::HTTPStatus::OK
249
+ end
250
+ end
251
+
252
+ class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler
253
+ def do_GET(req, res)
254
+ super
255
+ set_default_content_type(res, req.path)
256
+ prevent_caching(res)
257
+ end
258
+
259
+ def set_default_content_type(res, path)
260
+ res['Content-Type'] = case path
261
+ when /\.js$/ then 'text/javascript'
262
+ when /\.html$/ then 'text/html'
263
+ when /\.css$/ then 'text/css'
264
+ else 'text/plain'
265
+ end
266
+ end
267
+ end
268
+
269
+ class JavaScriptTestTask < ::Rake::TaskLib
270
+
271
+ def initialize(name=:test, port=4711)
272
+ @name = name
273
+ @tests = []
274
+ @browsers = []
275
+ @port = port
276
+ @queue = Queue.new
277
+
278
+ @server = WEBrick::HTTPServer.new(:Port => @port)
279
+ @server.mount_proc("/results") do |req, res|
280
+ @queue.push({
281
+ :tests => req.query['tests'].to_i,
282
+ :assertions => req.query['assertions'].to_i,
283
+ :failures => req.query['failures'].to_i,
284
+ :errors => req.query['errors'].to_i,
285
+ :warnings => req.query['warnings'].to_i
286
+ })
287
+ res.body = "OK"
288
+ end
289
+ @server.mount("/response", BasicServlet)
290
+ @server.mount("/slow", SlowServlet)
291
+ @server.mount("/down", DownServlet)
292
+ @server.mount("/inspect", InspectionServlet)
293
+ yield self if block_given?
294
+ define
295
+ end
296
+
297
+ def define
298
+ task @name do
299
+ trap("INT") { @server.shutdown }
300
+ t = Thread.new { @server.start }
301
+
302
+ # run all combinations of browsers and tests
303
+ @browsers.each do |browser|
304
+ if browser.supported?
305
+ t0 = Time.now
306
+ results = {:tests => 0, :assertions => 0, :failures => 0, :errors => 0, :warnings => 0}
307
+ errors = []
308
+ failures = []
309
+ warnings = []
310
+ browser.setup
311
+ puts "\nStarted tests in #{browser}"
312
+ @tests.each do |test|
313
+ params = "resultsURL=http://localhost:#{@port}/results&t=" + ("%.6f" % Time.now.to_f)
314
+ if test.is_a?(Hash)
315
+ params << "&tests=#{test[:testcases]}" if test[:testcases]
316
+ test = test[:url]
317
+ end
318
+ browser.visit("http://localhost:#{@port}#{test}?#{params}")
319
+
320
+ result = @queue.pop
321
+ result.each { |k, v| results[k] += v }
322
+ value = "."
323
+
324
+ if result[:failures] > 0
325
+ value = "F"
326
+ failures.push(test)
327
+ end
328
+
329
+ if result[:errors] > 0
330
+ value = "E"
331
+ errors.push(test)
332
+ end
333
+
334
+ if result[:warnings] > 0
335
+ value = "W"
336
+ warnings.push(test)
337
+ end
338
+
339
+ print value
340
+ end
341
+
342
+ puts "\nFinished in #{(Time.now - t0).round.to_s} seconds."
343
+ puts " Failures: #{failures.join(', ')}" unless failures.empty?
344
+ puts " Errors: #{errors.join(', ')}" unless errors.empty?
345
+ puts " Warnings: #{warnings.join(', ')}" unless warnings.empty?
346
+ puts "#{results[:tests]} tests, #{results[:assertions]} assertions, #{results[:failures]} failures, #{results[:errors]} errors, #{results[:warnings]} errors"
347
+ browser.teardown
348
+ else
349
+ puts "\nSkipping #{browser}, not supported on this OS"
350
+ end
351
+ end
352
+
353
+ @server.shutdown
354
+ t.join
355
+ end
356
+ end
357
+
358
+ def mount(path, dir=nil)
359
+ dir = Dir.pwd + path unless dir
360
+
361
+ # don't cache anything in our tests
362
+ @server.mount(path, NonCachingFileHandler, dir)
363
+ end
364
+
365
+ # test should be specified as a url or as a hash of the form
366
+ # {:url => "url", :testcases => "testFoo,testBar"}
367
+ def run(test)
368
+ @tests<<test
369
+ end
370
+
371
+ def browser(browser)
372
+ browser =
373
+ case(browser)
374
+ when :firefox
375
+ FirefoxBrowser.new
376
+ when :safari
377
+ SafariBrowser.new
378
+ when :ie
379
+ IEBrowser.new
380
+ when :konqueror
381
+ KonquerorBrowser.new
382
+ when :opera
383
+ OperaBrowser.new
384
+ else
385
+ browser
386
+ end
387
+
388
+ @browsers<<browser
389
+ end
390
+ end
@@ -0,0 +1,36 @@
1
+ require 'erb'
2
+
3
+ class String
4
+ def lines
5
+ split $/
6
+ end
7
+
8
+ def strip_whitespace_at_line_ends
9
+ lines.map {|line| line.gsub(/\s+$/, '')} * $/
10
+ end
11
+ end
12
+
13
+ module Protodoc
14
+ module Environment
15
+ def include(*filenames)
16
+ filenames.map {|filename| Preprocessor.new(filename).to_s}.join("\n")
17
+ end
18
+ end
19
+
20
+ class Preprocessor
21
+ include Environment
22
+
23
+ def initialize(filename)
24
+ @filename = File.expand_path(filename)
25
+ @template = ERB.new(IO.read(@filename), nil, '%')
26
+ end
27
+
28
+ def to_s
29
+ @template.result(binding).strip_whitespace_at_line_ends
30
+ end
31
+ end
32
+ end
33
+
34
+ if __FILE__ == $0
35
+ print Protodoc::Preprocessor.new(ARGV.first)
36
+ end