1 package Catalyst::Test;
6 use UNIVERSAL::require;
8 $ENV{CATALYST_ENGINE} = 'Test';
12 Catalyst::Test - Test Catalyst applications
20 use Catalyst::Test 'TestApp';
21 request('index.html');
24 # Run tests against a remote server
25 CATALYST_SERVER='http://localhost:3000/' prove -l lib/ t/
27 # Tests with inline apps need to use Catalyst::Engine::Test
30 use Catalyst qw[-Engine=Test];
33 my ( $self, $c ) = @_;
34 $c->res->output('bar');
41 use Test::More tests => 1;
42 use Catalyst::Test 'TestApp';
44 ok( get('/foo') =~ /bar/ );
48 Test Catalyst applications.
58 my $content = get('foo/bar?test=1');
62 Returns a C<HTTP::Response> object.
64 my $res =request('foo/bar?test=1');
72 my ( $get, $request );
74 if ( $ENV{CATALYST_SERVER} ) {
75 $request = sub { remote_request(@_) };
76 $get = sub { remote_request(@_)->content };
81 my $error = $UNIVERSAL::require::ERROR;
82 die qq/Couldn't load "$class", "$error"/ 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.
106 require LWP::UserAgent;
108 my $request = Catalyst::Utils::request( shift(@_) );
110 my $server = URI->new( $ENV{CATALYST_SERVER} );
112 if ( $server->path =~ m|^(.+)?/$| ) {
113 $server->path("$1"); # need to be quoted
116 $request->uri->scheme( $server->scheme );
117 $request->uri->host( $server->host );
118 $request->uri->port( $server->port );
119 $request->uri->path( $server->path . $request->uri->path );
123 $agent = LWP::UserAgent->new(
132 return $agent->request($request);
143 Sebastian Riedel, C<sri@cpan.org>
147 This program is free software, you can redistribute it and/or modify it under
148 the same terms as Perl itself.