X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FTest.pm;h=8157bf32f6ba307120fab1140552f0be29d052ab;hb=21465c884872c1ec8c30acd72796445f9eaacb31;hp=10d5c3ea6335cd97100c0c28c1899b8c525a1883;hpb=9ffadf88044260afc4dfb058cbfc08a3b0a803f0;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 10d5c3e..8157bf3 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -1,6 +1,9 @@ package Catalyst::Test; use strict; + +use Catalyst::Exception; +use Catalyst::Utils; use UNIVERSAL::require; $ENV{CATALYST_ENGINE} = 'Test'; @@ -20,19 +23,19 @@ Catalyst::Test - Test Catalyst applications get('index.html'); # Run tests against a remote server - CATALYST_SERVER='http://localhost:3000/' prove -l lib/ t/ + CATALYST_SERVER='http://localhost:3000/' prove -r -l lib/ t/ # Tests with inline apps need to use Catalyst::Engine::Test package TestApp; use Catalyst qw[-Engine=Test]; - __PACKAGE__->action( - foo => sub { + sub foo : Global { my ( $self, $c ) = @_; $c->res->output('bar'); - } - ); + } + + __PACKAGE__->setup(); package main; @@ -76,11 +79,14 @@ sub import { else { $class->require; - my $error = $UNIVERSAL::require::ERROR; - die qq/Couldn't load "$class", "$error"/ if $error; - - unless ( $INC{'Test/Builder.pm'} ) { - die qq/Couldn't load "$class", "$@"/ if $@; + + if ( $@ ) { + + my $error = $UNIVERSAL::require::ERROR; + + Catalyst::Exception->throw( + message => qq/Couldn't load "$class", "$error"/ + ); } $class->import; @@ -99,30 +105,17 @@ my $agent; =item remote_request -Do an actual remote rquest using LWP. +Do an actual remote request using LWP. =cut sub remote_request { - my $request = shift; - - require LWP::UserAgent; - - unless ( ref $request ) { - my $uri = - ( $request =~ m/http/i ) - ? URI->new($request) - : URI->new( 'http://localhost' . $request ); + require LWP::UserAgent; + + my $request = Catalyst::Utils::request( shift(@_) ); - $request = $uri->canonical; - } - - unless ( ref $request eq 'HTTP::Request' ) { - $request = HTTP::Request->new( 'GET', $request ); - } - - my $server = URI->new( $ENV{CATALYST_SERVER} ); + my $server = URI->new( $ENV{CATALYST_SERVER} ); if ( $server->path =~ m|^(.+)?/$| ) { $server->path("$1"); # need to be quoted @@ -133,14 +126,14 @@ sub remote_request { $request->uri->port( $server->port ); $request->uri->path( $server->path . $request->uri->path ); - unless ($agent) { - $agent = LWP::UserAgent->new( + unless ( $agent ) { - # cookie_jar => {}, + $agent = LWP::UserAgent->new( keep_alive => 1, max_redirect => 0, timeout => 60, ); + $agent->env_proxy; }