1 package Catalyst::Test;
5 use Catalyst::Exception;
7 use UNIVERSAL::require;
9 $ENV{CATALYST_ENGINE} = 'Test';
13 Catalyst::Test - Test Catalyst applications
21 use Catalyst::Test 'TestApp';
22 request('index.html');
25 # Run tests against a remote server
26 CATALYST_SERVER='http://localhost:3000/' prove -r -l lib/ t/
28 # Tests with inline apps need to use Catalyst::Engine::Test
31 use Catalyst qw[-Engine=Test];
34 my ( $self, $c ) = @_;
35 $c->res->output('bar');
42 use Test::More tests => 1;
43 use Catalyst::Test 'TestApp';
45 ok( get('/foo') =~ /bar/ );
49 Test Catalyst applications.
59 my $content = get('foo/bar?test=1');
63 Returns a C<HTTP::Response> object.
65 my $res =request('foo/bar?test=1');
73 my ( $get, $request );
75 if ( $ENV{CATALYST_SERVER} ) {
76 $request = sub { remote_request(@_) };
77 $get = sub { remote_request(@_)->content };
82 die if $@ && $@ !~ /^Can't locate /;
85 $request = sub { $class->run(@_) };
86 $get = sub { $class->run(@_)->content };
90 my $caller = caller(0);
91 *{"$caller\::request"} = $request;
92 *{"$caller\::get"} = $get;
99 Do an actual remote request using LWP.
105 require LWP::UserAgent;
107 my $request = Catalyst::Utils::request( shift(@_) );
109 my $server = URI->new( $ENV{CATALYST_SERVER} );
111 if ( $server->path =~ m|^(.+)?/$| ) {
112 $server->path("$1"); # need to be quoted
115 $request->uri->scheme( $server->scheme );
116 $request->uri->host( $server->host );
117 $request->uri->port( $server->port );
118 $request->uri->path( $server->path . $request->uri->path );
122 $agent = LWP::UserAgent->new(
131 return $agent->request($request);
142 Sebastian Riedel, C<sri@cpan.org>
146 This program is free software, you can redistribute it and/or modify it under
147 the same terms as Perl itself.