diff --git a/lib/Plack/Test.pm b/lib/Plack/Test.pm index 2596324f5..20dc1f3ad 100644 --- a/lib/Plack/Test.pm +++ b/lib/Plack/Test.pm @@ -42,8 +42,16 @@ Plack::Test - Test PSGI applications with various backends =head1 SYNOPSIS use Plack::Test; + use HTTP::Request::Common; + + # Simple OO interface + my $app = sub { return [ 200, [], [ "Hello "] ] }; + my $test = Plack::Test->create($app); + + my $res = $test->request(GET "/"); + is $res->content, "Hello"; - # named params + # traditional - named params test_psgi app => sub { my $env = shift; @@ -56,16 +64,13 @@ Plack::Test - Test PSGI applications with various backends like $res->content, qr/Hello World/; }; - use HTTP::Request::Common; - - # positional params (app, client) - my $app = sub { return [ 200, [], [ "Hello "] ] }; - test_psgi $app, sub { - my $cb = shift; - my $res = $cb->(GET "/"); - is $res->content, "Hello"; - }; - + # positional params (app, client) + my $app = sub { return [ 200, [], [ "Hello "] ] }; + test_psgi $app, sub { + my $cb = shift; + my $res = $cb->(GET "/"); + is $res->content, "Hello"; + }; =head1 DESCRIPTION @@ -75,8 +80,32 @@ applications in various ways. The default backend is C, but you may also use any L implementation to run live HTTP requests against a web server. +=head1 METHODS + +=over 4 + +=item create + + $test = Plack::Test->create($app, %options); + +creates an instance of Plack::Test implementation class. C<$app> has +to be a valid PSGI application code reference. + +=item request + + $res = $test->request($request); + +takes an HTTP::Request object, runs it through the PSGI application to +test and returns an HTTP::Response object. + +=back + =head1 FUNCTIONS +Plack::Test also provides a functional interface that takes two +callbacks, each of which represents PSGI application and HTTP client +code that tests the application. + =over 4 =item test_psgi