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.
- data/LICENSE +1 -1
- data/README +21 -0
- data/Rakefile +275 -108
- data/TODO +0 -0
- data/bin/merb +12 -0
- data/bin/merb-specs +5 -0
- data/docs/bootloading.dox +58 -0
- data/docs/documentation_standards +40 -0
- data/docs/merb-core-call-stack-diagram.mmap +0 -0
- data/docs/merb-core-call-stack-diagram.pdf +0 -0
- data/docs/merb-core-call-stack-diagram.png +0 -0
- data/docs/new_render_api +51 -0
- data/lib/merb-core.rb +603 -0
- data/lib/merb-core/autoload.rb +32 -0
- data/lib/merb-core/bootloader.rb +708 -0
- data/lib/merb-core/config.rb +303 -0
- data/lib/merb-core/constants.rb +43 -0
- data/lib/merb-core/controller/abstract_controller.rb +578 -0
- data/lib/merb-core/controller/exceptions.rb +302 -0
- data/lib/merb-core/controller/merb_controller.rb +256 -0
- data/lib/merb-core/controller/mime.rb +106 -0
- data/lib/merb-core/controller/mixins/authentication.rb +87 -0
- data/lib/merb-core/controller/mixins/controller.rb +290 -0
- data/lib/merb-core/controller/mixins/render.rb +481 -0
- data/lib/merb-core/controller/mixins/responder.rb +472 -0
- data/lib/merb-core/controller/template.rb +254 -0
- data/lib/merb-core/core_ext.rb +8 -0
- data/lib/merb-core/core_ext/kernel.rb +319 -0
- data/lib/merb-core/dispatch/cookies.rb +91 -0
- data/lib/merb-core/dispatch/dispatcher.rb +278 -0
- data/lib/merb-core/dispatch/exceptions.html.erb +303 -0
- data/lib/merb-core/dispatch/request.rb +603 -0
- data/lib/merb-core/dispatch/router.rb +179 -0
- data/lib/merb-core/dispatch/router/behavior.rb +867 -0
- data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
- data/lib/merb-core/dispatch/router/route.rb +321 -0
- data/lib/merb-core/dispatch/session.rb +78 -0
- data/lib/merb-core/dispatch/session/cookie.rb +168 -0
- data/lib/merb-core/dispatch/session/memcached.rb +184 -0
- data/lib/merb-core/dispatch/session/memory.rb +241 -0
- data/lib/merb-core/dispatch/worker.rb +28 -0
- data/lib/merb-core/gem_ext/erubis.rb +77 -0
- data/lib/{extlib → merb-core}/logger.rb +2 -2
- data/lib/merb-core/plugins.rb +59 -0
- data/lib/merb-core/rack.rb +21 -0
- data/lib/merb-core/rack/adapter.rb +44 -0
- data/lib/merb-core/rack/adapter/ebb.rb +25 -0
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/fcgi.rb +17 -0
- data/lib/merb-core/rack/adapter/irb.rb +118 -0
- data/lib/merb-core/rack/adapter/mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/runner.rb +28 -0
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/thin.rb +39 -0
- data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
- data/lib/merb-core/rack/adapter/webrick.rb +36 -0
- data/lib/merb-core/rack/application.rb +18 -0
- data/lib/merb-core/rack/handler/mongrel.rb +97 -0
- data/lib/merb-core/rack/middleware.rb +26 -0
- data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
- data/lib/merb-core/rack/middleware/profiler.rb +19 -0
- data/lib/merb-core/rack/middleware/static.rb +45 -0
- data/lib/merb-core/server.rb +252 -0
- data/lib/merb-core/tasks/audit.rake +68 -0
- data/lib/merb-core/tasks/merb.rb +1 -0
- data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
- data/lib/merb-core/test.rb +11 -0
- data/lib/merb-core/test/helpers.rb +9 -0
- data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
- data/lib/merb-core/test/helpers/request_helper.rb +344 -0
- data/lib/merb-core/test/helpers/route_helper.rb +33 -0
- data/lib/merb-core/test/helpers/view_helper.rb +121 -0
- data/lib/merb-core/test/matchers.rb +9 -0
- data/lib/merb-core/test/matchers/controller_matchers.rb +319 -0
- data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
- data/lib/merb-core/test/matchers/view_matchers.rb +335 -0
- data/lib/merb-core/test/run_specs.rb +47 -0
- data/lib/merb-core/test/tasks/spectasks.rb +68 -0
- data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
- data/lib/merb-core/test/test_ext/object.rb +14 -0
- data/lib/merb-core/test/test_ext/string.rb +14 -0
- data/lib/merb-core/vendor/facets.rb +2 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
- data/lib/merb-core/vendor/facets/inflect.rb +345 -0
- data/lib/merb-core/version.rb +11 -0
- data/spec/private/config/adapter_spec.rb +32 -0
- data/spec/private/config/config_spec.rb +202 -0
- data/spec/private/config/environment_spec.rb +13 -0
- data/spec/private/config/spec_helper.rb +1 -0
- data/spec/private/core_ext/kernel_spec.rb +169 -0
- data/spec/private/dispatch/bootloader_spec.rb +24 -0
- data/spec/private/dispatch/cookies_spec.rb +107 -0
- data/spec/private/dispatch/dispatch_spec.rb +35 -0
- data/spec/private/dispatch/fixture/app/controllers/application.rb +4 -0
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +27 -0
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +21 -0
- data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +8 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +37 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +40 -0
- data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +11 -0
- data/spec/private/dispatch/fixture/config/black_hole.rb +12 -0
- data/spec/private/dispatch/fixture/config/environments/development.rb +6 -0
- data/spec/private/dispatch/fixture/config/environments/production.rb +5 -0
- data/spec/private/dispatch/fixture/config/environments/test.rb +6 -0
- data/spec/private/dispatch/fixture/config/init.rb +45 -0
- data/spec/private/dispatch/fixture/config/rack.rb +11 -0
- data/spec/private/dispatch/fixture/config/router.rb +35 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +1874 -0
- data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
- data/spec/private/dispatch/fixture/public/merb.fcgi +4 -0
- data/spec/private/dispatch/fixture/public/stylesheets/master.css +119 -0
- data/spec/private/dispatch/route_params_spec.rb +24 -0
- data/spec/private/dispatch/session_mixin_spec.rb +47 -0
- data/spec/private/dispatch/spec_helper.rb +1 -0
- data/spec/private/plugins/plugin_spec.rb +166 -0
- data/spec/private/rack/application_spec.rb +49 -0
- data/spec/private/router/behavior_spec.rb +60 -0
- data/spec/private/router/fixture/log/merb_test.log +139 -0
- data/spec/private/router/route_spec.rb +414 -0
- data/spec/private/router/router_spec.rb +175 -0
- data/spec/private/vendor/facets/plural_spec.rb +564 -0
- data/spec/private/vendor/facets/singular_spec.rb +489 -0
- data/spec/public/DEFINITIONS +11 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
- data/spec/public/abstract_controller/controllers/display.rb +54 -0
- data/spec/public/abstract_controller/controllers/filters.rb +193 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +41 -0
- data/spec/public/abstract_controller/controllers/partial.rb +121 -0
- data/spec/public/abstract_controller/controllers/render.rb +113 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/alt.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/custom.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +1 -0
- data/spec/public/abstract_controller/display_spec.rb +33 -0
- data/spec/public/abstract_controller/filter_spec.rb +106 -0
- data/spec/public/abstract_controller/helper_spec.rb +21 -0
- data/spec/public/abstract_controller/partial_spec.rb +61 -0
- data/spec/public/abstract_controller/render_spec.rb +90 -0
- data/spec/public/abstract_controller/spec_helper.rb +31 -0
- data/spec/public/boot_loader/boot_loader_spec.rb +33 -0
- data/spec/public/boot_loader/spec_helper.rb +1 -0
- data/spec/public/controller/authentication_spec.rb +103 -0
- data/spec/public/controller/base_spec.rb +36 -0
- data/spec/public/controller/controllers/authentication.rb +45 -0
- data/spec/public/controller/controllers/base.rb +36 -0
- data/spec/public/controller/controllers/display.rb +118 -0
- data/spec/public/controller/controllers/redirect.rb +30 -0
- data/spec/public/controller/controllers/responder.rb +93 -0
- data/spec/public/controller/controllers/url.rb +7 -0
- data/spec/public/controller/controllers/views/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +1 -0
- data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +1 -0
- data/spec/public/controller/display_spec.rb +84 -0
- data/spec/public/controller/redirect_spec.rb +27 -0
- data/spec/public/controller/responder_spec.rb +163 -0
- data/spec/public/controller/spec_helper.rb +11 -0
- data/spec/public/controller/url_spec.rb +180 -0
- data/spec/public/core/merb_core_spec.rb +45 -0
- data/spec/public/core_ext/class_spec.rb +91 -0
- data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
- data/spec/public/core_ext/kernel_spec.rb +9 -0
- data/spec/public/core_ext/spec_helper.rb +1 -0
- data/spec/public/directory_structure/directory/app/controllers/application.rb +3 -0
- data/spec/public/directory_structure/directory/app/controllers/base.rb +13 -0
- data/spec/public/directory_structure/directory/app/controllers/custom.rb +19 -0
- data/spec/public/directory_structure/directory/app/views/base/template.html.erb +1 -0
- data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +1 -0
- data/spec/public/directory_structure/directory/config/router.rb +3 -0
- data/spec/public/directory_structure/directory/log/merb_test.log +562 -0
- data/spec/public/directory_structure/directory_spec.rb +44 -0
- data/spec/public/logger/logger_spec.rb +181 -0
- data/spec/public/logger/spec_helper.rb +1 -0
- data/spec/public/reloading/directory/app/controllers/application.rb +3 -0
- data/spec/public/reloading/directory/app/controllers/reload.rb +6 -0
- data/spec/public/reloading/directory/config/init.rb +2 -0
- data/spec/public/reloading/directory/log/merb_test.log +138 -0
- data/spec/public/reloading/reload_spec.rb +103 -0
- data/spec/public/request/multipart_spec.rb +41 -0
- data/spec/public/request/request_spec.rb +228 -0
- data/spec/public/router/default_spec.rb +21 -0
- data/spec/public/router/deferred_spec.rb +22 -0
- data/spec/public/router/fixation_spec.rb +27 -0
- data/spec/public/router/fixture/log/merb_test.log +1556 -0
- data/spec/public/router/namespace_spec.rb +113 -0
- data/spec/public/router/nested_matches_spec.rb +97 -0
- data/spec/public/router/nested_resources_spec.rb +41 -0
- data/spec/public/router/resource_spec.rb +37 -0
- data/spec/public/router/resources_spec.rb +82 -0
- data/spec/public/router/spec_helper.rb +90 -0
- data/spec/public/router/special_spec.rb +61 -0
- data/spec/public/router/string_spec.rb +61 -0
- data/spec/public/template/template_spec.rb +104 -0
- data/spec/public/template/templates/error.html.erb +2 -0
- data/spec/public/template/templates/template.html.erb +1 -0
- data/spec/public/template/templates/template.html.myt +1 -0
- data/spec/public/test/controller_matchers_spec.rb +402 -0
- data/spec/public/test/controllers/controller_assertion_mock.rb +7 -0
- data/spec/public/test/controllers/dispatch_controller.rb +11 -0
- data/spec/public/test/controllers/spec_helper_controller.rb +38 -0
- data/spec/public/test/multipart_request_helper_spec.rb +159 -0
- data/spec/public/test/multipart_upload_text_file.txt +1 -0
- data/spec/public/test/request_helper_spec.rb +221 -0
- data/spec/public/test/route_helper_spec.rb +71 -0
- data/spec/public/test/route_matchers_spec.rb +162 -0
- data/spec/public/test/view_helper_spec.rb +96 -0
- data/spec/public/test/view_matchers_spec.rb +183 -0
- data/spec/spec_helper.rb +68 -0
- metadata +493 -41
- data/README.txt +0 -3
- data/lib/extlib.rb +0 -32
- data/lib/extlib/assertions.rb +0 -8
- data/lib/extlib/blank.rb +0 -42
- data/lib/extlib/class.rb +0 -175
- data/lib/extlib/hash.rb +0 -410
- data/lib/extlib/hook.rb +0 -366
- data/lib/extlib/inflection.rb +0 -141
- data/lib/extlib/lazy_array.rb +0 -106
- data/lib/extlib/mash.rb +0 -143
- data/lib/extlib/module.rb +0 -37
- data/lib/extlib/object.rb +0 -165
- data/lib/extlib/object_space.rb +0 -13
- data/lib/extlib/pathname.rb +0 -5
- data/lib/extlib/pooling.rb +0 -233
- data/lib/extlib/rubygems.rb +0 -38
- data/lib/extlib/simple_set.rb +0 -39
- data/lib/extlib/string.rb +0 -132
- data/lib/extlib/struct.rb +0 -8
- data/lib/extlib/tasks/release.rb +0 -9
- data/lib/extlib/time.rb +0 -12
- data/lib/extlib/version.rb +0 -3
- data/lib/extlib/virtual_file.rb +0 -10
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "Regex-based routes" do
|
4
|
+
|
5
|
+
it "should process a simple regex" do
|
6
|
+
prepare_route(%r[^/foos?/(bar|baz)/:id], :controller => "foo", :action => "[1]", :id => ":id")
|
7
|
+
route_to("/foo/bar/baz").should have_route(:controller => "foo", :action => "bar", :id => "baz")
|
8
|
+
route_to("/foos/baz/bam").should have_route(:controller => "foo", :action => "baz", :id => "bam")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should support inbound user agents" do
|
12
|
+
Merb::Router.prepare do |r|
|
13
|
+
r.match(%r[^/foo/(.+)], :user_agent => /(MSIE|Gecko)/).
|
14
|
+
to(:controller => "foo", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
|
15
|
+
end
|
16
|
+
route_to("/foo/bar", :user_agent => /MSIE/).should have_route(
|
17
|
+
:controller => "foo", :action => "show", :title => "bar", :agent => "MSIE"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Routes that are restricted based on incoming params" do
|
24
|
+
|
25
|
+
it "should allow you to restrict routes to POST requests" do
|
26
|
+
Merb::Router.prepare do |r|
|
27
|
+
r.match("/:controller/create/:id", :method => :post).
|
28
|
+
to(:action => "create")
|
29
|
+
end
|
30
|
+
route_to("/foo/create/12", :method => "post").should have_route(
|
31
|
+
:controller => "foo", :action => "create", :id => "12"
|
32
|
+
)
|
33
|
+
|
34
|
+
route_to("/foo/create/12", :method => "get").should_not have_route(
|
35
|
+
:controller => "foo", :action => "create", :id => "12"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should allow you to restrict routes based on protocol" do
|
40
|
+
Merb::Router.prepare do |r|
|
41
|
+
r.match(:protocol => "http://").to(:controller => "foo", :action => "bar")
|
42
|
+
r.default_routes
|
43
|
+
end
|
44
|
+
route_to("/foo/bar").should have_route(:controller => "foo", :action => "bar")
|
45
|
+
route_to("/boo/hoo", :protocol => "https://").should have_route(:controller => "boo", :action => "hoo")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "does not require explicit specifying of params" do
|
49
|
+
Merb::Router.prepare do |r|
|
50
|
+
r.match!("/fb/:callback_path/:controller/:action")
|
51
|
+
end
|
52
|
+
|
53
|
+
route_to("/fb/callybacky/products/search").should have_route(
|
54
|
+
:controller => "products", :action => "search", :callback_path => "callybacky"
|
55
|
+
)
|
56
|
+
route_to("/fb/ping/products/search").should have_route(
|
57
|
+
:controller => "products", :action => "search", :callback_path => "ping"
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "A plain route with no variables" do
|
4
|
+
|
5
|
+
it "should return the parameters passed to #to" do
|
6
|
+
prepare_route("/info", :controller => "info", :action => "foo")
|
7
|
+
route_to("/info").should have_route(:controller => "info", :action => "foo", :id => nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "A route with variables specified as :foo/:bar" do
|
13
|
+
|
14
|
+
it "should work with :controller/:action/:id" do
|
15
|
+
prepare_route("/foo/:action/:id", :controller => "foobar")
|
16
|
+
route_to("/foo/bar/baz").should have_route(:controller => "foobar", :action => "bar", :id => "baz")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should work with :foo/:bar/:baz to :controller => ':foo/:bar'" do
|
20
|
+
prepare_route("/:foo/:bar/:baz/:id", :controller => ":foo/:bar", :action => ":baz")
|
21
|
+
route_to("/one/two/three/4").should have_route(:controller => "one/two", :action => "three", :id => "4")
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "A route containing block matchers" do
|
27
|
+
|
28
|
+
it "should support block matchers as a path namespace" do
|
29
|
+
Merb::Router.prepare do |r|
|
30
|
+
r.match("/foo") do |path|
|
31
|
+
path.match("/bar/:id").to(:controller => "foo/bar", :action => "bar")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
route_to("/foo/bar/1").should have_route(:controller => "foo/bar", :action => "bar", :id => "1")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should still support :variables in the to route from any level" do
|
38
|
+
Merb::Router.prepare do |r|
|
39
|
+
r.match("/foo/:bar") do |path|
|
40
|
+
path.match("/:baz/:id").to(:controller => "foo", :action => ":id", :id => ":bar/:baz")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
route_to("/foo/hello/goodbye/zoo").should have_route(:controller => "foo", :action => "zoo", :id => "hello/goodbye")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "A route containing block matchers for the 'to' section" do
|
49
|
+
|
50
|
+
it "should point a bunch of 'from' segments to the same 'to'" do
|
51
|
+
Merb::Router.prepare do |r|
|
52
|
+
r.to(:controller => "foo") do |a|
|
53
|
+
a.match("/hello/:action/:id").to(:tag => ":id")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
route_to("/hello/goodbye/tagging").should have_route(
|
57
|
+
:controller => "foo", :action => "goodbye", :id => "tagging", :tag => "tagging"
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# ==== Public Template API
|
2
|
+
# Merb::Template.register_extensions(engine<Class>, extenstions<Array[String]>)
|
3
|
+
#
|
4
|
+
# ==== Semipublic Template API
|
5
|
+
# Merb::Template.engine_for(path<String>)
|
6
|
+
# Merb::Template.template_name(path<String>)
|
7
|
+
# Merb::Template.inline_template(path<String>, mod<Module>)
|
8
|
+
#
|
9
|
+
# ==== Requirements for a new Template Engine
|
10
|
+
# A Template Engine must have at least a single class method called compile_template
|
11
|
+
# with the following parameters:
|
12
|
+
# * path<String>:: the full path to the template being compiled
|
13
|
+
# * name<String>:: the name of the method that will be inlined
|
14
|
+
# * mod<Module>:: the module that the method will be inlined into
|
15
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
16
|
+
|
17
|
+
# A small structure to hold the templates so we can test the templating system in isolation
|
18
|
+
# from the framework
|
19
|
+
|
20
|
+
module Merb::Test::Fixtures
|
21
|
+
# This is a fake templating engine that just copies the text of the template
|
22
|
+
# exactly from the file
|
23
|
+
|
24
|
+
class MyTemplateEngine
|
25
|
+
|
26
|
+
def self.compile_template(io, name, mod)
|
27
|
+
text = io.read
|
28
|
+
table = { "\r"=>"\\r", "\n"=>"\\n", "\t"=>"\\t", '"'=>'\\"', "\\"=>"\\\\" }
|
29
|
+
text = (text.split("\n").map {|x| '"' + (x.gsub(/[\r\n\t"\\]/) { |m| table[m] }) + '"'}).join(" +\n")
|
30
|
+
mod.class_eval <<-EOS, File.expand_path(io.path)
|
31
|
+
def #{name}
|
32
|
+
#{text}
|
33
|
+
end
|
34
|
+
EOS
|
35
|
+
end
|
36
|
+
|
37
|
+
module Mixin
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module MyHelpers
|
42
|
+
end
|
43
|
+
|
44
|
+
class Environment
|
45
|
+
include MyHelpers
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe Merb::Template do
|
50
|
+
|
51
|
+
# @public
|
52
|
+
it "should accept template-type registrations via #register_extensions" do
|
53
|
+
Merb::Template.register_extensions(Merb::Test::Fixtures::MyTemplateEngine, %w[myt])
|
54
|
+
Merb::Template.engine_for("foo.myt").should == Merb::Test::Fixtures::MyTemplateEngine
|
55
|
+
Merb::Template.template_extensions.should include("myt")
|
56
|
+
end
|
57
|
+
|
58
|
+
# @semipublic
|
59
|
+
|
60
|
+
def rendering_template(template_path)
|
61
|
+
Merb::Template.inline_template(File.open(template_path), Merb::Test::Fixtures::MyHelpers)
|
62
|
+
Merb::Test::Fixtures::Environment.new.
|
63
|
+
send(Merb::Template.template_name(template_path))
|
64
|
+
end
|
65
|
+
alias_method :render_template, :rendering_template
|
66
|
+
|
67
|
+
it "should compile and inline templates via #inline methods for custom languages" do
|
68
|
+
template_path = File.dirname(__FILE__) / "templates" / "template.html.myt"
|
69
|
+
rendering_template(template_path).should == "Hello world!"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should compile and inline templates via #inline_template for erubis" do
|
73
|
+
template_path = File.dirname(__FILE__) / "templates" / "template.html.erb"
|
74
|
+
rendering_template(template_path).should == "Hello world!"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should compile and inline templates that comes through via VirtualFile" do
|
78
|
+
Merb::Template.inline_template(VirtualFile.new("Hello",
|
79
|
+
File.dirname(__FILE__) / "templates" / "template.html.erb"),
|
80
|
+
Merb::Test::Fixtures::MyHelpers)
|
81
|
+
|
82
|
+
res = Merb::Test::Fixtures::Environment.new.
|
83
|
+
send(Merb::Template.template_name(File.dirname(__FILE__) / "templates" / "template.html.erb"))
|
84
|
+
|
85
|
+
res.should == "Hello"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should know how to correctly report errors" do
|
89
|
+
template_path = File.dirname(__FILE__) / "templates" / "error.html.erb"
|
90
|
+
running { render_template(template_path) }.should raise_error(NameError, /`foo'/)
|
91
|
+
begin
|
92
|
+
render_template(template_path)
|
93
|
+
rescue Exception => e
|
94
|
+
e.backtrace.first.match(/\/([^:\/]*:\d*)/)[1].should == "error.html.erb:2"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should find the full template name for a path via #template_for" do
|
99
|
+
template_path = File.dirname(__FILE__) / "templates" / "template.html.erb"
|
100
|
+
name = Merb::Template.inline_template(File.open(template_path), Merb::Test::Fixtures::MyHelpers)
|
101
|
+
Merb::Test::Fixtures::Environment.new.should respond_to(name)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello world!
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello world!
|
@@ -0,0 +1,402 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
|
3
|
+
Merb.start :environment => 'test', :log_level => :fatal
|
4
|
+
|
5
|
+
class TestController < Merb::Controller
|
6
|
+
attr_accessor :redirect_to
|
7
|
+
def redirect_action; redirect(@redirect_to || "/"); end
|
8
|
+
def success_action; end
|
9
|
+
def missing_action; render("i can has errorz", :status => 404); end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Merb::Test::Rspec::ControllerMatchers do
|
13
|
+
include Merb::Test::ControllerHelper
|
14
|
+
before(:each) do
|
15
|
+
Merb::Router.prepare do |r|
|
16
|
+
r.match("/redirect").to(:controller => "test_controller", :action => "redirect_action")
|
17
|
+
r.match("/success").to(:controller => "test_controller", :action => "success_action")
|
18
|
+
r.match("/missing").to(:controller => "test_controller", :action => "missing_action")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#redirect" do
|
23
|
+
it "should work with the result of a dispatch_to helper call" do
|
24
|
+
dispatch_to(TestController, :redirect_action).should redirect
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should work with the result of a get helper call" do
|
28
|
+
get("/redirect").should redirect
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should work with a redirection code" do
|
32
|
+
dispatch_to(TestController, :redirect_action).status.should redirect
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#redirect_to" do
|
37
|
+
it "should work with the result of a dispatch_to helper call" do
|
38
|
+
dispatch_to(TestController, :redirect_action).should redirect_to("/")
|
39
|
+
dispatch_to(TestController, :redirect_action){ |controller| controller.redirect_to = "http://example.com/" }.should redirect_to("http://example.com/")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should work with the result of a get helper call" do
|
43
|
+
get("/redirect"){|controller| controller.redirect_to = "http://example.com/" }.should redirect_to("http://example.com/")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#respond_successfully" do
|
48
|
+
it "should work with the result of a dispatch_to helper call" do
|
49
|
+
dispatch_to(TestController, :success_action).should respond_successfully
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should work with the result of a get helper call" do
|
53
|
+
get("/success").should respond_successfully
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should work with a redirection code" do
|
57
|
+
dispatch_to(TestController, :success_action).status.should be_successful
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#be_missing" do
|
62
|
+
it "should work with the result of a dispatch_to helper call" do
|
63
|
+
dispatch_to(TestController, :missing_action).should be_missing
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should work with the result of a get helper call" do
|
67
|
+
get("/missing").should be_client_error
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should work with a redirection code" do
|
71
|
+
dispatch_to(TestController, :missing_action).status.should be_missing
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module Merb::Test::Rspec
|
77
|
+
module ControllerMatchers
|
78
|
+
class RedirectableTarget
|
79
|
+
attr_accessor :status, :headers
|
80
|
+
def initialize; @headers = {}; end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe BeRedirect do
|
84
|
+
before(:each) do
|
85
|
+
@target = RedirectableTarget.new
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should match a 301 'Moved Permanently' redirect code" do
|
89
|
+
BeRedirect.new.matches?(301).should be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should match a 302 'Found' redirect code" do
|
93
|
+
BeRedirect.new.matches?(302).should be_true
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should match a 303 'See Other' redirect code" do
|
97
|
+
BeRedirect.new.matches?(303).should be_true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should match a 304 'Not Modified' redirect code" do
|
101
|
+
BeRedirect.new.matches?(304).should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should match a 307 'Temporary Redirect' redirect code" do
|
105
|
+
BeRedirect.new.matches?(307).should be_true
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should match a target with a valid redirect code" do
|
109
|
+
@target.status = 301
|
110
|
+
|
111
|
+
BeRedirect.new.matches?(@target).should be_true
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should not match a target with an unused redirect code" do
|
115
|
+
@target.status = 399
|
116
|
+
|
117
|
+
BeRedirect.new.matches?(@target).should_not be_true
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should not match a target with a non redirect code" do
|
121
|
+
@target.status = 200
|
122
|
+
|
123
|
+
BeRedirect.new.matches?(@target).should_not be_true
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#failure_message" do
|
127
|
+
it "should be 'expected to redirect' when the target is a status code" do
|
128
|
+
matcher = BeRedirect.new
|
129
|
+
matcher.matches?(200)
|
130
|
+
matcher.failure_message.should == "expected to redirect"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should be 'expected Foo#bar to redirect' when the target's controller is Foo and action is bar" do
|
134
|
+
matcher = BeRedirect.new
|
135
|
+
@target.stub!(:controller_name).and_return :Foo
|
136
|
+
@target.stub!(:action_name).and_return :bar
|
137
|
+
matcher.matches?(@target)
|
138
|
+
matcher.failure_message.should == "expected Foo#bar to redirect"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#negative_failure_message" do
|
143
|
+
it "should be 'expected not to redirect' when the target is a status code" do
|
144
|
+
matcher = BeRedirect.new
|
145
|
+
matcher.matches?(200)
|
146
|
+
matcher.negative_failure_message.should == "expected not to redirect"
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should be 'expected Foo#bar to redirect' when the target's controller is Foo and action is bar" do
|
150
|
+
matcher = BeRedirect.new
|
151
|
+
@target.stub!(:controller_name).and_return :Foo
|
152
|
+
@target.stub!(:action_name).and_return :bar
|
153
|
+
matcher.matches?(@target)
|
154
|
+
matcher.negative_failure_message.should == "expected Foo#bar not to redirect"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe RedirectTo do
|
160
|
+
before(:each) do
|
161
|
+
@target = RedirectableTarget.new
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should match a target if the status code is 300 level and the locations match" do
|
165
|
+
@target.status = 301
|
166
|
+
@target.headers['Location'] = "http://example.com/"
|
167
|
+
|
168
|
+
RedirectTo.new("http://example.com/").matches?(@target).should be_true
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should not match a target if the status code is not 300 level but the locations match" do
|
172
|
+
@target.status = 404
|
173
|
+
@target.headers['Location'] = "http://example.com/"
|
174
|
+
|
175
|
+
RedirectTo.new("http://example.com/").matches?(@target).should_not be_true
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should not match a target if the status code is 300 level but the locations do not match" do
|
179
|
+
@target.status = 301
|
180
|
+
@target.headers['Location'] = "http://merbivore.com/"
|
181
|
+
|
182
|
+
RedirectTo.new("http://example.com/").matches?(@target).should_not be_true
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "#failure_message" do
|
186
|
+
it "should be 'expected Foo#bar to redirect to <http://expected.com/>, but was <http://target.com/>' when the expected url is http://expected.com/ and the target url is http://target.com/" do
|
187
|
+
@target.stub!(:controller_name).and_return :Foo
|
188
|
+
@target.stub!(:action_name).and_return :bar
|
189
|
+
@target.status = 301
|
190
|
+
@target.headers['Location'] = "http://target.com/"
|
191
|
+
matcher = RedirectTo.new("http://expected.com/")
|
192
|
+
matcher.matches?(@target)
|
193
|
+
matcher.failure_message.should == "expected Foo#bar to redirect to <http://expected.com/>, but was <http://target.com/>"
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should be 'expected Foo#bar to redirect, but there was no redirection' when the target is not redirected" do
|
197
|
+
@target.stub!(:controller_name).and_return :Foo
|
198
|
+
@target.stub!(:action_name).and_return :bar
|
199
|
+
@target.status = 200
|
200
|
+
@target.headers['Location'] = "http://target.com/"
|
201
|
+
matcher = RedirectTo.new("http://expected.com/")
|
202
|
+
matcher.matches?(@target)
|
203
|
+
matcher.failure_message.should == "expected Foo#bar to redirect to <http://expected.com/>, but there was no redirection"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "#negative_failure_message" do
|
208
|
+
it "should be 'expected Foo#bar not to redirect to <http://expected.com/>, but it did anyways" do
|
209
|
+
@target.stub!(:controller_name).and_return :Foo
|
210
|
+
@target.stub!(:action_name).and_return :bar
|
211
|
+
@target.status = 200
|
212
|
+
@target.headers['Location'] = "http://target.com/"
|
213
|
+
matcher = RedirectTo.new("http://expected.com/")
|
214
|
+
matcher.matches?(@target)
|
215
|
+
matcher.negative_failure_message.should == "expected Foo#bar not to redirect to <http://expected.com/>, but did anyway"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe BeSuccess do
|
221
|
+
before(:each) do
|
222
|
+
@target = RedirectableTarget.new
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should match a target with a 200 'OK' status code" do
|
226
|
+
BeSuccess.new.matches?(200).should be_true
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should match a target with a 201 'Created' status code" do
|
230
|
+
BeSuccess.new.matches?(201).should be_true
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should match a target with a 202 'Accepted' status code" do
|
234
|
+
BeSuccess.new.matches?(202).should be_true
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should match a target with a 203 'Non-Authoritative Information' status code" do
|
238
|
+
BeSuccess.new.matches?(203).should be_true
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should match a target with a 204 'No Content' status code" do
|
242
|
+
BeSuccess.new.matches?(204).should be_true
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should match a target with a 205 'Reset Content' status code" do
|
246
|
+
BeSuccess.new.matches?(205).should be_true
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should match a target with a 206 'Partial Content' status code" do
|
250
|
+
BeSuccess.new.matches?(206).should be_true
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should match a target with a 207 'Multi-Status' status code" do
|
254
|
+
BeSuccess.new.matches?(207).should be_true
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should not match a target with an unused 200 level status code" do
|
258
|
+
BeSuccess.new.matches?(299).should_not be_true
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should not match a target with a non 200 level status code" do
|
262
|
+
BeSuccess.new.matches?(301).should_not be_true
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "#failure_message" do
|
266
|
+
it "should be 'expected to be successful but was 300' when the target is status code 300" do
|
267
|
+
matcher = BeSuccess.new
|
268
|
+
matcher.matches?(300)
|
269
|
+
matcher.failure_message.should == "expected to be successful but was 300"
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should be 'expected Foo#bar to be successful but was 404' when the target is controller-ish" do
|
273
|
+
@target.stub!(:controller_name).and_return :Foo
|
274
|
+
@target.stub!(:action_name).and_return :bar
|
275
|
+
@target.status = 404
|
276
|
+
matcher = BeSuccess.new
|
277
|
+
matcher.matches?(@target)
|
278
|
+
matcher.failure_message.should == "expected Foo#bar to be successful but was 404"
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe "#negative_failure_message" do
|
283
|
+
it "should be 'expected not to be successful but it was' when the target is a 200 status code" do
|
284
|
+
matcher = BeSuccess.new
|
285
|
+
matcher.matches?(200)
|
286
|
+
matcher.negative_failure_message.should == "expected not to be successful but it was 200"
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should be 'expected Foo#bar not to be successful but it was 200' when the target is controller-ish" do
|
290
|
+
@target.stub!(:controller_name).and_return :Foo
|
291
|
+
@target.stub!(:action_name).and_return :bar
|
292
|
+
@target.status = 200
|
293
|
+
matcher = BeSuccess.new
|
294
|
+
matcher.matches?(@target)
|
295
|
+
matcher.negative_failure_message.should == "expected Foo#bar not to be successful but it was 200"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe BeMissing do
|
301
|
+
before(:each) do
|
302
|
+
@target = RedirectableTarget.new
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should match a 400 'Bad Request'" do
|
306
|
+
BeMissing.new.matches?(400).should be_true
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should match a 401 'Unauthorized'" do
|
310
|
+
BeMissing.new.matches?(401).should be_true
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should match a 403 'Forbidden'" do
|
314
|
+
BeMissing.new.matches?(403).should be_true
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should match a 404 'Not Found'" do
|
318
|
+
BeMissing.new.matches?(404).should be_true
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should match a 409 'Conflict'" do
|
322
|
+
BeMissing.new.matches?(409).should be_true
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should match a target with a valid client side error code" do
|
326
|
+
@target.status = 404
|
327
|
+
|
328
|
+
BeMissing.new.matches?(@target).should be_true
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should not match a target with an unused client side error code" do
|
332
|
+
@target.status = 499
|
333
|
+
|
334
|
+
BeMissing.new.matches?(@target).should_not be_true
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should not match a target with a non client side error code" do
|
338
|
+
@target.status = 200
|
339
|
+
|
340
|
+
BeMissing.new.matches?(@target).should_not be_true
|
341
|
+
end
|
342
|
+
|
343
|
+
describe "#failure_message" do
|
344
|
+
it "should be 'expected to be missing but was 300' when the target is status code 300" do
|
345
|
+
matcher = BeMissing.new
|
346
|
+
matcher.matches?(300)
|
347
|
+
matcher.failure_message.should == "expected to be missing but was 300"
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should be 'expected Foo#bar to be successful but was 301' when the target is controller-ish" do
|
351
|
+
@target.stub!(:controller_name).and_return :Foo
|
352
|
+
@target.stub!(:action_name).and_return :bar
|
353
|
+
@target.status = 301
|
354
|
+
matcher = BeMissing.new
|
355
|
+
matcher.matches?(@target)
|
356
|
+
matcher.failure_message.should == "expected Foo#bar to be missing but was 301"
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
describe "#negative_failure_message" do
|
361
|
+
it "should be 'expected not to be successful but it was' when the target is a 400 status code" do
|
362
|
+
matcher = BeMissing.new
|
363
|
+
matcher.matches?(400)
|
364
|
+
matcher.negative_failure_message.should == "expected not to be missing but it was 400"
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should be 'expected Foo#bar not to be missing but it was 404' when the target is controller-ish" do
|
368
|
+
@target.stub!(:controller_name).and_return :Foo
|
369
|
+
@target.stub!(:action_name).and_return :bar
|
370
|
+
@target.status = 404
|
371
|
+
matcher = BeMissing.new
|
372
|
+
matcher.matches?(@target)
|
373
|
+
matcher.negative_failure_message.should == "expected Foo#bar not to be missing but it was 404"
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
describe Provide do
|
379
|
+
class TestController < Merb::Controller
|
380
|
+
provides :xml
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'should match for formats a controller class provides' do
|
384
|
+
Provide.new( :xml ).matches?( TestController ).should be_true
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'should match for formats a controller instance provides' do
|
388
|
+
t = TestController.new( fake_request )
|
389
|
+
Provide.new( :xml ).matches?( t ).should be_true
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'should not match for formats a controller class does not provide' do
|
393
|
+
Provide.new( :yaml ).matches?( TestController ).should be_false
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'should not match for formats a controller instance does not provide' do
|
397
|
+
t = TestController.new( fake_request )
|
398
|
+
Provide.new( :yaml ).matches?( t ).should be_false
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|