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