ramaze 0.0.9 → 0.1.0

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 (193) hide show
  1. data/Rakefile +14 -259
  2. data/bin/ramaze +52 -25
  3. data/doc/AUTHORS +6 -0
  4. data/doc/CHANGELOG +1363 -42
  5. data/doc/INSTALL +1 -1
  6. data/doc/README +48 -35
  7. data/doc/README.html +637 -0
  8. data/doc/TODO +7 -16
  9. data/doc/allison/allison.css +6 -7
  10. data/doc/allison/allison.gif +0 -0
  11. data/doc/allison/cache/STYLE +1 -2
  12. data/doc/changes.txt +3375 -0
  13. data/doc/changes.xml +3378 -0
  14. data/doc/meta/announcement.txt +47 -0
  15. data/doc/meta/configuration.txt +179 -0
  16. data/doc/meta/internals.txt +111 -0
  17. data/doc/readme_chunks/features.txt +8 -16
  18. data/doc/readme_chunks/installing.txt +7 -1
  19. data/doc/tutorial/todolist.txt +2 -3
  20. data/examples/blog/main.rb +9 -8
  21. data/examples/blog/public/styles/blog.css +132 -0
  22. data/examples/blog/src/controller.rb +14 -41
  23. data/examples/blog/src/model.rb +12 -13
  24. data/examples/blog/src/view.rb +16 -0
  25. data/examples/blog/template/edit.xhtml +19 -8
  26. data/examples/blog/template/index.xhtml +14 -22
  27. data/examples/blog/template/new.xhtml +18 -5
  28. data/examples/caching.rb +5 -8
  29. data/examples/element.rb +3 -3
  30. data/examples/hello.rb +3 -5
  31. data/examples/simple.rb +4 -7
  32. data/examples/templates/template/external.haml +8 -7
  33. data/examples/templates/template/external.mab +11 -8
  34. data/examples/templates/template_amrita2.rb +4 -4
  35. data/examples/templates/template_erubis.rb +3 -3
  36. data/examples/templates/template_ezamar.rb +1 -2
  37. data/examples/templates/template_haml.rb +24 -23
  38. data/examples/templates/template_liquid.rb +3 -1
  39. data/examples/templates/template_markaby.rb +15 -9
  40. data/examples/todolist/src/element/page.rb +1 -1
  41. data/lib/proto/conf/benchmark.yaml +6 -20
  42. data/lib/proto/conf/debug.yaml +6 -19
  43. data/lib/proto/conf/live.yaml +7 -19
  44. data/lib/proto/conf/silent.yaml +6 -16
  45. data/lib/proto/conf/stage.yaml +6 -18
  46. data/lib/proto/public/error.zmr +2 -2
  47. data/lib/ramaze.rb +34 -72
  48. data/lib/ramaze/adapter.rb +21 -18
  49. data/lib/ramaze/adapter/mongrel.rb +0 -3
  50. data/lib/ramaze/adapter/webrick.rb +6 -6
  51. data/lib/ramaze/cache/memcached.rb +3 -0
  52. data/lib/ramaze/controller.rb +227 -183
  53. data/lib/ramaze/dispatcher.rb +34 -129
  54. data/lib/ramaze/dispatcher/action.rb +28 -0
  55. data/lib/ramaze/dispatcher/error.rb +43 -0
  56. data/lib/ramaze/dispatcher/file.rb +34 -0
  57. data/lib/ramaze/global.rb +89 -48
  58. data/lib/ramaze/helper/aspect.rb +8 -6
  59. data/lib/ramaze/helper/auth.rb +3 -3
  60. data/lib/ramaze/helper/cache.rb +2 -2
  61. data/lib/ramaze/helper/file.rb +14 -0
  62. data/lib/ramaze/helper/inform.rb +36 -0
  63. data/lib/ramaze/helper/link.rb +7 -3
  64. data/lib/ramaze/helper/markaby.rb +30 -0
  65. data/lib/ramaze/helper/redirect.rb +2 -0
  66. data/lib/ramaze/inform.rb +8 -182
  67. data/lib/ramaze/inform/analogger.rb +19 -0
  68. data/lib/ramaze/inform/growl.rb +28 -0
  69. data/lib/ramaze/inform/hub.rb +26 -0
  70. data/lib/ramaze/inform/informer.rb +92 -0
  71. data/lib/ramaze/inform/informing.rb +44 -0
  72. data/lib/ramaze/inform/syslog.rb +27 -0
  73. data/lib/ramaze/inform/xosd.rb +42 -0
  74. data/lib/ramaze/snippets.rb +6 -2
  75. data/lib/ramaze/snippets/object/traits.rb +13 -1
  76. data/lib/ramaze/snippets/ramaze/autoreload.rb +58 -2
  77. data/lib/ramaze/snippets/string/color.rb +27 -0
  78. data/lib/ramaze/snippets/string/each.rb +6 -0
  79. data/lib/ramaze/snippets/struct/fill.rb +15 -0
  80. data/lib/ramaze/template/ezamar.rb +13 -22
  81. data/lib/ramaze/template/ezamar/element.rb +12 -12
  82. data/lib/ramaze/template/liquid.rb +19 -18
  83. data/lib/ramaze/template/markaby.rb +37 -58
  84. data/lib/ramaze/tool/localize.rb +128 -0
  85. data/lib/ramaze/tool/tidy.rb +51 -21
  86. data/lib/ramaze/trinity.rb +3 -3
  87. data/lib/ramaze/trinity/request.rb +41 -23
  88. data/lib/ramaze/trinity/response.rb +10 -5
  89. data/lib/ramaze/trinity/session.rb +17 -3
  90. data/lib/ramaze/version.rb +2 -2
  91. data/rake_tasks/conf.rake +56 -0
  92. data/rake_tasks/gem.rake +44 -0
  93. data/rake_tasks/maintaince.rake +187 -0
  94. data/spec/all.rb +32 -0
  95. data/spec/examples/caching.rb +19 -0
  96. data/spec/examples/element.rb +15 -0
  97. data/spec/examples/hello.rb +11 -0
  98. data/spec/examples/simple.rb +51 -0
  99. data/spec/examples/templates/template_amrita2.rb +14 -0
  100. data/spec/examples/templates/template_erubis.rb +21 -0
  101. data/spec/examples/templates/template_ezamar.rb +22 -0
  102. data/spec/examples/templates/template_haml.rb +23 -0
  103. data/spec/examples/templates/template_liquid.rb +24 -0
  104. data/spec/examples/templates/template_markaby.rb +21 -0
  105. data/spec/helper.rb +81 -0
  106. data/spec/{spec_helper_context.rb → helper/context.rb} +1 -1
  107. data/spec/helper/layout.rb +55 -0
  108. data/spec/helper/mock_http.rb +66 -0
  109. data/spec/{spec_helper_requester.rb → helper/requester.rb} +0 -6
  110. data/spec/{spec_helper_simple_http.rb → helper/simple_http.rb} +57 -57
  111. data/spec/helper/wrap.rb +193 -0
  112. data/spec/{adapter_spec.rb → ramaze/adapter.rb} +7 -5
  113. data/spec/{tc_adapter_mongrel.rb → ramaze/adapter/mongrel.rb} +2 -2
  114. data/spec/{tc_adapter_webrick.rb → ramaze/adapter/webrick.rb} +2 -2
  115. data/spec/{tc_cache.rb → ramaze/cache.rb} +16 -16
  116. data/spec/ramaze/conf/locale_de.yaml +6 -0
  117. data/spec/ramaze/conf/locale_en.yaml +6 -0
  118. data/spec/ramaze/controller.rb +184 -0
  119. data/spec/ramaze/controller/template/greet.xhtml +1 -0
  120. data/spec/ramaze/controller/template_resolving.rb +54 -0
  121. data/spec/ramaze/dependencies.rb +16 -0
  122. data/spec/{tc_element.rb → ramaze/element.rb} +21 -19
  123. data/spec/ramaze/error.rb +64 -0
  124. data/spec/{tc_gestalt.rb → ramaze/gestalt.rb} +10 -10
  125. data/spec/{tc_global.rb → ramaze/global.rb} +7 -7
  126. data/spec/{tc_helper_aspect.rb → ramaze/helper/aspect.rb} +22 -14
  127. data/spec/{tc_helper_auth.rb → ramaze/helper/auth.rb} +9 -7
  128. data/spec/{tc_helper_cache.rb → ramaze/helper/cache.rb} +14 -24
  129. data/spec/{tc_helper_feed.rb → ramaze/helper/feed.rb} +12 -12
  130. data/spec/ramaze/helper/file.rb +17 -0
  131. data/spec/{tc_helper_flash.rb → ramaze/helper/flash.rb} +16 -17
  132. data/spec/{tc_helper_form.rb → ramaze/helper/form.rb} +25 -26
  133. data/spec/{tc_helper_link.rb → ramaze/helper/link.rb} +9 -9
  134. data/spec/{tc_helper_redirect.rb → ramaze/helper/redirect.rb} +11 -10
  135. data/spec/{tc_helper_stack.rb → ramaze/helper/stack.rb} +10 -11
  136. data/spec/ramaze/inform/informer.rb +40 -0
  137. data/spec/ramaze/inform/syslog.rb +10 -0
  138. data/spec/ramaze/localize.rb +40 -0
  139. data/spec/ramaze/morpher.rb +82 -0
  140. data/spec/ramaze/params.rb +124 -0
  141. data/spec/{public → ramaze/public}/error404.xhtml +0 -0
  142. data/spec/{public → ramaze/public}/favicon.ico +0 -0
  143. data/spec/{public → ramaze/public}/ramaze.png +0 -0
  144. data/spec/{public → ramaze/public}/test_download.css +0 -0
  145. data/spec/ramaze/request.rb +129 -0
  146. data/spec/{tc_request_mongrel.rb → ramaze/request/mongrel.rb} +2 -2
  147. data/spec/{tc_request_webrick.rb → ramaze/request/webrick.rb} +1 -1
  148. data/spec/{tc_session.rb → ramaze/session.rb} +18 -18
  149. data/spec/{tc_store.rb → ramaze/store/default.rb} +10 -10
  150. data/spec/{tc_store_yaml.rb → ramaze/store/yaml.rb} +9 -9
  151. data/spec/ramaze/template.rb +86 -0
  152. data/spec/{tc_template_amrita2.rb → ramaze/template/amrita2.rb} +5 -5
  153. data/spec/{template → ramaze/template}/amrita2/data.amrita +0 -0
  154. data/spec/{template → ramaze/template}/amrita2/index.amrita +0 -0
  155. data/spec/{template → ramaze/template}/amrita2/sum.amrita +0 -0
  156. data/spec/{tc_template_erubis.rb → ramaze/template/erubis.rb} +9 -9
  157. data/spec/{template → ramaze/template}/erubis/sum.rhtml +0 -0
  158. data/spec/ramaze/template/ezamar.rb +62 -0
  159. data/spec/{template → ramaze/template}/ezamar/another/long/action.zmr +0 -0
  160. data/spec/{template → ramaze/template}/ezamar/combined.zmr +0 -0
  161. data/spec/{template → ramaze/template}/ezamar/file_only.zmr +0 -0
  162. data/spec/{template → ramaze/template}/ezamar/index.zmr +0 -0
  163. data/spec/ramaze/template/ezamar/nested.zmr +1 -0
  164. data/spec/{template → ramaze/template}/ezamar/some__long__action.zmr +0 -0
  165. data/spec/{template → ramaze/template}/ezamar/sum.zmr +0 -0
  166. data/spec/{tc_template_haml.rb → ramaze/template/haml.rb} +7 -7
  167. data/spec/{template → ramaze/template}/haml/index.haml +0 -0
  168. data/spec/{template → ramaze/template}/haml/with_vars.haml +0 -0
  169. data/spec/{tc_template_liquid.rb → ramaze/template/liquid.rb} +7 -7
  170. data/spec/{template → ramaze/template}/liquid/index.liquid +0 -0
  171. data/spec/{template → ramaze/template}/liquid/products.liquid +0 -0
  172. data/spec/ramaze/template/markaby.rb +59 -0
  173. data/spec/{template → ramaze/template}/markaby/external.mab +0 -0
  174. data/spec/{template → ramaze/template}/markaby/sum.mab +0 -0
  175. data/spec/ramaze/template/ramaze/external.test +1 -0
  176. data/spec/{tc_tidy.rb → ramaze/tidy.rb} +3 -3
  177. metadata +145 -81
  178. data/examples/blog/public/screen.css +0 -106
  179. data/examples/blog/src/element.rb +0 -58
  180. data/examples/blog/template/view.xhtml +0 -15
  181. data/examples/blog/test/tc_entry.rb +0 -18
  182. data/lib/proto/public/404.jpg +0 -0
  183. data/spec/request_tc_helper.rb +0 -135
  184. data/spec/spec_all.rb +0 -118
  185. data/spec/spec_helper.rb +0 -66
  186. data/spec/tc_controller.rb +0 -49
  187. data/spec/tc_dependencies.rb +0 -13
  188. data/spec/tc_error.rb +0 -43
  189. data/spec/tc_morpher.rb +0 -88
  190. data/spec/tc_params.rb +0 -125
  191. data/spec/tc_template_ezamar.rb +0 -64
  192. data/spec/tc_template_markaby.rb +0 -72
  193. data/spec/template/ezamar/nested.zmr +0 -1
