Commit | Line | Data |
fc7ec1d9 |
1 | package Catalyst::Test; |
2 | |
3 | use strict; |
4 | use UNIVERSAL::require; |
fc7ec1d9 |
5 | |
e05c5e3c |
6 | $ENV{CATALYST_ENGINE} = 'Test'; |
fc7ec1d9 |
7 | |
8 | =head1 NAME |
9 | |
10 | Catalyst::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 | |
44 | Test Catalyst applications. |
45 | |
46 | =head2 METHODS |
47 | |
48 | =head3 get |
49 | |
50 | Returns the content. |
51 | |
52 | my $content = get('foo/bar?test=1'); |
53 | |
54 | =head3 request |
55 | |
56 | Returns a C<HTTP::Response> object. |
57 | |
58 | my $res =request('foo/bar?test=1'); |
59 | |
60 | =cut |
61 | |
fc7ec1d9 |
62 | sub 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 | |
79 | L<Catalyst>. |
80 | |
81 | =head1 AUTHOR |
82 | |
83 | Sebastian Riedel, C<sri@cpan.org> |
84 | |
85 | =head1 COPYRIGHT |
86 | |
87 | This program is free software, you can redistribute it and/or modify it under |
88 | the same terms as Perl itself. |
89 | |
90 | =cut |
91 | |
92 | 1; |