X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fdispatch_misc.t;h=a4ab38a7366c490e85d8b124c97849f13740746a;hb=4bb0d044b7b948686ec4cb6598184e5136cd422a;hp=2924a9d5b3ef921ca7455b5b40947413d69d8668;hpb=e5250d96fc8320272ab2ddc39b445649f980815f;p=catagits%2FWeb-Simple.git diff --git a/t/dispatch_misc.t b/t/dispatch_misc.t index 2924a9d..a4ab38a 100644 --- a/t/dispatch_misc.t +++ b/t/dispatch_misc.t @@ -16,13 +16,16 @@ my @dispatch; package MiscTest; sub dispatch_request { @dispatch } + sub string_method { [ 999, [], [""] ]; } } my $app = MiscTest->new; sub run_request { $app->run_test_request( @_ ); } +string_method_name(); app_is_non_plack(); app_is_object(); +app_is_just_sub(); plack_app_return(); broken_route_def(); invalid_psgi_responses(); @@ -33,6 +36,14 @@ matcher_nonsub_pair(); done_testing(); +sub string_method_name { + @dispatch = ( '/' => "string_method" ); + + my $get = run_request( GET => 'http://localhost/' ); + + cmp_ok $get->code, '==', 999, "a dispatcher that's a string matching a method on the dispatch object gets executed"; +} + sub app_is_non_plack { my $r = HTTP::Response->new( 999 ); @@ -53,12 +64,21 @@ sub app_is_object { sub to_app { [ 999, [], ["ok"] ] } } - my $d = Web::Dispatch->new( dispatch_object => ObjectApp->new ); + my $o = ObjectApp->new; + my $d = Web::Dispatch->new( dispatch_object => $o ); my $res = $d->call; cmp_ok $res->[0], '==', 999, "Web::Dispatch can dispatch properly, given only an object with to_app method"; } +sub app_is_just_sub { + my $d = Web::Dispatch->new( dispatch_app => sub () { [ 999, [], ["ok"] ] } ); + my $res = $d->call( {} ); + + cmp_ok $res->[0], '==', 999, + "Web::Dispatch can dispatch properly, given only an app that's just a sub, with no object involved"; +} + sub plack_app_return { { @@ -106,12 +126,22 @@ sub invalid_psgi_responses { for my $response ( @responses ) { @dispatch = ( sub (/) { $response->[0] } ); - eval { run_request( GET => 'http://localhost/' ) }; - - like $@, qr/Can't call method "request" on an undefined value .*MockHTTP/, - sprintf( + my $message = sprintf( "if a route returns %s, then that is returned as a response by WD, causing HTTP::Message::PSGI to choke", - $response->[1] ); + $response->[1] + ); + + # Somewhere between 1.0028 and 1.0031 Plack changed so that the + # FauxObject case became a 500 rather than a die; in case it later does + # the same thing for other stuff, just accept either sort of error + + my $res = eval { run_request( GET => 'http://localhost/' ) }; + + if ($res) { + ok $res->is_error, $message; + } else { + like $@, qr/Can't call method "request" on an undefined value .*MockHTTP/, $message; + } undef $@; } }