thorero 0.9.4.4 → 0.9.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. data/LICENSE +1 -1
  2. data/README +21 -0
  3. data/Rakefile +275 -108
  4. data/TODO +0 -0
  5. data/bin/merb +12 -0
  6. data/bin/merb-specs +5 -0
  7. data/docs/bootloading.dox +58 -0
  8. data/docs/documentation_standards +40 -0
  9. data/docs/merb-core-call-stack-diagram.mmap +0 -0
  10. data/docs/merb-core-call-stack-diagram.pdf +0 -0
  11. data/docs/merb-core-call-stack-diagram.png +0 -0
  12. data/docs/new_render_api +51 -0
  13. data/lib/merb-core.rb +603 -0
  14. data/lib/merb-core/autoload.rb +32 -0
  15. data/lib/merb-core/bootloader.rb +708 -0
  16. data/lib/merb-core/config.rb +303 -0
  17. data/lib/merb-core/constants.rb +43 -0
  18. data/lib/merb-core/controller/abstract_controller.rb +578 -0
  19. data/lib/merb-core/controller/exceptions.rb +302 -0
  20. data/lib/merb-core/controller/merb_controller.rb +256 -0
  21. data/lib/merb-core/controller/mime.rb +106 -0
  22. data/lib/merb-core/controller/mixins/authentication.rb +87 -0
  23. data/lib/merb-core/controller/mixins/controller.rb +290 -0
  24. data/lib/merb-core/controller/mixins/render.rb +481 -0
  25. data/lib/merb-core/controller/mixins/responder.rb +472 -0
  26. data/lib/merb-core/controller/template.rb +254 -0
  27. data/lib/merb-core/core_ext.rb +8 -0
  28. data/lib/merb-core/core_ext/kernel.rb +319 -0
  29. data/lib/merb-core/dispatch/cookies.rb +91 -0
  30. data/lib/merb-core/dispatch/dispatcher.rb +278 -0
  31. data/lib/merb-core/dispatch/exceptions.html.erb +303 -0
  32. data/lib/merb-core/dispatch/request.rb +603 -0
  33. data/lib/merb-core/dispatch/router.rb +179 -0
  34. data/lib/merb-core/dispatch/router/behavior.rb +867 -0
  35. data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
  36. data/lib/merb-core/dispatch/router/route.rb +321 -0
  37. data/lib/merb-core/dispatch/session.rb +78 -0
  38. data/lib/merb-core/dispatch/session/cookie.rb +168 -0
  39. data/lib/merb-core/dispatch/session/memcached.rb +184 -0
  40. data/lib/merb-core/dispatch/session/memory.rb +241 -0
  41. data/lib/merb-core/dispatch/worker.rb +28 -0
  42. data/lib/merb-core/gem_ext/erubis.rb +77 -0
  43. data/lib/{extlib → merb-core}/logger.rb +2 -2
  44. data/lib/merb-core/plugins.rb +59 -0
  45. data/lib/merb-core/rack.rb +21 -0
  46. data/lib/merb-core/rack/adapter.rb +44 -0
  47. data/lib/merb-core/rack/adapter/ebb.rb +25 -0
  48. data/lib/merb-core/rack/adapter/evented_mongrel.rb +26 -0
  49. data/lib/merb-core/rack/adapter/fcgi.rb +17 -0
  50. data/lib/merb-core/rack/adapter/irb.rb +118 -0
  51. data/lib/merb-core/rack/adapter/mongrel.rb +26 -0
  52. data/lib/merb-core/rack/adapter/runner.rb +28 -0
  53. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
  54. data/lib/merb-core/rack/adapter/thin.rb +39 -0
  55. data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
  56. data/lib/merb-core/rack/adapter/webrick.rb +36 -0
  57. data/lib/merb-core/rack/application.rb +18 -0
  58. data/lib/merb-core/rack/handler/mongrel.rb +97 -0
  59. data/lib/merb-core/rack/middleware.rb +26 -0
  60. data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
  61. data/lib/merb-core/rack/middleware/profiler.rb +19 -0
  62. data/lib/merb-core/rack/middleware/static.rb +45 -0
  63. data/lib/merb-core/server.rb +252 -0
  64. data/lib/merb-core/tasks/audit.rake +68 -0
  65. data/lib/merb-core/tasks/merb.rb +1 -0
  66. data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
  67. data/lib/merb-core/test.rb +11 -0
  68. data/lib/merb-core/test/helpers.rb +9 -0
  69. data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
  70. data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
  71. data/lib/merb-core/test/helpers/request_helper.rb +344 -0
  72. data/lib/merb-core/test/helpers/route_helper.rb +33 -0
  73. data/lib/merb-core/test/helpers/view_helper.rb +121 -0
  74. data/lib/merb-core/test/matchers.rb +9 -0
  75. data/lib/merb-core/test/matchers/controller_matchers.rb +319 -0
  76. data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
  77. data/lib/merb-core/test/matchers/view_matchers.rb +335 -0
  78. data/lib/merb-core/test/run_specs.rb +47 -0
  79. data/lib/merb-core/test/tasks/spectasks.rb +68 -0
  80. data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
  81. data/lib/merb-core/test/test_ext/object.rb +14 -0
  82. data/lib/merb-core/test/test_ext/string.rb +14 -0
  83. data/lib/merb-core/vendor/facets.rb +2 -0
  84. data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
  85. data/lib/merb-core/vendor/facets/inflect.rb +345 -0
  86. data/lib/merb-core/version.rb +11 -0
  87. data/spec/private/config/adapter_spec.rb +32 -0
  88. data/spec/private/config/config_spec.rb +202 -0
  89. data/spec/private/config/environment_spec.rb +13 -0
  90. data/spec/private/config/spec_helper.rb +1 -0
  91. data/spec/private/core_ext/kernel_spec.rb +169 -0
  92. data/spec/private/dispatch/bootloader_spec.rb +24 -0
  93. data/spec/private/dispatch/cookies_spec.rb +107 -0
  94. data/spec/private/dispatch/dispatch_spec.rb +35 -0
  95. data/spec/private/dispatch/fixture/app/controllers/application.rb +4 -0
  96. data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +27 -0
  97. data/spec/private/dispatch/fixture/app/controllers/foo.rb +21 -0
  98. data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +8 -0
  99. data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +37 -0
  100. data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
  101. data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
  102. data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +40 -0
  103. data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
  104. data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +11 -0
  105. data/spec/private/dispatch/fixture/config/black_hole.rb +12 -0
  106. data/spec/private/dispatch/fixture/config/environments/development.rb +6 -0
  107. data/spec/private/dispatch/fixture/config/environments/production.rb +5 -0
  108. data/spec/private/dispatch/fixture/config/environments/test.rb +6 -0
  109. data/spec/private/dispatch/fixture/config/init.rb +45 -0
  110. data/spec/private/dispatch/fixture/config/rack.rb +11 -0
  111. data/spec/private/dispatch/fixture/config/router.rb +35 -0
  112. data/spec/private/dispatch/fixture/log/merb_test.log +1874 -0
  113. data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
  114. data/spec/private/dispatch/fixture/public/merb.fcgi +4 -0
  115. data/spec/private/dispatch/fixture/public/stylesheets/master.css +119 -0
  116. data/spec/private/dispatch/route_params_spec.rb +24 -0
  117. data/spec/private/dispatch/session_mixin_spec.rb +47 -0
  118. data/spec/private/dispatch/spec_helper.rb +1 -0
  119. data/spec/private/plugins/plugin_spec.rb +166 -0
  120. data/spec/private/rack/application_spec.rb +49 -0
  121. data/spec/private/router/behavior_spec.rb +60 -0
  122. data/spec/private/router/fixture/log/merb_test.log +139 -0
  123. data/spec/private/router/route_spec.rb +414 -0
  124. data/spec/private/router/router_spec.rb +175 -0
  125. data/spec/private/vendor/facets/plural_spec.rb +564 -0
  126. data/spec/private/vendor/facets/singular_spec.rb +489 -0
  127. data/spec/public/DEFINITIONS +11 -0
  128. data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +1 -0
  129. data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +1 -0
  130. data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +1 -0
  131. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +1 -0
  132. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +1 -0
  133. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
  134. data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +1 -0
  135. data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +1 -0
  136. data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +1 -0
  137. data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
  138. data/spec/public/abstract_controller/controllers/display.rb +54 -0
  139. data/spec/public/abstract_controller/controllers/filters.rb +193 -0
  140. data/spec/public/abstract_controller/controllers/helpers.rb +41 -0
  141. data/spec/public/abstract_controller/controllers/partial.rb +121 -0
  142. data/spec/public/abstract_controller/controllers/render.rb +113 -0
  143. data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +1 -0
  144. data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
  145. data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
  146. data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +1 -0
  147. data/spec/public/abstract_controller/controllers/views/layout/alt.erb +1 -0
  148. data/spec/public/abstract_controller/controllers/views/layout/custom.erb +1 -0
  149. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +1 -0
  150. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +1 -0
  151. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +1 -0
  152. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
  153. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +1 -0
  154. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
  155. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +1 -0
  156. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
  157. data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +1 -0
  158. data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +1 -0
  159. data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +1 -0
  160. data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +1 -0
  161. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +1 -0
  162. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +1 -0
  163. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +1 -0
  164. data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +1 -0
  165. data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +1 -0
  166. data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +1 -0
  167. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +1 -0
  168. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +1 -0
  169. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +1 -0
  170. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +1 -0
  171. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
  172. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
  173. data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +1 -0
  174. data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +1 -0
  175. data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +1 -0
  176. data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +1 -0
  177. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
  178. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
  179. data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +1 -0
  180. data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +1 -0
  181. data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +1 -0
  182. data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +1 -0
  183. data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +1 -0
  184. data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +1 -0
  185. data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +1 -0
  186. data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
  187. data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +1 -0
  188. data/spec/public/abstract_controller/display_spec.rb +33 -0
  189. data/spec/public/abstract_controller/filter_spec.rb +106 -0
  190. data/spec/public/abstract_controller/helper_spec.rb +21 -0
  191. data/spec/public/abstract_controller/partial_spec.rb +61 -0
  192. data/spec/public/abstract_controller/render_spec.rb +90 -0
  193. data/spec/public/abstract_controller/spec_helper.rb +31 -0
  194. data/spec/public/boot_loader/boot_loader_spec.rb +33 -0
  195. data/spec/public/boot_loader/spec_helper.rb +1 -0
  196. data/spec/public/controller/authentication_spec.rb +103 -0
  197. data/spec/public/controller/base_spec.rb +36 -0
  198. data/spec/public/controller/controllers/authentication.rb +45 -0
  199. data/spec/public/controller/controllers/base.rb +36 -0
  200. data/spec/public/controller/controllers/display.rb +118 -0
  201. data/spec/public/controller/controllers/redirect.rb +30 -0
  202. data/spec/public/controller/controllers/responder.rb +93 -0
  203. data/spec/public/controller/controllers/url.rb +7 -0
  204. data/spec/public/controller/controllers/views/layout/custom.html.erb +1 -0
  205. data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +1 -0
  206. data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
  207. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
  208. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
  209. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +1 -0
  210. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +1 -0
  211. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +1 -0
  212. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
  213. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +1 -0
  214. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +1 -0
  215. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +1 -0
  216. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +1 -0
  217. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +1 -0
  218. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +1 -0
  219. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +1 -0
  220. data/spec/public/controller/display_spec.rb +84 -0
  221. data/spec/public/controller/redirect_spec.rb +27 -0
  222. data/spec/public/controller/responder_spec.rb +163 -0
  223. data/spec/public/controller/spec_helper.rb +11 -0
  224. data/spec/public/controller/url_spec.rb +180 -0
  225. data/spec/public/core/merb_core_spec.rb +45 -0
  226. data/spec/public/core_ext/class_spec.rb +91 -0
  227. data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
  228. data/spec/public/core_ext/kernel_spec.rb +9 -0
  229. data/spec/public/core_ext/spec_helper.rb +1 -0
  230. data/spec/public/directory_structure/directory/app/controllers/application.rb +3 -0
  231. data/spec/public/directory_structure/directory/app/controllers/base.rb +13 -0
  232. data/spec/public/directory_structure/directory/app/controllers/custom.rb +19 -0
  233. data/spec/public/directory_structure/directory/app/views/base/template.html.erb +1 -0
  234. data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +1 -0
  235. data/spec/public/directory_structure/directory/config/router.rb +3 -0
  236. data/spec/public/directory_structure/directory/log/merb_test.log +562 -0
  237. data/spec/public/directory_structure/directory_spec.rb +44 -0
  238. data/spec/public/logger/logger_spec.rb +181 -0
  239. data/spec/public/logger/spec_helper.rb +1 -0
  240. data/spec/public/reloading/directory/app/controllers/application.rb +3 -0
  241. data/spec/public/reloading/directory/app/controllers/reload.rb +6 -0
  242. data/spec/public/reloading/directory/config/init.rb +2 -0
  243. data/spec/public/reloading/directory/log/merb_test.log +138 -0
  244. data/spec/public/reloading/reload_spec.rb +103 -0
  245. data/spec/public/request/multipart_spec.rb +41 -0
  246. data/spec/public/request/request_spec.rb +228 -0
  247. data/spec/public/router/default_spec.rb +21 -0
  248. data/spec/public/router/deferred_spec.rb +22 -0
  249. data/spec/public/router/fixation_spec.rb +27 -0
  250. data/spec/public/router/fixture/log/merb_test.log +1556 -0
  251. data/spec/public/router/namespace_spec.rb +113 -0
  252. data/spec/public/router/nested_matches_spec.rb +97 -0
  253. data/spec/public/router/nested_resources_spec.rb +41 -0
  254. data/spec/public/router/resource_spec.rb +37 -0
  255. data/spec/public/router/resources_spec.rb +82 -0
  256. data/spec/public/router/spec_helper.rb +90 -0
  257. data/spec/public/router/special_spec.rb +61 -0
  258. data/spec/public/router/string_spec.rb +61 -0
  259. data/spec/public/template/template_spec.rb +104 -0
  260. data/spec/public/template/templates/error.html.erb +2 -0
  261. data/spec/public/template/templates/template.html.erb +1 -0
  262. data/spec/public/template/templates/template.html.myt +1 -0
  263. data/spec/public/test/controller_matchers_spec.rb +402 -0
  264. data/spec/public/test/controllers/controller_assertion_mock.rb +7 -0
  265. data/spec/public/test/controllers/dispatch_controller.rb +11 -0
  266. data/spec/public/test/controllers/spec_helper_controller.rb +38 -0
  267. data/spec/public/test/multipart_request_helper_spec.rb +159 -0
  268. data/spec/public/test/multipart_upload_text_file.txt +1 -0
  269. data/spec/public/test/request_helper_spec.rb +221 -0
  270. data/spec/public/test/route_helper_spec.rb +71 -0
  271. data/spec/public/test/route_matchers_spec.rb +162 -0
  272. data/spec/public/test/view_helper_spec.rb +96 -0
  273. data/spec/public/test/view_matchers_spec.rb +183 -0
  274. data/spec/spec_helper.rb +68 -0
  275. metadata +493 -41
  276. data/README.txt +0 -3
  277. data/lib/extlib.rb +0 -32
  278. data/lib/extlib/assertions.rb +0 -8
  279. data/lib/extlib/blank.rb +0 -42
  280. data/lib/extlib/class.rb +0 -175
  281. data/lib/extlib/hash.rb +0 -410
  282. data/lib/extlib/hook.rb +0 -366
  283. data/lib/extlib/inflection.rb +0 -141
  284. data/lib/extlib/lazy_array.rb +0 -106
  285. data/lib/extlib/mash.rb +0 -143
  286. data/lib/extlib/module.rb +0 -37
  287. data/lib/extlib/object.rb +0 -165
  288. data/lib/extlib/object_space.rb +0 -13
  289. data/lib/extlib/pathname.rb +0 -5
  290. data/lib/extlib/pooling.rb +0 -233
  291. data/lib/extlib/rubygems.rb +0 -38
  292. data/lib/extlib/simple_set.rb +0 -39
  293. data/lib/extlib/string.rb +0 -132
  294. data/lib/extlib/struct.rb +0 -8
  295. data/lib/extlib/tasks/release.rb +0 -9
  296. data/lib/extlib/time.rb +0 -12
  297. data/lib/extlib/version.rb +0 -3
  298. data/lib/extlib/virtual_file.rb +0 -10
