X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FTest.pm;h=84ba98ad986d4e487ba2ee637b3dc453b8c8682b;hp=349e80a8df35eb6f5f037a160b6aef76352d05b2;hb=a7daf37e6f5527ee3a601bffb3df321e53327d89;hpb=16d306fa5433396d8716b6f108a7d7db070b6bce diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 349e80a..84ba98a 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -6,7 +6,6 @@ use warnings; use Catalyst::Exception; use Catalyst::Utils; use Class::Inspector; -use UNIVERSAL::require; =head1 NAME @@ -56,6 +55,17 @@ Returns the content. my $content = get('foo/bar?test=1'); +Note that this method doesn't follow redirects, so to test for a +correctly redirecting page you'll need to use a combination of this +method and the L method below: + + my $res = request('/'); # redirects to /y + warn $res->header('location'); + use URI; + my $uri = URI->new($res->header('location')); + is ( $uri->path , '/y'); + my $content = get($uri->path); + =head2 request Returns a C object. @@ -73,12 +83,12 @@ sub import { if ( $ENV{CATALYST_SERVER} ) { $request = sub { remote_request(@_) }; $get = sub { remote_request(@_)->content }; - } - - else { + } elsif (! $class) { + $request = sub { Catalyst::Exception->throw("Must specify a test app: use Catalyst::Test 'TestApp'") }; + $get = $request; + } else { unless( Class::Inspector->loaded( $class ) ) { - $class->require; - die $@ if $@; + require Class::Inspector->filename( $class ); } $class->import; @@ -126,6 +136,21 @@ sub remote_request { if ( $server->path =~ m|^(.+)?/$| ) { $server->path("$1"); # need to be quoted + } + + # the request path needs to be sanitised if $server is using a + # non-root path due to potential overlap between request path and + # response path. + if ($server->path) { + my @sp = split '/', $server->path; + my @rp = split '/', $request->uri->path; + shift @sp;shift @rp; # leading / + if (@rp) { + foreach my $sp (@sp) { + $sp eq $rp[0] ? shift @rp : last + } + } + $request->uri->path(join '/', @rp); } $request->uri->scheme( $server->scheme );