Fixed multiple header bug
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Test.pm
index a9f74e5..3af0f15 100644 (file)
@@ -1,12 +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
@@ -22,7 +41,7 @@ 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;
@@ -61,7 +80,7 @@ Returns the content.
 
 Returns a C<HTTP::Response> object.
 
-    my $res =request('foo/bar?test=1');
+    my $res = request('foo/bar?test=1');
 
 =cut
 
@@ -78,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(@_) };
@@ -97,17 +114,17 @@ my $agent;
 
 =item remote_request
 
-Do an actual remote rquest using LWP.
+Do an actual remote request using LWP.
 
 =cut
 
 sub remote_request {
 
-    require LWP::UserAgent; 
-    
+    require LWP::UserAgent;
+
     my $request = Catalyst::Utils::request( shift(@_) );
 
-    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
@@ -118,7 +135,7 @@ sub remote_request {
     $request->uri->port( $server->port );
     $request->uri->path( $server->path . $request->uri->path );
 
-    unless ( $agent ) {
+    unless ($agent) {
 
         $agent = LWP::UserAgent->new(
             keep_alive   => 1,