thorero 0.9.4.4 → 0.9.4.5

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 (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,136 @@
1
+ module Merb::Test::Rspec::RouteMatchers
2
+
3
+ class RouteToMatcher
4
+
5
+ # ==== Parameters
6
+ # klass_or_name<Class, String>::
7
+ # The controller class or class name to match routes for.
8
+ # action<~to_s>:: The name of the action to match routes for.
9
+ def initialize(klass_or_name, action)
10
+ @expected_controller = Class === klass_or_name ? klass_or_name.name : klass_or_name
11
+ @expected_action = action.to_s
12
+ end
13
+
14
+ # ==== Parameters
15
+ # target<Hash>:: The route parameters to match.
16
+ #
17
+ # ==== Returns
18
+ # Boolean:: True if the controller action and parameters match.
19
+ def matches?(target)
20
+ @target_env = target.dup
21
+ @target_controller, @target_action = @target_env.delete(:controller).to_s, @target_env.delete(:action).to_s
22
+
23
+ @target_controller = "#{target.delete(:namespace)}::#{@target_controller}" if target.has_key?(:namespace)
24
+
25
+ @expected_controller.snake_case == @target_controller.snake_case && @expected_action == @target_action && match_parameters(@target_env)
26
+ end
27
+
28
+ # ==== Parameters
29
+ # target<Hash>:: The route parameters to match.
30
+ #
31
+ # ==== Returns
32
+ # Boolean::
33
+ # True if the parameter matcher created with #with matches or if no
34
+ # parameter matcher exists.
35
+ def match_parameters(target)
36
+ @parameter_matcher.nil? ? true : @parameter_matcher.matches?(target)
37
+ end
38
+
39
+ # Creates a new paramter matcher.
40
+ #
41
+ # ==== Parameters
42
+ # parameters<Hash, ~to_param>:: The parameters to match.
43
+ #
44
+ # ==== Returns
45
+ # RouteToMatcher:: This matcher.
46
+ #
47
+ # ==== Alternatives
48
+ # If parameters is an object, then a new expected hash will be constructed
49
+ # with the key :id set to parameters.to_param.
50
+ def with(parameters)
51
+ @parameter_matcher = ParameterMatcher.new(parameters)
52
+
53
+ self
54
+ end
55
+
56
+ # ==== Returns
57
+ # String:: The failure message.
58
+ def failure_message
59
+ "expected the request to route to #{@expected_controller.camel_case}##{@expected_action}#{expected_parameters_message}, but was #{@target_controller.camel_case}##{@target_action}#{actual_parameters_message}"
60
+ end
61
+
62
+ # ==== Returns
63
+ # String:: The failure message to be displayed in negative matches.
64
+ def negative_failure_message
65
+ "expected the request not to route to #{@expected_controller.camel_case}##{@expected_action}#{expected_parameters_message}, but it did"
66
+ end
67
+
68
+ def expected_parameters_message
69
+ " with #{@parameter_matcher.expected.inspect}" if @parameter_matcher
70
+ end
71
+
72
+ def actual_parameters_message
73
+ " with #{(@parameter_matcher.actual || {}).inspect}" if @parameter_matcher
74
+ end
75
+ end
76
+
77
+ class ParameterMatcher
78
+ attr_accessor :expected, :actual
79
+
80
+ # ==== Parameters
81
+ # hash_or_object<Hash, ~to_param>:: The parameters to match.
82
+ #
83
+ # ==== Alternatives
84
+ # If hash_or_object is an object, then a new expected hash will be
85
+ # constructed with the key :id set to hash_or_object.to_param.
86
+ def initialize(hash_or_object)
87
+ @expected = {}
88
+ case hash_or_object
89
+ when Hash then @expected = hash_or_object
90
+ else @expected[:id] = hash_or_object.to_param
91
+ end
92
+ end
93
+
94
+ # ==== Parameters
95
+ # parameter_hash<Hash>:: The route parameters to match.
96
+ #
97
+ # ==== Returns
98
+ # Boolean:: True if the route parameters match the expected ones.
99
+ def matches?(parameter_hash)
100
+ @actual = parameter_hash.dup.except(:controller, :action)
101
+
102
+ @expected.all? {|(k, v)| @actual.has_key?(k) && @actual[k] == v}
103
+ end
104
+
105
+ # ==== Returns
106
+ # String:: The failure message.
107
+ def failure_message
108
+ "expected the route to contain parameters #{@expected.inspect}, but instead contained #{@actual.inspect}"
109
+ end
110
+
111
+ # ==== Returns
112
+ # String:: The failure message to be displayed in negative matches.
113
+ def negative_failure_message
114
+ "expected the route not to contain parameters #{@expected.inspect}, but it did"
115
+ end
116
+ end
117
+
118
+ # Passes when the actual route parameters match the expected controller class
119
+ # and controller action. Exposes a +with+ method for specifying parameters.
120
+ #
121
+ # ==== Parameters
122
+ # klass_or_name<Class, String>::
123
+ # The controller class or class name to match routes for.
124
+ # action<~to_s>:: The name of the action to match routes for.
125
+ #
126
+ # ==== Example
127
+ # # Passes if a GET request to "/" is routed to the Widgets controller's
128
+ # # index action.
129
+ # request_to("/", :get).should route_to(Widgets, :index)
130
+ #
131
+ # # Use the 'with' method for parameter checks
132
+ # request_to("/123").should route_to(widgets, :show).with(:id => "123")
133
+ def route_to(klass_or_name, action)
134
+ RouteToMatcher.new(klass_or_name, action)
135
+ end
136
+ end
@@ -0,0 +1,335 @@
1
+ module Merb::Test::Rspec::ViewMatchers
2
+ class HaveSelector
3
+
4
+ # ==== Parameters
5
+ # expected<String>:: The string to look for.
6
+ def initialize(expected)
7
+ @expected = expected
8
+ end
9
+
10
+ # ==== Parameters
11
+ # stringlike<Hpricot::Elem, StringIO, String>:: The thing to search in.
12
+ #
13
+ # ==== Returns
14
+ # Boolean:: True if there was at least one match.
15
+ def matches?(stringlike)
16
+ @document = case stringlike
17
+ when Hpricot::Elem
18
+ stringlike
19
+ when StringIO
20
+ Hpricot.parse(stringlike.string)
21
+ else
22
+ Hpricot.parse(stringlike)
23
+ end
24
+ !@document.search(@expected).empty?
25
+ end
26
+
27
+ # ==== Returns
28
+ # String:: The failure message.
29
+ def failure_message
30
+ "expected following text to match selector #{@expected}:\n#{@document}"
31
+ end
32
+
33
+ # ==== Returns
34
+ # String:: The failure message to be displayed in negative matches.
35
+ def negative_failure_message
36
+ "expected following text to not match selector #{@expected}:\n#{@document}"
37
+ end
38
+ end
39
+
40
+ class MatchTag
41
+
42
+ # ==== Parameters
43
+ # name<~to_s>:: The name of the tag to look for.
44
+ # attrs<Hash>:: Attributes to look for in the tag (see below).
45
+ #
46
+ # ==== Options (attrs)
47
+ # :content<String>:: Optional content to match.
48
+ def initialize(name, attrs)
49
+ @name, @attrs = name, attrs
50
+ @content = @attrs.delete(:content)
51
+ end
52
+
53
+ # ==== Parameters
54
+ # target<String>:: The string to look for the tag in.
55
+ #
56
+ # ==== Returns
57
+ # Boolean:: True if the tag matched.
58
+ def matches?(target)
59
+ @errors = []
60
+ unless target.include?("<#{@name}")
61
+ @errors << "Expected a <#{@name}>, but was #{target}"
62
+ end
63
+ @attrs.each do |attr, val|
64
+ unless target.include?("#{attr}=\"#{val}\"")
65
+ @errors << "Expected #{attr}=\"#{val}\", but was #{target}"
66
+ end
67
+ end
68
+ if @content
69
+ unless target.include?(">#{@content}<")
70
+ @errors << "Expected #{target} to include #{@content}"
71
+ end
72
+ end
73
+ @errors.size == 0
74
+ end
75
+
76
+ # ==== Returns
77
+ # String:: The failure message.
78
+ def failure_message
79
+ @errors[0]
80
+ end
81
+
82
+ # ==== Returns
83
+ # String:: The failure message to be displayed in negative matches.
84
+ def negative_failure_message
85
+ "Expected not to match against <#{@name} #{@attrs.map{ |a,v| "#{a}=\"#{v}\"" }.join(" ")}> tag, but it matched"
86
+ end
87
+ end
88
+
89
+ class NotMatchTag
90
+
91
+ # === Parameters
92
+ # attrs<Hash>:: A set of attributes that must not be matched.
93
+ def initialize(attrs)
94
+ @attrs = attrs
95
+ end
96
+
97
+ # ==== Parameters
98
+ # target<String>:: The target to look for the match in.
99
+ #
100
+ # ==== Returns
101
+ # Boolean:: True if none of the attributes were matched.
102
+ def matches?(target)
103
+ @errors = []
104
+ @attrs.each do |attr, val|
105
+ if target.include?("#{attr}=\"#{val}\"")
106
+ @errors << "Should not include #{attr}=\"#{val}\", but was #{target}"
107
+ end
108
+ end
109
+ @errors.size == 0
110
+ end
111
+
112
+ # ==== Returns
113
+ # String:: The failure message.
114
+ def failure_message
115
+ @errors[0]
116
+ end
117
+ end
118
+
119
+ class HasTag
120
+
121
+ # ==== Parameters
122
+ # tag<~to_s>:: The tag to look for.
123
+ # attributes<Hash>:: Attributes for the tag (see below).
124
+ def initialize(tag, attributes = {}, &blk)
125
+ @tag, @attributes = tag, attributes
126
+ @id, @class = @attributes.delete(:id), @attributes.delete(:class)
127
+ @blk = blk
128
+ end
129
+
130
+ # ==== Parameters
131
+ # stringlike<Hpricot::Elem, StringIO, String>:: The thing to search in.
132
+ # &blk:: An optional block for searching in child elements using with_tag.
133
+ #
134
+ # ==== Returns
135
+ # Boolean:: True if there was at least one match.
136
+ def matches?(stringlike, &blk)
137
+ @document = case stringlike
138
+ when Hpricot::Elem
139
+ stringlike
140
+ when StringIO
141
+ Hpricot.parse(stringlike.string)
142
+ else
143
+ Hpricot.parse(stringlike)
144
+ end
145
+
146
+ @blk = blk unless blk.nil?
147
+
148
+ unless @blk.nil?
149
+ !@document.search(selector).select do |ele|
150
+ @blk.call ele
151
+ true
152
+ end.empty?
153
+ else
154
+ !@document.search(selector).empty?
155
+ end
156
+ end
157
+
158
+ # ==== Returns
159
+ # String:: The complete selector for element queries.
160
+ def selector
161
+ @selector = "//#{@tag}#{id_selector}#{class_selector}"
162
+ @selector << @attributes.map{|a, v| "[@#{a}=\"#{v}\"]"}.join
163
+
164
+ @selector << @inner_has_tag.selector unless @inner_has_tag.nil?
165
+
166
+ @selector
167
+ end
168
+
169
+ # ==== Returns
170
+ # String:: ID selector for use in element queries.
171
+ def id_selector
172
+ "##{@id}" if @id
173
+ end
174
+
175
+ # ==== Returns
176
+ # String:: Class selector for use in element queries.
177
+ def class_selector
178
+ ".#{@class}" if @class
179
+ end
180
+
181
+ # ==== Returns
182
+ # String:: The failure message.
183
+ def failure_message
184
+ "expected following output to contain a #{tag_for_error} tag:\n#{@document}"
185
+ end
186
+
187
+ # ==== Returns
188
+ # String:: The failure message to be displayed in negative matches.
189
+ def negative_failure_message
190
+ "expected following output to omit a #{tag_for_error} tag:\n#{@document}"
191
+ end
192
+
193
+ # ==== Returns
194
+ # String:: The tag used in failure messages.
195
+ def tag_for_error
196
+ "#{inner_failure_message}<#{@tag}#{id_for_error}#{class_for_error}#{attributes_for_error}>"
197
+ end
198
+
199
+ # ==== Returns
200
+ # String::
201
+ # The failure message to be displayed in negative matches within the
202
+ # have_tag block.
203
+ def inner_failure_message
204
+ "#{@inner_has_tag.tag_for_error} tag within a " unless @inner_has_tag.nil?
205
+ end
206
+
207
+ # ==== Returns
208
+ # String:: ID for the error tag.
209
+ def id_for_error
210
+ " id=\"#{@id}\"" unless @id.nil?
211
+ end
212
+
213
+ # ==== Returns
214
+ # String:: Class for the error tag.
215
+ def class_for_error
216
+ " class=\"#{@class}\"" unless @class.nil?
217
+ end
218
+
219
+ # ==== Returns
220
+ # String:: Class for the error tag.
221
+ def attributes_for_error
222
+ @attributes.map{|a,v| " #{a}=\"#{v}\""}.join
223
+ end
224
+
225
+ # Search for a child tag within a have_tag block.
226
+ #
227
+ # ==== Parameters
228
+ # tag<~to_s>:: The tag to look for.
229
+ # attributes<Hash>:: Attributes for the tag (see below).
230
+ def with_tag(name, attrs={})
231
+ @inner_has_tag = HasTag.new(name, attrs)
232
+ end
233
+ end
234
+
235
+ class HasContent
236
+ def initialize(content)
237
+ @content = content
238
+ end
239
+
240
+ def matches?(element)
241
+ @element = element
242
+
243
+ case @content
244
+ when String
245
+ @element.contains?(@content)
246
+ when Regexp
247
+ @element.matches?(@content)
248
+ end
249
+ end
250
+
251
+ # ==== Returns
252
+ # String:: The failure message.
253
+ def failure_message
254
+ "expected the following element's content to #{content_message}:\n#{@element.inner_text}"
255
+ end
256
+
257
+ # ==== Returns
258
+ # String:: The failure message to be displayed in negative matches.
259
+ def negative_failure_message
260
+ "expected the following element's content to not #{content_message}:\n#{@element.inner_text}"
261
+ end
262
+
263
+ def content_message
264
+ case @content
265
+ when String
266
+ "include \"#{@content}\""
267
+ when Regexp
268
+ "match #{@content.inspect}"
269
+ end
270
+ end
271
+ end
272
+
273
+ # ==== Parameters
274
+ # name<~to_s>:: The name of the tag to look for.
275
+ # attrs<Hash>:: Attributes to look for in the tag (see below).
276
+ #
277
+ # ==== Options (attrs)
278
+ # :content<String>:: Optional content to match.
279
+ #
280
+ # ==== Returns
281
+ # MatchTag:: A new match tag matcher.
282
+ def match_tag(name, attrs={})
283
+ MatchTag.new(name, attrs)
284
+ end
285
+
286
+ # ==== Parameters
287
+ # attrs<Hash>:: A set of attributes that must not be matched.
288
+ #
289
+ # ==== Returns
290
+ # NotMatchTag:: A new not match tag matcher.
291
+ def not_match_tag(attrs)
292
+ NotMatchTag.new(attrs)
293
+ end
294
+
295
+ # ==== Parameters
296
+ # expected<String>:: The string to look for.
297
+ #
298
+ # ==== Returns
299
+ # HaveSelector:: A new have selector matcher.
300
+ def have_selector(expected)
301
+ HaveSelector.new(expected)
302
+ end
303
+ alias_method :match_selector, :have_selector
304
+
305
+ # RSpec matcher to test for the presence of tags.
306
+ #
307
+ # ==== Parameters
308
+ # tag<~to_s>:: The name of the tag.
309
+ # attributes<Hash>:: Tag attributes.
310
+ #
311
+ # ==== Returns
312
+ # HasTag:: A new has tag matcher.
313
+ #
314
+ # ==== Examples
315
+ # # Check for <div>
316
+ # body.should have_tag("div")
317
+ #
318
+ # # Check for <span id="notice">
319
+ # body.should have_tag("span", :id => :notice)
320
+ #
321
+ # # Check for <h1 id="foo" class="bar">
322
+ # body.should have_tag(:h2, :class => "bar", :id => "foo")
323
+ #
324
+ # # Check for <div attr="val">
325
+ # body.should have_tag(:div, :attr => :val)
326
+ def have_tag(tag, attributes = {}, &blk)
327
+ HasTag.new(tag, attributes, &blk)
328
+ end
329
+
330
+ alias_method :with_tag, :have_tag
331
+
332
+ def contain(content)
333
+ HasContent.new(content)
334
+ end
335
+ end