Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Jul 12, 2013
1 parent 1985ac4 commit 40daf7e
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions lib/Plack/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -75,8 +80,32 @@ applications in various ways. The default backend is C<Plack::Test::MockHTTP>,
but you may also use any L<Plack::Handler> 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
Expand Down

0 comments on commit 40daf7e

Please sign in to comment.