added synopsis to Engine subclassed and documented a couple of methods to make podcov...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Test.pm
CommitLineData
fc7ec1d9 1package Catalyst::Test;
2
3use strict;
4use UNIVERSAL::require;
fc7ec1d9 5
e05c5e3c 6$ENV{CATALYST_ENGINE} = 'Test';
fc7ec1d9 7
8=head1 NAME
9
10Catalyst::Test - Test Catalyst applications
11
12=head1 SYNOPSIS
13
49faa307 14 # Helper
49faa307 15 script/test.pl
16
fc7ec1d9 17 # Tests
18 use Catalyst::Test 'TestApp';
19 request('index.html');
20 get('index.html');
21
b6898a9f 22 # Tests with inline apps need to use Catalyst::Engine::Test
23 package TestApp;
24
25 use Catalyst qw[-Engine=Test];
26
27 __PACKAGE__->action(
28 foo => sub {
29 my ( $self, $c ) = @_;
30 $c->res->output('bar');
31 }
32 );
33
34 package main;
35
36 use Test::More tests => 1;
37 use Catalyst::Test 'TestApp';
38
39 ok( get('/foo') =~ /bar/ );
40
fc7ec1d9 41
fc7ec1d9 42=head1 DESCRIPTION
43
44Test Catalyst applications.
45
46=head2 METHODS
47
48=head3 get
49
50Returns the content.
51
52 my $content = get('foo/bar?test=1');
53
54=head3 request
55
56Returns a C<HTTP::Response> object.
57
58 my $res =request('foo/bar?test=1');
59
60=cut
61
fc7ec1d9 62sub import {
63 my $self = shift;
d8c1e612 64 if ( my $class = shift ) {
bc024080 65 $class->require;
66 unless ( $INC{'Test/Builder.pm'} ) {
67 die qq/Couldn't load "$class", "$@"/ if $@;
68 }
e646f111 69
bc024080 70 no strict 'refs';
e646f111 71 my $caller = caller(0);
72 *{"$caller\::request"} = sub { $class->run(@_) };
73 *{"$caller\::get"} = sub { $class->run(@_)->content };
49faa307 74 }
fc7ec1d9 75}
76
fc7ec1d9 77=head1 SEE ALSO
78
79L<Catalyst>.
80
81=head1 AUTHOR
82
83Sebastian Riedel, C<sri@cpan.org>
84
85=head1 COPYRIGHT
86
87This program is free software, you can redistribute it and/or modify it under
88the same terms as Perl itself.
89
90=cut
91
921;