@@ -1,10 +1,4 @@
1
1
  module Requester
2
- def get url, hash = {}
3
- http = SimpleHttp.new(url2uri(url))
4
- p :GET => http.uri
5
- response = http.get(hash).strip
6
- end
7
-
8
2
  def get url = '/', hash = {}
9
3
  request(:get, url, hash)
10
4
  end
@@ -46,9 +46,9 @@ You can redistribute it and/or modify it under either the terms of the GPL
46
46
  files under the ./missing directory. See each file for the copying
47
47
  condition.
48
48
 
49
- 5. The scripts and library files supplied as input to or produced as
49
+ 5. The scripts and library files supplied as input to or produced as
50
50
  output from the software do not automatically fall under the
51
- copyright of the software, but belong to whomever generated them,
51
+ copyright of the software, but belong to whomever generated them,
52
52
  and may be sold commercially, and may be aggregated with this
53
53
  software.
54
54
 
@@ -71,10 +71,10 @@ require 'base64'
71
71
  # complicated requests need to be made or default settings need to be
72
72
  # overriden, it's possible to instantiate `SimpleHttp` and use instance
73
73
  # methods `get` and `put`.
74
- #
74
+ #
75
75
  #
76
76
  # Features:
77
- #
77
+ #
78
78
  # * Handles Redirects automatically
