X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FTest.pm;h=eff1a43c86b6d3b7d6f351f9f2910f6e57ca0b7f;hb=146554c575f7f9fda102985196e0b6b364847bc0;hp=3de24ad53cb2d8b9449ba91adfab3552c029a1e1;hpb=66d9e175a28989d4454714edf2cc2dab5ad64d96;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 3de24ad..eff1a43 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -20,7 +20,7 @@ Catalyst::Test - Test Catalyst applications get('index.html'); # Run tests against a remote server - CATALYST_REMOTE='http://localhost:3000/' prove -l lib/ t/ + CATALYST_SERVER='http://localhost:3000/' prove -l lib/ t/ # Tests with inline apps need to use Catalyst::Engine::Test package TestApp; @@ -47,13 +47,15 @@ Test Catalyst applications. =head2 METHODS -=head3 get +=over 4 + +=item get Returns the content. my $content = get('foo/bar?test=1'); -=head3 request +=item request Returns a C object. @@ -67,17 +69,20 @@ sub import { my ( $get, $request ); - if ( $ENV{CATALYST_REMOTE} ) { + if ( $ENV{CATALYST_SERVER} ) { $request = sub { remote_request(@_) }; $get = sub { remote_request(@_)->content }; } else { $class->require; + unless ( $INC{'Test/Builder.pm'} ) { die qq/Couldn't load "$class", "$@"/ if $@; } + $class->import; + $request = sub { $class->run(@_) }; $get = sub { $class->run(@_)->content }; } @@ -88,36 +93,58 @@ sub import { *{"$caller\::get"} = $get; } +my $agent; + +=item remote_request + +Do an actual remote rquest using LWP. + +=cut + sub remote_request { my $request = shift; require LWP::UserAgent; - my $remote = URI->new( $ENV{CATALYST_REMOTE} ); - unless ( ref $request ) { - my $uri = - ( $request =~ m/http/i ) + my $uri = ( $request =~ m/http/i ) ? URI->new($request) : URI->new( 'http://localhost' . $request ); $request = $uri->canonical; } - $request->scheme( $remote->scheme ); - $request->host( $remote->host ); - $request->port( $remote->port ); - unless ( ref $request eq 'HTTP::Request' ) { $request = HTTP::Request->new( 'GET', $request ); } - my $agent = LWP::UserAgent->new; + my $server = URI->new( $ENV{CATALYST_SERVER} ); + + if ( $server->path =~ m|^(.+)?/$| ) { + $server->path("$1"); # need to be quoted + } + + $request->uri->scheme( $server->scheme ); + $request->uri->host( $server->host ); + $request->uri->port( $server->port ); + $request->uri->path( $server->path . $request->uri->path ); + + unless ($agent) { + $agent = LWP::UserAgent->new( + # cookie_jar => {}, + keep_alive => 1, + max_redirect => 0, + timeout => 60, + ); + $agent->env_proxy; + } return $agent->request($request); } +=back + =head1 SEE ALSO L.