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;
97 require LWP::UserAgent;
99 my $server = URI->new( $ENV{CATALYST_SERVER} );
101 unless ( ref $request ) {
104 ( $request =~ m/http/i )
106 : URI->new( 'http://localhost' . $request );
108 $request = $uri->canonical;
111 $request->scheme( $server->scheme );
112 $request->host( $server->host );
113 $request->port( $server->port );
115 unless ( ref $request eq 'HTTP::Request' ) {
116 $request = HTTP::Request->new( 'GET', $request );
119 my $agent = LWP::UserAgent->new;
121 return $agent->request($request);
130 Sebastian Riedel, C<sri@cpan.org>
134 This program is free software, you can redistribute it and/or modify it under
135 the same terms as Perl itself.