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.
54 my $content = get('foo/bar?test=1');
58 Returns a C<HTTP::Response> object.
60 my $res =request('foo/bar?test=1');
68 my ( $get, $request );
70 if ( $ENV{CATALYST_SERVER} ) {
71 $request = sub { remote_request(@_) };
72 $get = sub { remote_request(@_)->content };
78 unless ( $INC{'Test/Builder.pm'} ) {
79 die qq/Couldn't load "$class", "$@"/ 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;
99 require LWP::UserAgent;
101 unless ( ref $request ) {
103 my $uri = ( $request =~ m/http/i )
105 : URI->new( 'http://localhost' . $request );
107 $request = $uri->canonical;
110 unless ( ref $request eq 'HTTP::Request' ) {
111 $request = HTTP::Request->new( 'GET', $request );
114 my $server = URI->new( $ENV{CATALYST_SERVER} );
116 if ( $server->path =~ m|^(.+)?/$| ) {
117 $server->path("$1"); # need to be quoted
120 $request->uri->scheme( $server->scheme );
121 $request->uri->host( $server->host );
122 $request->uri->port( $server->port );
123 $request->uri->path( $server->path . $request->uri->path );
126 $agent = LWP::UserAgent->new(
135 return $agent->request($request);
144 Sebastian Riedel, C<sri@cpan.org>
148 This program is free software, you can redistribute it and/or modify it under
149 the same terms as Perl itself.