thorero-core 0.9.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +352 -0
- 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/merb-core/logger.rb +202 -0
- 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 +542 -0
@@ -0,0 +1,162 @@
|
|
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
|
+
def get(id = nil); end
|
7
|
+
def post(version = nil); end
|
8
|
+
end
|
9
|
+
|
10
|
+
class IDish
|
11
|
+
attr_accessor :id
|
12
|
+
alias_method :to_param, :id
|
13
|
+
|
14
|
+
def initialize(id)
|
15
|
+
@id = id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Merb::Test::Rspec::RouteMatchers do
|
20
|
+
include Merb::Test::RouteHelper
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
Merb::Router.prepare do |r|
|
24
|
+
r.match(%r"/v(\d+\.\d+)", :method => :post).to(:controller => "test_controller", :action => "post", :version => "[1]")
|
25
|
+
r.match("/", :method => :get).to(:controller => "test_controller", :action => "get").name(:getter)
|
26
|
+
r.match("/", :method => :post).to(:controller => "test_controller", :action => "post")
|
27
|
+
r.match("/:id").to(:controller => "test_controller", :action => "get").name(:with_id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#route_to" do
|
32
|
+
it "should work with the request_to helper" do
|
33
|
+
request_to("/", :get).should route_to(TestController, :get)
|
34
|
+
request_to("/", :post).should_not route_to(TestController, :get)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should work with the url helper and ParamMatcher" do
|
38
|
+
idish = IDish.new(rand(1000).to_s)
|
39
|
+
|
40
|
+
request_to(url(:with_id, idish)).should route_to(TestController, :get).with(idish)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should work with a negative ParamMatcher" do
|
44
|
+
request_to(url(:with_id, :id => 100)).should_not route_to(TestController, :get).with(:id => 1)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should work with a route containing a regexp" do
|
48
|
+
request_to("/v1.2", :post).should route_to(TestController, :post).with(:version => "1.2")
|
49
|
+
request_to("/v1.0", :post).should_not route_to(TestController, :post).with(:version => "3.14")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module Merb::Test::Rspec::RouteMatchers
|
54
|
+
|
55
|
+
describe RouteToMatcher do
|
56
|
+
|
57
|
+
it "should work with snake cased controllers" do
|
58
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "get").should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should work with camel cased controllers" do
|
62
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "TestController", :action => "get").should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should work with symbol or string controller name" do
|
66
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "get").should be_true
|
67
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => :test_controller, :action => :get)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not pass if the controllers do not match" do
|
71
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "other_controller", :action => "get").should be_false
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not pass if the actions do not match" do
|
75
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "post").should be_false
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not pass if the parameters do not the ParameterMatcher" do
|
79
|
+
route_matcher = RouteToMatcher.new(TestController, :get)
|
80
|
+
route_matcher.with(:id => "123")
|
81
|
+
|
82
|
+
route_matcher.matches?(:controller => "test_case", :action => "get", :id => "456").should be_false
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#with" do
|
86
|
+
it "should add a ParameterMatcher" do
|
87
|
+
ParameterMatcher.should_receive(:new).with(:id => "123")
|
88
|
+
|
89
|
+
route_matcher = RouteToMatcher.new(TestController, :get)
|
90
|
+
route_matcher.with(:id => "123")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#failure_message" do
|
95
|
+
it "should include the expected controller and action" do
|
96
|
+
matcher = RouteToMatcher.new(TestController, :any_action)
|
97
|
+
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
98
|
+
matcher.failure_message.should include("TestController#any_action")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should include the target controller and action in camel case" do
|
102
|
+
matcher = RouteToMatcher.new(TestController, :any_action)
|
103
|
+
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
104
|
+
matcher.failure_message.should include("TargetController#target_action")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should include the expected parameters" do
|
108
|
+
expected_parameters = {:id => '123', :page => '2'}
|
109
|
+
matcher = RouteToMatcher.new(TestController, :any_action)
|
110
|
+
matcher.with(expected_parameters)
|
111
|
+
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
112
|
+
matcher.failure_message.should include(expected_parameters.inspect)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should include the actual paramters" do
|
116
|
+
expected_parameters, actual_parameters = {:id => '123', :page => '2'}, {:id => '2', :page => '321'}
|
117
|
+
matcher = RouteToMatcher.new(TestController, :any_action)
|
118
|
+
matcher.with(expected_parameters)
|
119
|
+
matcher.matches?(actual_parameters.merge(:controller => "test_controller", :action => "any_action"))
|
120
|
+
matcher.failure_message.should include(actual_parameters.inspect)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#negative_failure_message" do
|
125
|
+
it "should include the expected controller and action" do
|
126
|
+
RouteToMatcher.new(TestController, :any_action).negative_failure_message.should include("TestController#any_action")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe ParameterMatcher do
|
132
|
+
it "should work with a Hash as the parameter argument" do
|
133
|
+
ParameterMatcher.new(:param => "abc").matches?(:param => "abc").should be_true
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should work with an object as the parameter argument" do
|
137
|
+
ParameterMatcher.new(IDish.new(1234)).matches?(:id => 1234).should be_true
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#failure_message" do
|
141
|
+
it "should include the expected parameters hash" do
|
142
|
+
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
143
|
+
ParameterMatcher.new(parameter_hash).failure_message.should include(parameter_hash.inspect)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should include the actual parameters hash" do
|
147
|
+
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
148
|
+
matcher = ParameterMatcher.new(:id => 123)
|
149
|
+
matcher.matches?(parameter_hash)
|
150
|
+
matcher.failure_message.should include(parameter_hash.inspect)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#negative_failure_message" do
|
155
|
+
it "should include the expected parameters hash" do
|
156
|
+
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
157
|
+
ParameterMatcher.new(parameter_hash).negative_failure_message.should include(parameter_hash.inspect)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
|
3
|
+
describe Merb::Test::ViewHelper do
|
4
|
+
before(:each) do
|
5
|
+
@output = Merb::Test::ViewHelper::DocumentOutput.new(test_response)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#tag" do
|
9
|
+
it "should return the inner content of the first tag found by the css query" do
|
10
|
+
tag(:li).should == "item 1"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#tags" do
|
15
|
+
it "should return an array of tag contents for all tags found by the css query" do
|
16
|
+
tags(:li).should include("item 1", "item 2", "item 3")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#element" do
|
21
|
+
it "should return a raw Hpricot::Elem object for the first result found by the query" do
|
22
|
+
Hpricot::Elem.should === element(:body)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#elements" do
|
27
|
+
it "should return an array of Hpricot::Elem objects for the results found by the query" do
|
28
|
+
elements("li, ul").each{|ele| Hpricot::Elem.should === ele}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#have_tag" do
|
33
|
+
it "should work without options hash" do
|
34
|
+
have_tag(:html)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should work with options hash" do
|
38
|
+
have_tag(:html, {})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#get_elements" do
|
43
|
+
it "should return an array of Hpricot::Elem objects for the results found by the query containing the filter string" do
|
44
|
+
get_elements(:li, "item").size.should == 3
|
45
|
+
get_elements(:li, "item 2").size.should == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return an array of Hpricot::Elem objects for the results found by the query matching the filter regexp" do
|
49
|
+
get_elements(:li, /^item \d$/).size.should == 3
|
50
|
+
get_elements(:li, /^item (1|2)$/).size.should == 2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should raise an error if the ouput is not specified and cannot be found" do
|
55
|
+
@output, @response_output, @controller = nil
|
56
|
+
|
57
|
+
lambda { tag("div") }.should raise_error("The response output was not in its usual places, please provide the output")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should use @output if no output parameter is supplied" do
|
61
|
+
@output.should_receive(:content_for)
|
62
|
+
|
63
|
+
tag(:div)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should use @output_response if no output parameter is supplied and @output does not contain output" do
|
67
|
+
@output = nil
|
68
|
+
@response_output = test_response
|
69
|
+
|
70
|
+
tag(:div)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should use @controller.body if no output parameter is supplied and both @output and @response_output do not contain output" do
|
74
|
+
@output, @response_output = nil
|
75
|
+
@controller = mock(:controller)
|
76
|
+
@controller.should_receive(:nil?).and_return false
|
77
|
+
@controller.should_receive(:body).any_number_of_times.and_return test_response
|
78
|
+
|
79
|
+
tag(:div)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_response
|
83
|
+
<<-EOR
|
84
|
+
<html>
|
85
|
+
<body>
|
86
|
+
<div>Hello, World!</div>
|
87
|
+
<ul>
|
88
|
+
<li>item 1</li>
|
89
|
+
<li>item 2</li>
|
90
|
+
<li>item 3</li>
|
91
|
+
</ul
|
92
|
+
</body>
|
93
|
+
</html>
|
94
|
+
EOR
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
require "merb-core/test"
|
3
|
+
|
4
|
+
Merb.start :environment => 'test', :log_level => :fatal
|
5
|
+
|
6
|
+
describe Merb::Test::Rspec::ViewMatchers do
|
7
|
+
include Merb::Test::ViewHelper
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@body = <<-EOF
|
11
|
+
<div id='main'>
|
12
|
+
<div class='inner'>hello, world!</div>
|
13
|
+
</div>
|
14
|
+
EOF
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#match_tag" do
|
18
|
+
it "should work with a HasContent matcher in the block" do
|
19
|
+
@body.should have_tag(:div) {|d| d.should_not contain("merb")}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should work with a 'with_tag' chain" do
|
23
|
+
@body.should have_tag(:div, :id => :main).with_tag(:div, :class => 'inner')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work with a block before a with_tag" do
|
27
|
+
@body.should have_tag(:div, :id => :main) {|d| d.should_not contain("merb")}.with_tag(:div, :class => 'inner')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Merb::Test::Rspec::ViewMatchers
|
32
|
+
|
33
|
+
describe HasTag do
|
34
|
+
describe "#matches?" do
|
35
|
+
before(:each) do
|
36
|
+
@document = stub(:document)
|
37
|
+
Hpricot.should_receive(:parse).and_return @document
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should should pass all found elements to the block" do
|
41
|
+
@block_called = false
|
42
|
+
|
43
|
+
@document.should_receive(:search).and_return [""]
|
44
|
+
HasTag.new("tag").matches?("") {|e| @block_called = true}
|
45
|
+
|
46
|
+
@block_called.should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not intercept any errors raised in the block" do
|
50
|
+
@document.should_receive(:search).and_return [""]
|
51
|
+
lambda {
|
52
|
+
HasTag.new("tag").matches?("") {|e| true.should be_false }
|
53
|
+
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#with_tag" do
|
58
|
+
it "should set @inner_tag" do
|
59
|
+
outer = HasTag.new("outer")
|
60
|
+
inner = outer.with_tag("inner")
|
61
|
+
|
62
|
+
outer.selector.should include(inner.selector)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#selector" do
|
67
|
+
it "should always start with \/\/" do
|
68
|
+
HasTag.new("tag").selector.should =~ /^\/\//
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should use @tag for the element" do
|
72
|
+
HasTag.new("tag").selector.should include("tag")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should use dot notation for the class" do
|
76
|
+
HasTag.new("tag", :class => "class").selector.should include("tag.class")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should use pound(#) notation for the id" do
|
80
|
+
HasTag.new("tag", :id => "id").selector.should include("tag#id")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should include any custom attributes" do
|
84
|
+
HasTag.new("tag", :random => :attribute).selector.should include("[@random=\"attribute\"]")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not include the class as a custom attribute" do
|
88
|
+
HasTag.new("tag", :class => :my_class, :rand => :attr).selector.should_not include("[@class=\"my_class\"]")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not include the id as a custom attribute" do
|
92
|
+
HasTag.new("tag", :id => :my_id, :rand => :attr).selector.should_not include("[@id=\"my_id\"]")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#failure_message" do
|
97
|
+
it "should include the tag name" do
|
98
|
+
HasTag.new("anytag").failure_message.should include("<anytag")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should include the tag's id" do
|
102
|
+
HasTag.new("div", :id => :spacer).failure_message.should include("<div id=\"spacer\"")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should include the tag's class" do
|
106
|
+
HasTag.new("div", :class => :header).failure_message.should include("<div class=\"header\"")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should include the tag's custom attributes" do
|
110
|
+
HasTag.new("h1", :attr => :val, :foo => :bar).failure_message.should include("attr=\"val\"")
|
111
|
+
HasTag.new("h1", :attr => :val, :foo => :bar).failure_message.should include("foo=\"bar\"")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "id, class, and attributes for error messages" do
|
116
|
+
it "should start with a space for a class, id, or custom attribute" do
|
117
|
+
HasTag.new("tag", :id => "identifier").id_for_error.should =~ /^ /
|
118
|
+
HasTag.new("tag", :class => "classifier").class_for_error.should =~ /^ /
|
119
|
+
HasTag.new("tag", :rand => "attr").attributes_for_error.should =~ /^ /
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should have 'class=\"classifier\"' in class_for_error" do
|
123
|
+
HasTag.new("tag", :class => "classifier").class_for_error.should include("class=\"classifier\"")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should have 'id=\"identifier\" in id_for_error" do
|
127
|
+
HasTag.new("tag", :id => "identifier").id_for_error.should include("id=\"identifier\"")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe HasContent do
|
133
|
+
before(:each) do
|
134
|
+
@element = stub(:element)
|
135
|
+
@element.stub!(:inner_text).and_return <<-EOF
|
136
|
+
<div id='main'>
|
137
|
+
<div class='inner'>hello, world!</div>
|
138
|
+
</div>
|
139
|
+
EOF
|
140
|
+
|
141
|
+
@element.stub!(:contains?)
|
142
|
+
@element.stub!(:matches?)
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#matches?" do
|
146
|
+
it "should call element#contains? when the argument is a string" do
|
147
|
+
@element.should_receive(:contains?)
|
148
|
+
|
149
|
+
HasContent.new("hello, world!").matches?(@element)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should call element#matches? when the argument is a regular expression" do
|
153
|
+
@element.should_receive(:matches?)
|
154
|
+
|
155
|
+
HasContent.new(/hello, world/).matches?(@element)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#failure_message" do
|
160
|
+
it "should include the content string" do
|
161
|
+
hc = HasContent.new("hello, world!")
|
162
|
+
hc.matches?(@element)
|
163
|
+
|
164
|
+
hc.failure_message.should include("\"hello, world!\"")
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should include the content regular expresson" do
|
168
|
+
hc = HasContent.new(/hello,\sworld!/)
|
169
|
+
hc.matches?(@element)
|
170
|
+
|
171
|
+
hc.failure_message.should include("/hello,\\sworld!/")
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should include the element's inner content" do
|
175
|
+
hc = HasContent.new(/hello,\sworld!/)
|
176
|
+
hc.matches?(@element)
|
177
|
+
|
178
|
+
hc.failure_message.should include(@element.inner_text)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
$TESTING=true
|
2
|
+
require "rubygems"
|
3
|
+
require "spec"
|
4
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "merb-core")
|
5
|
+
|
6
|
+
Merb.start :environment => 'test', :adapter => 'runner'
|
7
|
+
|
8
|
+
# -- Global custom matchers --
|
9
|
+
|
10
|
+
# A better +be_kind_of+ with more informative error messages.
|
11
|
+
#
|
12
|
+
# The default +be_kind_of+ just says
|
13
|
+
#
|
14
|
+
# "expected to return true but got false"
|
15
|
+
#
|
16
|
+
# This one says
|
17
|
+
#
|
18
|
+
# "expected File but got Tempfile"
|
19
|
+
|
20
|
+
module Merb
|
21
|
+
module Test
|
22
|
+
module RspecMatchers
|
23
|
+
class BeKindOf
|
24
|
+
def initialize(expected) # + args
|
25
|
+
@expected = expected
|
26
|
+
end
|
27
|
+
|
28
|
+
def matches?(target)
|
29
|
+
@target = target
|
30
|
+
@target.kind_of?(@expected)
|
31
|
+
end
|
32
|
+
|
33
|
+
def failure_message
|
34
|
+
"expected #{@expected} but got #{@target.class}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def negative_failure_message
|
38
|
+
"expected #{@expected} to not be #{@target.class}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def description
|
42
|
+
"be_kind_of #{@target}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def be_kind_of(expected) # + args
|
47
|
+
BeKindOf.new(expected)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Helper
|
52
|
+
def running(&blk) blk; end
|
53
|
+
|
54
|
+
def executing(&blk) blk; end
|
55
|
+
|
56
|
+
def doing(&blk) blk; end
|
57
|
+
|
58
|
+
def calling(&blk) blk; end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
Spec::Runner.configure do |config|
|
65
|
+
config.include Merb::Test::Helper
|
66
|
+
config.include Merb::Test::RspecMatchers
|
67
|
+
config.include Merb::Test::RequestHelper
|
68
|
+
end
|