call to $class->import in Catalyst::Test
[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 }
e519ff34 69 $class->import;
e646f111 70
bc024080 71 no strict 'refs';
e646f111 72 my $caller = caller(0);
73 *{"$caller\::request"} = sub { $class->run(@_) };
74 *{"$caller\::get"} = sub { $class->run(@_)->content };
49faa307 75 }
fc7ec1d9 76}
77
fc7ec1d9 78=head1 SEE ALSO
79
80L<Catalyst>.
81
82=head1 AUTHOR
83
84Sebastian Riedel, C<sri@cpan.org>
85
86=head1 COPYRIGHT
87
88This program is free software, you can redistribute it and/or modify it under
89the same terms as Perl itself.
90
91=cut
92
931;