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 };
80 unless ( $INC{'Test/Builder.pm'} ) {
81 die qq/Couldn't load "$class", "$@"/ if $@;
86 $request = sub { $class->run(@_) };
87 $get = sub { $class->run(@_)->content };
91 my $caller = caller(0);
92 *{"$caller\::request"} = $request;
93 *{"$caller\::get"} = $get;
100 Do an actual remote rquest using LWP.
107 require LWP::UserAgent;
109 unless ( ref $request ) {
111 my $uri = ( $request =~ m/http/i )
113 : URI->new( 'http://localhost' . $request );
115 $request = $uri->canonical;
118 unless ( ref $request eq 'HTTP::Request' ) {
119 $request = HTTP::Request->new( 'GET', $request );
122 my $server = URI->new( $ENV{CATALYST_SERVER} );
124 if ( $server->path =~ m|^(.+)?/$| ) {
125 $server->path("$1"); # need to be quoted
128 $request->uri->scheme( $server->scheme );
129 $request->uri->host( $server->host );
130 $request->uri->port( $server->port );
131 $request->uri->path( $server->path . $request->uri->path );
134 $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.