From: Christian Walde Date: Fri, 22 Nov 2013 13:56:32 +0000 (+0100) Subject: consolidate tests for invalid psgi responses X-Git-Tag: v0.021~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=19b1ef0b2bbd6639d672d1541c635dc086b4fba2;hp=24ecd3bd2cf188c1909b62228a55dd6b5eca3d2e consolidate tests for invalid psgi responses --- diff --git a/t/dispatch_misc.t b/t/dispatch_misc.t index 0c11f2c..6941513 100644 --- a/t/dispatch_misc.t +++ b/t/dispatch_misc.t @@ -23,8 +23,7 @@ sub run_request { $app->run_test_request( @_ ); } app_is_non_plack(); plack_app_return(); broken_route_def(); -array_with_sub(); -array_with_no_sub(); +invalid_psgi_responses(); middleware_as_only_route(); route_returns_middleware_plus_extra(); route_returns_undef(); @@ -78,35 +77,25 @@ sub broken_route_def { like $get->content, qr[No idea how we got here with /], "the error message points out the broken definition"; } -sub array_with_sub { - @dispatch = ( - sub (/) { - [ - sub { - [ 999, [], [""] ]; - }, - ]; - } - ); - - eval { run_request( GET => 'http://localhost/' ) }; - - like $@, qr/Can't call method "request" on an undefined value .*MockHTTP/, -"if a route returns an arrayref with a single sub in it, then that sub is returned as a response by WD, causing HTTP::Message::PSGI to choke"; -} +sub invalid_psgi_responses { + undef $@; -sub array_with_no_sub { - @dispatch = ( - sub (/) { - ["moo"]; - } + my @responses = ( + [ [ sub { } ], "an arrayref with a single sub in it" ], + [ ["moo"], "an arrayref with a scalar that is not a sub" ], ); - eval { run_request( GET => 'http://localhost/' ) }; + for my $response ( @responses ) { + @dispatch = ( sub (/) { $response->[0] } ); - like $@, qr/Can't call method "request" on an undefined value .*MockHTTP/, -"if a route returns an arrayref with a scalar that is not a sub, then WD returns that array out of the PSGI app (and causes HTTP::Message::PSGI to choke)"; - undef $@; + eval { run_request( GET => 'http://localhost/' ) }; + + like $@, qr/Can't call method "request" on an undefined value .*MockHTTP/, + sprintf( + "if a route returns %s, then that is returned as a response by WD, causing HTTP::Message::PSGI to choke", + $response->[1] ); + undef $@; + } } sub middleware_as_only_route {