79
79
  # * Proxy used transparently if http_proxy environment variable is
80
80
  # set.
@@ -101,27 +101,27 @@ require 'base64'
101
101
  # sh.request_headers= {'X-Special-Http-Header'=>'my-value'}
102
102
  # sh.get
103
103
  class SimpleHttp
104
-
104
+
105
105
  VERSION='0.1.1'
106
106
 
107
107
  attr_accessor :proxy_host, :proxy_port, :proxy_user, :proxy_pwd, :uri, :request_headers, :response_headers, :response_handlers, :follow_num_redirects
108
108
 
109
109
  RESPONSE_HANDLERS = {
110
- Net::HTTPResponse => lambda { |request, response, http|
110
+ Net::HTTPResponse => lambda { |request, response, http|
111
111
  response.each_header {|key, value|
112
- http.response_headers[key]=value
112
+ http.response_headers[key]=value
113
113
  }
114
114
  raise response.to_s
115
115
  },
116
116
  Net::HTTPSuccess => lambda { |request, response, http|
117
117
  response.each_header {|key, value|
118
- http.response_headers[key]=value
118
+ http.response_headers[key]=value
119
119
  }
120
120
  return response.body
121
121
  },
122
122
  Net::HTTPRedirection => lambda { |request, response, http|
123
- raise "too many redirects!" unless http.follow_num_redirects > 0
124
-
123
+ raise "too many redirects!" unless http.follow_num_redirects > 0
124
+
125
125
  # create a new SimpleHttp for the location
126
126
  # refered to decreasing the remaining redirects
127
127
  # by one.
@@ -143,12 +143,12 @@ class SimpleHttp
143
143
  # http doesn't permit redirects for methods
144
144
  # other than GET of HEAD, so we complain in case
145
145
  # we get them in response to a POST request. (Or
146
- # anything other than GET, for that matter.)
147
-
146
+ # anything other than GET, for that matter.)
147
+
148
148
  case request
149
149
  when Net::HTTP::Get : sh.get
150
150
  when Net::HTTP::Post : sh.post
151
- else
151
+ else
152
152
  raise "Not a valid HTTP method for redirection: #{request.class}"
153
153
  end
154
154
  }
@@ -167,7 +167,7 @@ class SimpleHttp
167
167
  # http = SimpleHttp.new "http://usr:pwd@www.example.com:1234"
168
168
  def initialize uri
169
169
  set_proxy ENV['http_proxy'] if ENV['http_proxy']
170
-
170
+
171
171
  if uri.class == String
172
172
 
173
173
  unless uri =~ /^https?:\/\//
@@ -194,26 +194,26 @@ class SimpleHttp
194
194
 
195
195
  end
196
196
 
197
- #
197
+ #
198
198
  # Provides facilities to perform http basic authentication. You
199
199
  # don't need to provide +usr+ and +pwd+ if they are already included
200
200
  # in the uri, i.e. http://user:password@www.example.com/
201
201
  #
202
-
202
+
203
203
  def basic_authentication usr, pwd
204
204
  str = Base64.encode64("#{usr}:#{pwd}")
205
205
  str = "Basic #{str}"
206
206
  @request_headers["Authorization"]=str
207
207
  end
208
-
208
+
209
209
  #
210
210
  # this method can be used to register response handlers for specific
211
211
  # http responses in case you need to override the default behaviour.
212
- # Defaults are:
212
+ # Defaults are:
213
213
  #
214
- # HTTPSuccess : return the body of the response
214
+ # HTTPSuccess : return the body of the response
215
215
  # HTTPRedirection : follow the redirection until success
216
- # Others : raise an exception
216
+ # Others : raise an exception
217
217
  #
218
218
  # `clazz` is the subclass of HTTPResponse (or HTTPResponse in case you
219
219
  # want to define "default" behaviour) that you are registering the
@@ -225,42 +225,42 @@ class SimpleHttp
225
225
  # and a reference to the instance of `SimpleHttp` that is executing the
226
226
  # call.
227
227
  #
228
- # example:
228
+ # example:
229
229
  #
230
230
  # # to override the default action of following a HTTP
231
231
  # # redirect, you could register the folllowing handler:
232
232
  #
233
- # sh = SimpleHttp "www.example.com"
234
- # sh.register_response_handler Net::HTTPRedirection {|request, response, shttp|
235
- # response['location']
233
+ # sh = SimpleHttp "www.example.com"
234
+ # sh.register_response_handler Net::HTTPRedirection {|request, response, shttp|
235
+ # response['location']
236
236
  # }
237
237
  #
238
-
238
+
239
239
  def register_response_handler clazz, &block
240
240
  c = clazz
241
241
  while c != Object
242
242
  # completely unnecessary sanity check to make sure parameter
243
243
  # `clazz` is in fact a HTTPResponse ...
244
244
  if c == Net::HTTPResponse
245
- @response_handlers[clazz]=block
245
+ @response_handlers[clazz]=block
246
246
  return
247
247
  end
248
248
  c = c.superclass
249
249
  end
250
250
 
251
- raise "Trying to register a response handler for non-response class: #{clazz}"
251
+ raise "Trying to register a response handler for non-response class: #{clazz}"
252
252
  end
253
253
 
254
254
  #
255
255
  # Set the proxy to use for the http request.
256
256
  # Note that you don't need to set the proxy in case the
257
- # `http_proxy` environment variable is set. To override
258
- # previous proxy settings and connect directly, call
257
+ # `http_proxy` environment variable is set. To override
258
+ # previous proxy settings and connect directly, call
259
259
  # `set_proxy nil`
260
260
  #
261
261
  # usage:
262
262
  # http = SimpleHttp.new "www.example.com"
263
- #
263
+ #
264
264
  # http.set_proxy "http://proxy:8000"
265
265
  # or:
266
266
  # http.set_proxy(URI.parse("http://proxy:8000"))
@@ -270,28 +270,28 @@ class SimpleHttp
270
270
  # http.set_proxy nil # to override previous proxy
271
271
  # settings and make the request directly.
272
272
  #
273
-
274
-
273
+
274
+
275
275
  def set_proxy proxy, port=nil, user=nil, pwd=nil
276
-
277
-
278
- if !proxy
279
- @proxy_host=@proxy_port=@proxy_user=@proxy_pwd=nil
276
+
277
+
278
+ if !proxy
279
+ @proxy_host=@proxy_port=@proxy_user=@proxy_pwd=nil
280
280
  return
281
281
  end
282
282
 
283
- if proxy.class == String
283
+ if proxy.class == String
284
284
  if !port && !user && !pwd
285
285
  proxy = URI.parse(proxy)
286
- else
286
+ else
287
287
  @proxy_host= host
288
288
  @proxy_port= port
289
289
  @proxy_user= user
290
290
  @proxy_pwd = pwd
291
291
  end
292
292
  end
293
-
294
- if proxy.class == URI::HTTP
293
+
294
+ if proxy.class == URI::HTTP
295
295
  @proxy_host= proxy.host
296
296
  @proxy_port= proxy.port
297
297
  @proxy_user= proxy.user
@@ -299,7 +299,7 @@ class SimpleHttp
299
299
  end
300
300
  end
301
301
 
302
- # interal
302
+ # interal
303
303
  # Takes a HTTPResponse (or subclass) and determines how to
304
304
  # handle the response. Default behaviour is:
305
305
  #
@@ -310,10 +310,10 @@ class SimpleHttp
310
310
  # the default behaviour can be overidden by registering a
311
311
  # response handler using the `register_response_handler` method.
312
312
  #
313
-
313
+
314
314
  def handle_response http_request, http_response
315
315
  raise "Not a Net::HTTPResponse" unless http_response.is_a? Net::HTTPResponse
316
-
316
+
317
317
  c = http_response.class
318
318
  while c!=Object
319
319
  # the response_handlers hash contains a handler
@@ -323,11 +323,11 @@ class SimpleHttp
323
323
  end
324
324
 
325
325
  c=c.superclass
326
- end
326
+ end
327
327
 
328
328
  # if we reached this place, no handler was registered
329
329
  # for this response. default is to return the response.
330
-
330
+
331
331
  return http_response
332
332
  end
333
333
 
@@ -335,12 +335,12 @@ class SimpleHttp
335
335
  def do_http request
336
336
  response = nil
337
337
 
338
- http = Net::HTTP.new(@uri.host, @uri.port, @proxy_host,
339
- @proxy_port, @proxy_user, @proxy_pwd)
338
+ http = Net::HTTP.new(@uri.host, @uri.port, proxy_host,
339
+ proxy_port, proxy_user, proxy_pwd)
340
340
  http.use_ssl = @uri.scheme == 'https'
341
-
341
+
342
342
  # add custom request headers.
343
-
343
+
344
344
  @request_headers.each {|key,value|
345
345
  request[key]=value;
346
346
  }
@@ -355,14 +355,14 @@ class SimpleHttp
355
355
  s + [CGI::escape(key) + "=" + CGI::escape(value)]
356
356
  end.join('&')
357
357
  end
358
-
358
+
359
359
  # Make a simple GET request to the provided URI.
360
360
  #
361
361
  # Example:
362
362
  # puts(SimpleHttp.get("www.example.com"))
363
363
  def self.get uri, query=nil
364
364
  http = SimpleHttp.new uri
365
- http.get query
365
+ http.get query
366
366
  end
367
367
 
368
368
  # Make a POST request to the provided URI.
@@ -374,32 +374,32 @@ class SimpleHttp
374
374
  # set the appriate content_type:
375
375
  #
376
376
  # SimpleHttp.post("http://www.example.com/", binary_data, "img/png")
377
-
377
+
378
378
  def self.post uri, query=nil, content_type='application/x-www-form-urlencoded'
379
379
  http = SimpleHttp.new uri
380
380
  http.post query, content_type
381
381
  end
382
-
382
+
383
383
  # Call the +get+ method as an instance method if you need to
384
384
  # modify the default behaviour of the library, or set special
385
385
  # headers:
386
386
  #
387
387
  # http = SimpleHttp.new "www.example.com"
388
388
  # http.request_headers["X-Special"]="whatever"
389
- # str = http.get
389
+ # str = http.get
390
390
  def get query = nil
391
391
  if (query = make_query query)
392
392
  @uri.query = @uri.query ? @uri.query+"&"+query : query
393
393
  end
394
394
  full_path = @uri.path + (@uri.query ? "?#{@uri.query}" : "")
395
-
395
+
396
396
  req = Net::HTTP::Get.new(full_path)
397
397
  # puts Net::HTTP::Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pwd).get(@uri)
398
398
  do_http req
399
399
  end
400
400
 
401
401
  #
402
- # Post the query data to the url.
402
+ # Post the query data to the url.
403
403
  # The body of the request remains empty if query=nil.
404
404
  # In case `query` is a `Hash`, it's assumed that we are
405
405
  # sending a form.
@@ -416,7 +416,7 @@ class SimpleHttp
416
416
 
417
417
  do_http req
418
418
  end
419
-
419
+
420
420
  end
421
421
 
422
422
  #ht = SimpleHttp.new "http://www.google.com/aldfksjaldskjfalskjfdlk"
@@ -0,0 +1,193 @@
1
+ require 'pp'
2
+ require 'set'
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+
9
+ begin
10
+ require 'systemu'
11
+ rescue LoadError
12
+ puts "Please install systemu for better-looking results"
13
+
14
+ # small drop-in replacement for systemu... far from perfect though, so please
15
+ # install the library
16
+
17
+ def systemu command
18
+ stdout = `#{command} 2>&1`
19
+ status, stdout, stderr = $?, stdout, ''
20
+ end
21
+ end
22
+
23
+ class String
24
+ { :red => 31,
25
+ :green => 32,
26
+ :yellow => 33,
27
+ }.each do |key, value|
28
+ define_method key do
29
+ "\e[#{value}m" + self + "\e[0m"
30
+ end
31
+ end
32
+
33
+ def /(str)
34
+ File.join(self, str.to_s)
35
+ end
36
+ end
37
+
38
+ class Array
39
+ def commonize
40
+ snips, rest = map{|s| [s[0,1], s[1..-1]]}.transpose
41
+ unless snips.uniq.size != 1 or rest.any?{|r| File.basename(r) == r}
42
+ rest.commonize
43
+ else
44
+ self.map{|e| e.gsub(/^\//, '')}
45
+ end
46
+ end
47
+
48
+ def namize
49
+ commonize.map do |e|
50
+ dir = File.dirname(e)
51
+ file = File.basename(e, File.extname(e))
52
+ ( dir / file ).gsub(/^\.\//, '')
53
+ end
54
+ end
55
+ end
56
+
57
+ $stdout.sync = true
58
+
59
+ class SpecWrap
60
+ def initialize(*files)
61
+ @files = files.flatten
62
+ @names = @files.namize
63
+ @specs = Hash[*@files.zip(@names).flatten]
64
+ @done = Set.new
65
+ end
66
+
67
+ def run
68
+ @specs.sort_by{|s| s.last}.each do |file, name|
69
+ spec = SpecFile.new(file, name, term_width)
70
+ spec.run
71
+ spec.short_summary
72
+ @done << spec
73
+ end
74
+
75
+ @done.sort_by{|d| d.name}.each do |spec|
76
+ puts(spec.long_summary) if spec.failed?
77
+ end
78
+
79
+ summarize
80
+ end
81
+
82
+ def summarize
83
+ total_passed = @done.inject(0){|s,v| s + v.passed }
84
+ total_failed = @done.inject(0){|s,v| s + v.failed }
85
+ total_specs = total_failed + total_passed
86
+
87
+ puts "#{total_specs} examples, #{total_failed} failures"
88
+ puts
89
+
90
+ if total_failed.nonzero?
91
+ failed = @done.select{|d| d.failed.nonzero? or d.passed.zero?}.map{|f| f.name.red }
92
+ puts "These failed: #{failed.join(', ')}"
93
+ exit 1
94
+ else
95
+ puts("No failing examples, let's add some tests!")
96
+ end
97
+ end
98
+
99
+ def term_width
100
+ @names.sort_by{|s| s.size }.last.size
101
+ end
102
+ end
103
+
104
+ class SpecFile
105
+ attr_reader :file, :name, :passed, :failed, :mark_passed
106
+
107
+ def initialize file, name, term_width
108
+ @file, @name, @term_width = file, name, term_width
109
+ @inc = $:.map{|e| "-I#{e}" }.join(" ")
110
+ end
111
+
112
+ def run
113
+ init
114
+ execute
115
+ parse
116
+ done
117
+ self
118
+ end
119
+
120
+ def init
121
+ print "Running #@name... ".ljust(@term_width + 20)
122
+ end
123
+
124
+ def execute
125
+ @status, @stdout, @stderr = systemu("ruby #@inc #@file")
126
+ end
127
+
128
+ def done
129
+ @ran = true
130
+ end
131
+
132
+ def short_summary
133
+ f = lambda{|n| n.to_s.rjust(3) }
134
+ total = f[@passed + @failed] rescue nil
135
+ failed, passed = f[@failed], f[@passed]
136
+ color = :red
137
+
138
+ if total_failure?
139
+ text = 'total failure'
140
+ elsif failed?
141
+ text = "#{total} specs - #{failed} failed"
142
+ if @stdout =~ /Usually you should not worry about this failure, just install the/
143
+ lib = @stdout.scan(/^no such file to load -- (.*?)$/).flatten.first
144
+ text = "needs #{lib}"
145
+ @mark_passed = true
146
+ end
147
+ elsif (not @mark_passed) and succeeded?
148
+ color = :green
149
+ text = "#{total} specs - all passed"
150
+ end
151
+
152
+ text.strip!
153
+ text = (' ' + text + ' ').center(24)
154
+ text = "[#{text}]"
155
+
156
+ puts(text.send(color))
157
+ end
158
+
159
+ def long_summary
160
+ puts "[ #@name ]".center(80, '-'), "ExitStatus:".yellow
161
+ pp @status
162
+ puts "StdOut:".yellow, @stdout, "StdErr:".yellow, @stderr
163
+ end
164
+
165
+ def parse
166
+ @passed = 0
167
+ @failed = 0
168
+ found = false
169
+ @stdout.grep(/(\d+) examples?, (\d+) failures?/)
170
+ @passed, @failed = $1.to_i, $2.to_i
171
+ end
172
+
173
+ def failed?
174
+ not succeeded?
175
+ end
176
+
177
+ def total_failure?
178
+ succeeded? == nil
179
+ end
180
+
181
+ def succeeded?
182
+ run unless @ran
183
+ return @mark_passed unless @mark_passed.nil?
184
+ crits = [
185
+ [@status.exitstatus.zero?, @stderr.empty?],
186
+ [@passed, @failed],
187
+ [@passed.nonzero?, @failed.zero?],
188
+ ]
189
+ crits.all?{|c| c.all? }
190
+ rescue
191
+ nil
192
+ end
193
+ end