1 package Catalyst::Test;
4 use UNIVERSAL::require;
6 $ENV{CATALYST_ENGINE} = 'Test';
10 Catalyst::Test - Test Catalyst applications
18 use Catalyst::Test 'TestApp';
19 request('index.html');
22 # Run tests against a remote server
23 CATALYST_SERVER='http://localhost:3000/' prove -l lib/ t/
25 # Tests with inline apps need to use Catalyst::Engine::Test
28 use Catalyst qw[-Engine=Test];
32 my ( $self, $c ) = @_;
33 $c->res->output('bar');
39 use Test::More tests => 1;
40 use Catalyst::Test 'TestApp';
42 ok( get('/foo') =~ /bar/ );
46 Test Catalyst applications.
56 my $content = get('foo/bar?test=1');
60 Returns a C<HTTP::Response> object.
62 my $res =request('foo/bar?test=1');
70 my ( $get, $request );
72 if ( $ENV{CATALYST_SERVER} ) {
73 $request = sub { remote_request(@_) };
74 $get = sub { remote_request(@_)->content };
79 my $error = $UNIVERSAL::require::ERROR;
80 die qq/Couldn't load "$class", "$error"/ if $@;
84 $request = sub { $class->run(@_) };
85 $get = sub { $class->run(@_)->content };
89 my $caller = caller(0);
90 *{"$caller\::request"} = $request;
91 *{"$caller\::get"} = $get;
98 Do an actual remote rquest using LWP.
105 require LWP::UserAgent;
107 unless ( ref $request ) {
110 ( $request =~ m/http/i )
112 : URI->new( 'http://localhost' . $request );
114 $request = $uri->canonical;
117 unless ( ref $request eq 'HTTP::Request' ) {
118 $request = HTTP::Request->new( 'GET', $request );
121 my $server = URI->new( $ENV{CATALYST_SERVER} );
123 if ( $server->path =~ m|^(.+)?/$| ) {
124 $server->path("$1"); # need to be quoted
127 $request->uri->scheme( $server->scheme );
128 $request->uri->host( $server->host );
129 $request->uri->port( $server->port );
130 $request->uri->path( $server->path . $request->uri->path );
133 $agent = LWP::UserAgent->new(
143 return $agent->request($request);
154 Sebastian Riedel, C<sri@cpan.org>
158 This program is free software, you can redistribute it and/or modify it under
159 the same terms as Perl itself.