X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FTest.pm;h=3af0f151f677f318a863b412b9482e04597869c5;hb=b39840dab69d787e608212d070f7ab4a29204f5f;hp=10c52a5e5f969e992c9f8a2d5b62aa0a363a3701;hpb=aa777f5683889f7a5fe8b3352cde20dde8f35a3d;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 10c52a5..3af0f15 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -1,10 +1,31 @@ package Catalyst::Test; use strict; +use warnings; + +use Catalyst::Exception; +use Catalyst::Utils; use UNIVERSAL::require; +use HTTP::Headers; $ENV{CATALYST_ENGINE} = 'Test'; +# Bypass a HTTP::Headers bug +{ + no warnings 'redefine'; + + sub HTTP::Headers::new { + my $class = shift; + my $self = bless {}, $class; + if (@_) { + while ( my ( $field, $val ) = splice( @_, 0, 2 ) ) { + $self->push_header( $field, $val ); + } + } + return $self; + } +} + =head1 NAME Catalyst::Test - Test Catalyst applications @@ -20,19 +41,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; @@ -59,7 +80,7 @@ Returns the content. Returns a C object. - my $res =request('foo/bar?test=1'); + my $res = request('foo/bar?test=1'); =cut @@ -76,9 +97,7 @@ sub import { else { $class->require; - my $error = $UNIVERSAL::require::ERROR; - die qq/Couldn't load "$class", "$error"/ if $@; - + die if $@ && $@ !~ /^Can't locate /; $class->import; $request = sub { $class->run(@_) }; @@ -95,28 +114,15 @@ 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 ); - - $request = $uri->canonical; - } - - unless ( ref $request eq 'HTTP::Request' ) { - $request = HTTP::Request->new( 'GET', $request ); - } + my $request = Catalyst::Utils::request( shift(@_) ); my $server = URI->new( $ENV{CATALYST_SERVER} ); @@ -130,13 +136,13 @@ sub remote_request { $request->uri->path( $server->path . $request->uri->path ); unless ($agent) { - $agent = LWP::UserAgent->new( - # cookie_jar => {}, + $agent = LWP::UserAgent->new( keep_alive => 1, max_redirect => 0, timeout => 60, ); + $agent->env_proxy; }