@@ -0,0 +1,33 @@
1
+ module Merb
2
+ module Test
3
+ module RouteHelper
4
+ include RequestHelper
5
+
6
+ # Mimics the url method available to controllers.
7
+ #
8
+ # ==== Parameters
9
+ # name<~to_sym>:: The name of the URL to generate.
10
+ # params<Hash>:: Parameters for the route generation.
11
+ #
12
+ # ==== Returns
13
+ # String:: The generated URL.
14
+ def url(name, params={})
15
+ Merb::Router.generate(name, params)
16
+ end
17
+
18
+ # ==== Parameters
19
+ # path<~to_string>:: The URL of the request.
20
+ # method<~to_sym>:: HTTP request method.
21
+ # env<Hash>:: Additional parameters for the request.
22
+ #
23
+ # ==== Returns
24
+ # Hash:: A hash containing the controller and action along with any parameters
25
+ def request_to(path, method = :get, env = {})
26
+ env[:request_method] ||= method.to_s.upcase
27
+ env[:request_uri] = path
28
+
29
+ check_request_for_route(fake_request(env))
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,121 @@
1
+ module Merb
2
+ module Test
3
+ module ViewHelper
4
+
5
+ # Small utility class for working with the Hpricot parser class
6
+ class DocumentOutput
7
+
8
+ # ==== Parameters
9
+ # response_body<String>:: The response body to parse with Hpricot.
10
+ def initialize(response_body)
11
+ @parser = Hpricot.parse(response_body)
12
+ end
13
+
14
+ # ==== Parameters
15
+ # css_query<String>::
16
+ # A CSS query to find the element for, e.g. "ul.links".
17
+ #
18
+ # ==== Returns
19
+ # String:: The content of the first tag matching the query.
20
+ def content_for(css_query)
21
+ match = @parser.search(css_query).first
22
+ match.inner_text unless match.nil?
23
+ end
24
+
25
+ # ==== Parameters
26
+ # css_query<String>:: A CSS query to find the elements for.
27
+ #
28
+ # ==== Returns
29
+ # Array[String]:: Content of all tags matching the query.
30
+ def content_for_all(css_query)
31
+ matches = @parser.search(css_query).collect{|ele| ele.inner_text}
32
+ end
33
+
34
+ # ==== Parameters
35
+ # css_query<String>:: A CSS query to find the elements for.
36
+ #
37
+ # ==== Returns
38
+ # Hpricot::Elements:: All tags matching the query.
39
+ def [](css_query)
40
+ @parser.search(css_query)
41
+ end
42
+ end
43
+
44
+ # ==== Parameters
45
+ # css_query<String>:: A CSS query to find the element for.
46
+ # output<DocumentOutput>::
47
+ # The output to look for the element in. Defaults to process_output.
48
+ #
49
+ # ==== Returns
50
+ # String:: The content of the first tag matching the query.
51
+ def tag(css_query, output = process_output)
52
+ output.content_for(css_query)
53
+ end
54
+
55
+ # ==== Parameters
56
+ # css_query<String>:: A CSS query to find the elements for.
57
+ # output<DocumentOutput>::
58
+ # The output to look for the element in. Defaults to process_output.
59
+ #
60
+ # ==== Returns
61
+ # Array[String]:: Content of all tags matching the query.
62
+ def tags(css_query, output = process_output)
63
+ output.content_for_all(css_query)
64
+ end
65
+
66
+ # ==== Parameters
67
+ # css_query<String>:: A CSS query to find the element for.
68
+ # output<DocumentOutput>::
69
+ # The output to look for the element in. Defaults to process_output.
70
+ #
71
+ # ==== Returns
72
+ # Hpricot::Elem:: The first tag matching the query.
73
+ def element(css_query, output = process_output)
74
+ output[css_query].first
75
+ end
76
+
77
+ # ==== Parameters
78
+ # css_query<String>:: A CSS query to find the elements for.
79
+ # output<DocumentOutput>::
80
+ # The output to look for the elements in. Defaults to process_output.
81
+ #
82
+ # ==== Returns
83
+ # Array[Hpricot::Elem]:: All tags matching the query.
84
+ def elements(css_query, output = process_output)
85
+ Hpricot::Elements[*css_query.to_s.split(",").map{|s| s.strip}.map do |query|
86
+ output[query]
87
+ end.flatten]
88
+ end
89
+
90
+ # ==== Parameters
91
+ # css_query<String>:: A CSS query to find the elements for.
92
+ # text<String, Regexp>:: A pattern to match tag contents for.
93
+ # output<DocumentOutput>::
94
+ # The output to look for the elements in. Defaults to process_output.
95
+ #
96
+ # ==== Returns
97
+ # Array[Hpricot::Elem]:: All tags matching the query and pattern.
98
+ def get_elements(css_query, text, output = nil)
99
+ els = elements(*[css_query, output].compact)
100
+ case text
101
+ when String then els.reject {|t| !t.contains?(text) }
102
+ when Regexp then els.reject {|t| !t.matches?(text) }
103
+ else []
104
+ end
105
+ end
106
+
107
+ protected
108
+
109
+ # ==== Returns
110
+ # DocumentOutput:: Document output from the response body.
111
+ def process_output
112
+ return @output unless @output.nil?
113
+ return @output = DocumentOutput.new(@response_output) unless @response_output.nil?
114
+
115
+ raise "The response output was not in its usual places, please provide the output" if @controller.nil? || @controller.body.empty?
116
+ @response_output = @controller.body
117
+ @output = DocumentOutput.new(@controller.body)
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,9 @@
1
+ module Merb::Test::Rspec; end
2
+
3
+ require "merb-core/test/matchers/controller_matchers"
4
+ require "merb-core/test/matchers/route_matchers"
5
+ require "merb-core/test/matchers/view_matchers"
6
+
7
+ Merb::Test::ControllerHelper.send(:include, Merb::Test::Rspec::ControllerMatchers)
8
+ Merb::Test::RouteHelper.send(:include, Merb::Test::Rspec::RouteMatchers)
9
+ Merb::Test::ViewHelper.send(:include, Merb::Test::Rspec::ViewMatchers)
@@ -0,0 +1,319 @@
1
+ module Merb::Test::Rspec::ControllerMatchers
2
+
3
+ class BeRedirect
4
+
5
+ # ==== Parameters
6
+ # target<Fixnum, ~status>::
7
+ # Either the status code or a controller with a status code.
8
+ #
9
+ # ==== Returns
10
+ # Boolean:: True if the status code is in the range 300..305 or 307.
11
+ def matches?(target)
12
+ @target = target
13
+ [307, *(300..305)].include?(target.respond_to?(:status) ? target.status : target)
14
+ end
15
+
16
+ # ==== Returns
17
+ # String:: The failure message.
18
+ def failure_message
19
+ "expected#{inspect_target} to redirect"
20
+ end
21
+
22
+ # ==== Returns
23
+ # String:: The failure message to be displayed in negative matches.
24
+ def negative_failure_message
25
+ "expected#{inspect_target} not to redirect"
26
+ end
27
+
28
+ # ==== Returns
29
+ # String:: The controller and action name.
30
+ def inspect_target
31
+ " #{@target.controller_name}##{@target.action_name}" if @target.respond_to?(:controller_name) && @target.respond_to?(:action_name)
32
+ end
33
+ end
34
+
35
+ class RedirectTo
36
+
37
+ # === Parameters
38
+ # String:: The expected location
39
+ def initialize(expected)
40
+ @expected = expected
41
+ end
42
+
43
+ # ==== Parameters
44
+ # target<Merb::Controller>:: The controller to match
45
+ #
46
+ # ==== Returns
47
+ # Boolean::
48
+ # True if the controller status is redirect and the locations match.
49
+ def matches?(target)
50
+ @target, @location = target, target.headers['Location']
51
+ @redirected = BeRedirect.new.matches?(target.status)
52
+ @location == @expected && @redirected
53
+ end
54
+
55
+ # ==== Returns
56
+ # String:: The failure message.
57
+ def failure_message
58
+ msg = "expected #{inspect_target} to redirect to <#{@expected}>, but "
59
+ if @redirected
60
+ msg << "was <#{target_location}>"
61
+ else
62
+ msg << "there was no redirection"
63
+ end
64
+ end
65
+
66
+ # ==== Returns
67
+ # String:: The failure message to be displayed in negative matches.
68
+ def negative_failure_message
69
+ "expected #{inspect_target} not to redirect to <#{@expected}>, but did anyway"
70
+ end
71
+
72
+ # ==== Returns
73
+ # String:: The controller and action name.
74
+ def inspect_target
75
+ "#{@target.controller_name}##{@target.action_name}"
76
+ end
77
+
78
+ # ==== Returns
79
+ # String:: Either the target's location header or the target itself.
80
+ def target_location
81
+ @target.respond_to?(:headers) ? @target.headers['Location'] : @target
82
+ end
83
+ end
84
+
85
+ class BeSuccess
86
+
87
+ # ==== Parameters
88
+ # target<Fixnum, ~status>::
89
+ # Either the status code or a controller with a status code.
90
+ #
91
+ # ==== Returns
92
+ # Boolean:: True if the status code is in the range 200..207.
93
+ def matches?(target)
94
+ @target = target
95
+ (200..207).include?(status_code)
96
+ end
97
+
98
+ # ==== Returns
99
+ # String:: The failure message.
100
+ def failure_message
101
+ "expected#{inspect_target} to be successful but was #{status_code}"
102
+ end
103
+
104
+ # ==== Returns
105
+ # String:: The failure message to be displayed in negative matches.
106
+ def negative_failure_message
107
+ "expected#{inspect_target} not to be successful but it was #{status_code}"
108
+ end
109
+
110
+ # ==== Returns
111
+ # String:: The controller and action name.
112
+ def inspect_target
113
+ " #{@target.controller_name}##{@target.action_name}" if @target.respond_to?(:controller_name) && @target.respond_to?(:action_name)
114
+ end
115
+
116
+ # ==== Returns
117
+ # Fixnum:: Either the target's status or the target itself.
118
+ def status_code
119
+ @target.respond_to?(:status) ? @target.status : @target
120
+ end
121
+ end
122
+
123
+ class BeMissing
124
+
125
+ # ==== Parameters
126
+ # target<Fixnum, ~status>::
127
+ # Either the status code or a controller with a status code.
128
+ #
129
+ # ==== Returns
130
+ # Boolean:: True if the status code is in the range 400..417.
131
+ def matches?(target)
132
+ @target = target
133
+ (400..417).include?(status_code)
134
+ end
135
+
136
+ # ==== Returns
137
+ # String:: The failure message.
138
+ def failure_message
139
+ "expected#{inspect_target} to be missing but was #{status_code}"
140
+ end
141
+
142
+ # ==== Returns
143
+ # String:: The failure message to be displayed in negative matches.
144
+ def negative_failure_message
145
+ "expected#{inspect_target} not to be missing but it was #{status_code}"
146
+ end
147
+
148
+ # ==== Returns
149
+ # String:: The controller and action name.
150
+ def inspect_target
151
+ " #{@target.controller_name}##{@target.action_name}" if @target.respond_to?(:controller_name) && @target.respond_to?(:action_name)
152
+ end
153
+
154
+ # ==== Returns
155
+ # Fixnum:: Either the target's status or the target itself.
156
+ def status_code
157
+ @target.respond_to?(:status) ? @target.status : @target
158
+ end
159
+ end
160
+
161
+ class Provide
162
+
163
+ # === Parameters
164
+ # expected<Symbol>:: A format to check
165
+ def initialize(expected)
166
+ @expected = expected
167
+ end
168
+
169
+ # ==== Parameters
170
+ # target<Symbol>::
171
+ # A ControllerClass or controller_instance
172
+ #
173
+ # ==== Returns
174
+ # Boolean:: True if the formats provided by the target controller/class include the expected
175
+ def matches?(target)
176
+ @target = target
177
+ provided_formats.include?( @expected )
178
+ end
179
+
180
+ # ==== Returns
181
+ # String:: The failure message.
182
+ def failure_message
183
+ "expected #{@target.name} to provide #{@expected}, but it doesn't"
184
+ end
185
+
186
+ # ==== Returns
187
+ # String:: The failure message to be displayed in negative matches.
188
+ def negative_failure_message
189
+ "expected #{@target.name} not to provide #{@expected}, but it does"
190
+ end
191
+
192
+ # ==== Returns
193
+ # Array[Symbol]:: The formats the expected provides
194
+ def provided_formats
195
+ @target.class_provided_formats
196
+ end
197
+ end
198
+
199
+ # Passes if the target was redirected, or the target is a redirection (300
200
+ # level) response code.
201
+ #
202
+ # ==== Examples
203
+ # # Passes if the controller was redirected
204
+ # controller.should redirect
205
+ #
206
+ # # Also works if the target is the response code
207
+ # controller.status.should redirect
208
+ #
209
+ # ==== Notes
210
+ # valid HTTP Redirection codes:
211
+ # * 300: Multiple Choices
212
+ # * 301: Moved Permanently
213
+ # * 302: Moved Temporarily (HTTP/1.0)
214
+ # * 302: Found (HTTP/1.1)
215
+ # * 303: See Other (HTTP/1.1)
216
+ # * 304: Not Modified
217
+ # * 305: Use Proxy
218
+ # * 307: Temporary Redirect
219
+ #--
220
+ # status codes based on: http://cheat.errtheblog.com/s/http_status_codes/
221
+ def redirect
222
+ BeRedirect.new
223
+ end
224
+
225
+ alias_method :be_redirection, :redirect
226
+
227
+ # Passes if the target was redirected to the expected location.
228
+ #
229
+ # ==== Paramters
230
+ # expected<String>:: A relative or absolute url.
231
+ #
232
+ # ==== Examples
233
+ # # Passes if the controller was redirected to http://example.com/
234
+ # controller.should redirect_to('http://example.com/')
235
+ def redirect_to(expected)
236
+ RedirectTo.new(expected)
237
+ end
238
+
239
+ alias_method :be_redirection_to, :redirect_to
240
+
241
+ # Passes if the request that generated the target was successful, or the
242
+ # target is a success (200 level) response code.
243
+ #
244
+ # ==== Examples
245
+ # # Passes if the controller call was successful
246
+ # controller.should respond_successfully
247
+ #
248
+ # # Also works if the target is the response code
249
+ # controller.status.should respond_successfully
250
+ #
251
+ # ==== Notes
252
+ # valid HTTP Success codes:
253
+ # * 200: OK
254
+ # * 201: Created
255
+ # * 202: Accepted
256
+ # * 203: Non-Authoritative Information
257
+ # * 204: No Content
258
+ # * 205: Reset Content
259
+ # * 206: Partial Content
260
+ # * 207: Multi-Status
261
+ #--
262
+ # status codes based on: http://cheat.errtheblog.com/s/http_status_codes/
263
+ def respond_successfully
264
+ BeSuccess.new
265
+ end
266
+
267
+ alias_method :be_successful, :respond_successfully
268
+
269
+ # Passes if the request that generated the target was missing, or the target
270
+ # is a client-side error (400 level) response code.
271
+ #
272
+ # ==== Examples
273
+ # # Passes if the controller call was unknown or not understood
274
+ # controller.should be_missing
275
+ #
276
+ # # Also passes if the target is a response code
277
+ # controller.status.should be_missing
278
+ #
279
+ # ==== Notes
280
+ # valid HTTP Client Error codes:
281
+ # * 400: Bad Request
282
+ # * 401: Unauthorized
283
+ # * 402: Payment Required
284
+ # * 403: Forbidden
285
+ # * 404: Not Found
286
+ # * 405: Method Not Allowed
287
+ # * 406: Not Acceptable
288
+ # * 407: Proxy Authentication Required
289
+ # * 408: Request Timeout
290
+ # * 409: Conflict
291
+ # * 410: Gone
292
+ # * 411: Length Required
293
+ # * 412: Precondition Failed
294
+ # * 413: Request Entity Too Large
295
+ # * 414: Request-URI Too Long
296
+ # * 415: Unsupported Media Type
297
+ # * 416: Requested Range Not Satisfiable
298
+ # * 417: Expectation Failed
299
+ # * 422: Unprocessable Entity
300
+ #--
301
+ # status codes based on: http://cheat.errtheblog.com/s/http_status_codes/
302
+ def be_missing
303
+ BeMissing.new
304
+ end
305
+
306
+ alias_method :be_client_error, :be_missing
307
+
308
+ # Passes if the controller actually provides the target format
309
+ #
310
+ # === Parameters
311
+ # expected<Symbol>:: A format to check
312
+ #
313
+ # ==== Examples
314
+ # ControllerClass.should provide( :html )
315
+ # controller_instance.should provide( :xml )
316
+ def provide( expected )
317
+ Provide.new( expected )
318
+ end
319
+ end