merb-core 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +136 -2
- data/CONTRIBUTORS +6 -0
- data/PUBLIC_CHANGELOG +38 -0
- data/Rakefile +38 -30
- data/lib/merb-core.rb +88 -23
- data/lib/merb-core/bootloader.rb +235 -51
- data/lib/merb-core/config.rb +121 -36
- data/lib/merb-core/controller/abstract_controller.rb +59 -36
- data/lib/merb-core/controller/exceptions.rb +2 -15
- data/lib/merb-core/controller/merb_controller.rb +44 -1
- data/lib/merb-core/controller/mime.rb +4 -0
- data/lib/merb-core/controller/mixins/controller.rb +38 -21
- data/lib/merb-core/controller/mixins/render.rb +44 -29
- data/lib/merb-core/controller/mixins/responder.rb +3 -31
- data/lib/merb-core/controller/template.rb +45 -21
- data/lib/merb-core/core_ext/kernel.rb +60 -32
- data/lib/merb-core/dispatch/default_exception/default_exception.rb +2 -2
- data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +3 -1
- data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +71 -67
- data/lib/merb-core/dispatch/default_exception/views/index.html.erb +7 -3
- data/lib/merb-core/dispatch/dispatcher.rb +3 -3
- data/lib/merb-core/dispatch/request.rb +56 -9
- data/lib/merb-core/dispatch/router.rb +159 -133
- data/lib/merb-core/dispatch/router/behavior.rb +462 -703
- data/lib/merb-core/dispatch/router/cached_proc.rb +3 -3
- data/lib/merb-core/dispatch/router/resources.rb +289 -0
- data/lib/merb-core/dispatch/router/route.rb +514 -294
- data/lib/merb-core/dispatch/session.rb +4 -2
- data/lib/merb-core/logger.rb +213 -202
- data/lib/merb-core/plugins.rb +9 -1
- data/lib/merb-core/rack.rb +3 -1
- data/lib/merb-core/rack/adapter.rb +7 -4
- data/lib/merb-core/rack/adapter/abstract.rb +188 -0
- data/lib/merb-core/rack/adapter/ebb.rb +12 -13
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +2 -15
- data/lib/merb-core/rack/adapter/irb.rb +3 -2
- data/lib/merb-core/rack/adapter/mongrel.rb +22 -15
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +4 -16
- data/lib/merb-core/rack/adapter/thin.rb +21 -22
- data/lib/merb-core/rack/adapter/thin_turbo.rb +4 -11
- data/lib/merb-core/rack/adapter/webrick.rb +54 -18
- data/lib/merb-core/rack/application.rb +4 -4
- data/lib/merb-core/rack/handler/mongrel.rb +12 -13
- data/lib/merb-core/rack/middleware/csrf.rb +1 -1
- data/lib/merb-core/rack/stream_wrapper.rb +41 -0
- data/lib/merb-core/server.rb +157 -90
- data/lib/merb-core/tasks/gem_management.rb +267 -0
- data/lib/merb-core/tasks/merb.rb +1 -0
- data/lib/merb-core/tasks/merb_rake_helper.rb +48 -34
- data/lib/merb-core/tasks/stats.rake +1 -1
- data/lib/merb-core/test.rb +9 -3
- data/lib/merb-core/test/helpers.rb +1 -0
- data/lib/merb-core/test/helpers/mock_request_helper.rb +393 -0
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -2
- data/lib/merb-core/test/helpers/request_helper.rb +40 -372
- data/lib/merb-core/test/helpers/route_helper.rb +16 -2
- data/lib/merb-core/test/matchers.rb +1 -0
- data/lib/merb-core/test/matchers/controller_matchers.rb +4 -247
- data/lib/merb-core/test/matchers/request_matchers.rb +140 -0
- data/lib/merb-core/test/matchers/view_matchers.rb +22 -4
- data/lib/merb-core/test/run_specs.rb +118 -26
- data/lib/merb-core/test/test_ext/rspec.rb +181 -0
- data/lib/merb-core/version.rb +1 -9
- metadata +10 -342
- data/docs/bootloading.dox +0 -58
- data/docs/documentation_standards +0 -40
- 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 +0 -51
- data/lib/merb-core/vendor/facets.rb +0 -2
- data/lib/merb-core/vendor/facets/dictionary.rb +0 -433
- data/lib/merb-core/vendor/facets/inflect.rb +0 -342
- data/spec/private/config/adapter_spec.rb +0 -32
- data/spec/private/config/config_spec.rb +0 -202
- data/spec/private/config/environment_spec.rb +0 -13
- data/spec/private/config/merb_spec.rb +0 -34
- data/spec/private/config/spec_helper.rb +0 -1
- data/spec/private/core_ext/kernel_spec.rb +0 -159
- data/spec/private/dispatch/bootloader_spec.rb +0 -24
- data/spec/private/dispatch/fixture/app/controllers/application.rb +0 -4
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -25
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -19
- data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +0 -8
- data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +0 -37
- data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +0 -216
- data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +0 -38
- data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +0 -40
- data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +0 -11
- data/spec/private/dispatch/fixture/config/black_hole.rb +0 -12
- data/spec/private/dispatch/fixture/config/environments/development.rb +0 -6
- data/spec/private/dispatch/fixture/config/environments/production.rb +0 -5
- data/spec/private/dispatch/fixture/config/environments/test.rb +0 -6
- data/spec/private/dispatch/fixture/config/init.rb +0 -45
- data/spec/private/dispatch/fixture/config/rack.rb +0 -11
- data/spec/private/dispatch/fixture/config/router.rb +0 -35
- data/spec/private/dispatch/fixture/log/merb_test.log +0 -8839
- data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
- data/spec/private/dispatch/fixture/public/merb.fcgi +0 -4
- data/spec/private/dispatch/fixture/public/stylesheets/master.css +0 -119
- data/spec/private/dispatch/route_params_spec.rb +0 -23
- data/spec/private/dispatch/spec_helper.rb +0 -1
- data/spec/private/router/behavior_spec.rb +0 -60
- data/spec/private/router/fixture/log/merb_test.log +0 -35
- data/spec/private/router/route_spec.rb +0 -418
- data/spec/private/router/router_spec.rb +0 -183
- data/spec/private/vendor/facets/plural_spec.rb +0 -564
- data/spec/private/vendor/facets/singular_spec.rb +0 -489
- data/spec/public/DEFINITIONS +0 -11
- data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/cousins.rb +0 -41
- data/spec/public/abstract_controller/controllers/display.rb +0 -60
- data/spec/public/abstract_controller/controllers/filters.rb +0 -260
- data/spec/public/abstract_controller/controllers/helpers.rb +0 -41
- data/spec/public/abstract_controller/controllers/partial.rb +0 -121
- data/spec/public/abstract_controller/controllers/render.rb +0 -113
- data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/layout/alt.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/layout/custom.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +0 -1
- 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 +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +0 -1
- data/spec/public/abstract_controller/display_spec.rb +0 -37
- data/spec/public/abstract_controller/filter_spec.rb +0 -136
- data/spec/public/abstract_controller/helper_spec.rb +0 -21
- data/spec/public/abstract_controller/partial_spec.rb +0 -61
- data/spec/public/abstract_controller/render_spec.rb +0 -90
- data/spec/public/abstract_controller/spec_helper.rb +0 -31
- data/spec/public/boot_loader/boot_loader_spec.rb +0 -33
- data/spec/public/boot_loader/spec_helper.rb +0 -1
- data/spec/public/controller/authentication_spec.rb +0 -174
- data/spec/public/controller/base_spec.rb +0 -88
- data/spec/public/controller/conditional_get_spec.rb +0 -100
- data/spec/public/controller/config/init.rb +0 -6
- data/spec/public/controller/controllers/authentication.rb +0 -74
- data/spec/public/controller/controllers/base.rb +0 -65
- data/spec/public/controller/controllers/conditional_get.rb +0 -35
- data/spec/public/controller/controllers/cookies.rb +0 -36
- data/spec/public/controller/controllers/dispatcher.rb +0 -35
- data/spec/public/controller/controllers/display.rb +0 -118
- data/spec/public/controller/controllers/redirect.rb +0 -36
- data/spec/public/controller/controllers/responder.rb +0 -93
- data/spec/public/controller/controllers/url.rb +0 -7
- data/spec/public/controller/controllers/views/layout/custom.html.erb +0 -1
- data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +0 -1
- data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +0 -1
- data/spec/public/controller/cookies_spec.rb +0 -95
- data/spec/public/controller/dispatcher_spec.rb +0 -410
- data/spec/public/controller/display_spec.rb +0 -84
- data/spec/public/controller/redirect_spec.rb +0 -33
- data/spec/public/controller/responder_spec.rb +0 -169
- data/spec/public/controller/spec_helper.rb +0 -13
- data/spec/public/controller/url_spec.rb +0 -255
- data/spec/public/core/merb_core_spec.rb +0 -45
- data/spec/public/core_ext/fixtures/core_ext_dependency.rb +0 -2
- data/spec/public/core_ext/kernel_spec.rb +0 -88
- data/spec/public/core_ext/spec_helper.rb +0 -1
- data/spec/public/directory_structure/directory/app/controllers/application.rb +0 -3
- data/spec/public/directory_structure/directory/app/controllers/base.rb +0 -13
- data/spec/public/directory_structure/directory/app/controllers/custom.rb +0 -19
- data/spec/public/directory_structure/directory/app/views/base/template.html.erb +0 -1
- data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +0 -1
- data/spec/public/directory_structure/directory/config/router.rb +0 -3
- data/spec/public/directory_structure/directory/log/merb_test.log +0 -4588
- data/spec/public/directory_structure/directory_spec.rb +0 -43
- data/spec/public/logger/logger_spec.rb +0 -181
- data/spec/public/logger/spec_helper.rb +0 -1
- data/spec/public/rack/conditinal_get_middleware_spec.rb +0 -127
- data/spec/public/rack/csrf_middleware_spec.rb +0 -70
- data/spec/public/rack/rack_middleware_spec.rb +0 -99
- data/spec/public/rack/shared_example_groups.rb +0 -35
- data/spec/public/reloading/directory/app/controllers/application.rb +0 -3
- data/spec/public/reloading/directory/app/controllers/reload.rb +0 -6
- data/spec/public/reloading/directory/config/init.rb +0 -2
- data/spec/public/reloading/directory/log/merb_test.log +0 -288231
- data/spec/public/reloading/reload_spec.rb +0 -103
- data/spec/public/request/multipart_spec.rb +0 -41
- data/spec/public/request/request_spec.rb +0 -250
- data/spec/public/router/default_spec.rb +0 -21
- data/spec/public/router/deferred_spec.rb +0 -22
- data/spec/public/router/fixation_spec.rb +0 -49
- data/spec/public/router/fixture/log/merb_test.log +0 -524
- data/spec/public/router/namespace_spec.rb +0 -113
- data/spec/public/router/nested_matches_spec.rb +0 -97
- data/spec/public/router/nested_resources_spec.rb +0 -41
- data/spec/public/router/resource_spec.rb +0 -37
- data/spec/public/router/resources_spec.rb +0 -82
- data/spec/public/router/spec_helper.rb +0 -90
- data/spec/public/router/special_spec.rb +0 -61
- data/spec/public/router/string_spec.rb +0 -61
- data/spec/public/session/controllers/sessions.rb +0 -56
- data/spec/public/session/cookie_session_spec.rb +0 -73
- data/spec/public/session/memcached_session_spec.rb +0 -31
- data/spec/public/session/memory_session_spec.rb +0 -28
- data/spec/public/session/multiple_sessions_spec.rb +0 -74
- data/spec/public/session/no_session_spec.rb +0 -12
- data/spec/public/session/session_spec.rb +0 -106
- data/spec/public/template/template_spec.rb +0 -104
- data/spec/public/template/templates/error.html.erb +0 -2
- data/spec/public/template/templates/template.html.erb +0 -1
- data/spec/public/template/templates/template.html.myt +0 -1
- data/spec/public/test/controller_matchers_spec.rb +0 -412
- data/spec/public/test/controllers/controller_assertion_mock.rb +0 -7
- data/spec/public/test/controllers/dispatch_controller.rb +0 -11
- data/spec/public/test/controllers/spec_helper_controller.rb +0 -39
- data/spec/public/test/multipart_request_helper_spec.rb +0 -159
- data/spec/public/test/multipart_upload_text_file.txt +0 -1
- data/spec/public/test/request_helper_spec.rb +0 -269
- data/spec/public/test/route_helper_spec.rb +0 -78
- data/spec/public/test/route_matchers_spec.rb +0 -166
- data/spec/public/test/view_helper_spec.rb +0 -96
- data/spec/public/test/view_matchers_spec.rb +0 -183
- data/spec/spec_helper.rb +0 -121
@@ -1,78 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
-
|
3
|
-
class TestController < Merb::Controller
|
4
|
-
def get(id = nil); end
|
5
|
-
def post; end
|
6
|
-
end
|
7
|
-
|
8
|
-
describe Merb::Test::RouteHelper do
|
9
|
-
before(:each) do
|
10
|
-
Merb::Router.prepare do |r|
|
11
|
-
r.match("/").defer_to do |request, params|
|
12
|
-
{ :controller => 'test_controller', :action => request.raw_post } unless request.raw_post.blank?
|
13
|
-
end
|
14
|
-
r.match("/", :method => :get).to(:controller => "test_controller", :action => "get").name(:getter)
|
15
|
-
r.match("/", :method => :post).to(:controller => "test_controller", :action => "post")
|
16
|
-
r.match("/:id").to(:controller => "test_controller", :action => "get").name(:with_id)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#url" do
|
21
|
-
it "should use Merb::Router" do
|
22
|
-
url(:getter).should == "/"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should work with a model as the parameter" do
|
26
|
-
model = mock(:model)
|
27
|
-
model.stub!(:id).and_return("123")
|
28
|
-
url(:with_id, model).should == "/123"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should work with a parameters hash" do
|
32
|
-
url(:with_id, :id => 123).should == "/123"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should turn extra hash items into query params" do
|
36
|
-
generated_url = url(:getter, :id => 123, :color => 'red', :size => 'large')
|
37
|
-
lambda {
|
38
|
-
generated_url.match(/\bid=123\b/) &&
|
39
|
-
generated_url.match(/\bsize=large\b/) &&
|
40
|
-
generated_url.match(/\bcolor=red\b/)
|
41
|
-
}.call.should_not be_nil
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should remove items with nil values from query params" do
|
45
|
-
url(:getter, :color => nil, :size => 'large').should == "/?size=large"
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should remove items with nil values from query params when named route isn't specified" do
|
49
|
-
url(:controller => 'cont', :action => 'act', :color => nil, :size => 'large').should == "/cont/act?size=large"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#request_to" do
|
54
|
-
it "should GET if no method is given" do
|
55
|
-
request_to("/")[:action].should == "get"
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should return a hash" do
|
59
|
-
Hash.should === request_to("/")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should contain the controller in the result" do
|
63
|
-
request_to("/")[:controller].should == "test_controller"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should contain the action in the result" do
|
67
|
-
request_to("/")[:action].should == "get"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should contain any parameters in the result" do
|
71
|
-
request_to("/123")[:id].should == "123"
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should play nice with raw_post in deferred routing" do
|
75
|
-
request_to("/", :post, {:post_body => 'deferred'})[:action].should == 'deferred'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,166 +0,0 @@
|
|
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
|
-
|
93
|
-
it "should work with an empty expectation" do
|
94
|
-
ParameterMatcher.new({}).matches?(:param => "abc").should be_false
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#failure_message" do
|
99
|
-
it "should include the expected controller and action" do
|
100
|
-
matcher = RouteToMatcher.new(TestController, :any_action)
|
101
|
-
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
102
|
-
matcher.failure_message.should include("TestController#any_action")
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should include the target controller and action in camel case" do
|
106
|
-
matcher = RouteToMatcher.new(TestController, :any_action)
|
107
|
-
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
108
|
-
matcher.failure_message.should include("TargetController#target_action")
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should include the expected parameters" do
|
112
|
-
expected_parameters = {:id => '123', :page => '2'}
|
113
|
-
matcher = RouteToMatcher.new(TestController, :any_action)
|
114
|
-
matcher.with(expected_parameters)
|
115
|
-
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
116
|
-
matcher.failure_message.should include(expected_parameters.inspect)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should include the actual paramters" do
|
120
|
-
expected_parameters, actual_parameters = {:id => '123', :page => '2'}, {:id => '2', :page => '321'}
|
121
|
-
matcher = RouteToMatcher.new(TestController, :any_action)
|
122
|
-
matcher.with(expected_parameters)
|
123
|
-
matcher.matches?(actual_parameters.merge(:controller => "test_controller", :action => "any_action"))
|
124
|
-
matcher.failure_message.should include(actual_parameters.inspect)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "#negative_failure_message" do
|
129
|
-
it "should include the expected controller and action" do
|
130
|
-
RouteToMatcher.new(TestController, :any_action).negative_failure_message.should include("TestController#any_action")
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe ParameterMatcher do
|
136
|
-
it "should work with a Hash as the parameter argument" do
|
137
|
-
ParameterMatcher.new(:param => "abc").matches?(:param => "abc").should be_true
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should work with an object as the parameter argument" do
|
141
|
-
ParameterMatcher.new(IDish.new(1234)).matches?(:id => 1234).should be_true
|
142
|
-
end
|
143
|
-
|
144
|
-
describe "#failure_message" do
|
145
|
-
it "should include the expected parameters hash" do
|
146
|
-
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
147
|
-
ParameterMatcher.new(parameter_hash).failure_message.should include(parameter_hash.inspect)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should include the actual parameters hash" do
|
151
|
-
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
152
|
-
matcher = ParameterMatcher.new(:id => 123)
|
153
|
-
matcher.matches?(parameter_hash)
|
154
|
-
matcher.failure_message.should include(parameter_hash.inspect)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe "#negative_failure_message" do
|
159
|
-
it "should include the expected parameters hash" do
|
160
|
-
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
161
|
-
ParameterMatcher.new(parameter_hash).negative_failure_message.should include(parameter_hash.inspect)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
@@ -1,96 +0,0 @@
|
|
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
|
@@ -1,183 +0,0 @@
|
|
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
|