Plack::Test::Simple::Transaction - PSGI Automated Application Testing Layer
version 0.02
use Test::More; use Plack::Test::Simple::Transaction; # prepare test container my $tx = Plack::Test::Simple::Transaction->new('/path/to/app.psgi'); my $req = $tx->request; # get request setup $req->method('GET'); $request->uri(URI->new('/path/to/resource')); $req->headers->authorization_basic('h@cker', 's3cret'); $req->headers->content_type('application/json'); $request->content('...'); # test the requesting $tx->content_like(qr/hello world/i, 'test description'); done_testing;
Plack::Test::Simple::Transaction is a container for testing HTTP transactions against a PSGI web application.
The data attribute contains the pre-processed data found in the HTTP response body.
The psgi attribute contains a coderef containing the PSGI compliant application code.
The request attribute contains the HTTP::Request object which will be used to process the HTTP requests.
The response attribute contains the HTTP::Response object which will be automatically set upon resolving the corresponding HTTP requests.
The content_is method tests if the decoded HTTP response body matches the value specified.
$self->content_is($value); $self->content_is($value => 'test description');
The content_isnt method tests if the decoded HTTP response body does not match the value specified.
$self->content_isnt($value); $self->content_isnt($value => 'test description');
The content_like method tests if the decoded HTTP response body contains matches for the regex value specified.
$self->content_like(qr/body/); $self->content_like(qr/body/ => 'test description');
The content_unlike method tests if the decoded HTTP response body does not contain matches for the regex value specified.
$self->content_isnt(qr/body/); $self->content_is(qr/body/ => 'test description');
The data_has method tests if the decoded HTTP response data structure contains matches for the Data::DPath path value specified.
$self->data_has('/results'); $self->data_has('/results' => 'test description');
The data_hasnt method tests if the decoded HTTP response data structure does not contain matches for the Data::DPath path value specified.
$self->data_hasnt('/results'); $self->data_hasnt('/results' => 'test description');
The data_is_deeply method tests if the decoded HTTP response data structure contains matches for the Data::DPath path value specified, then tests if the first match matches the supplied Perl data structure exactly.
$self->data_is_deeply('/results', $data); $self->data_is_deeply('/results', $data => 'test description');
The data_match method is an alias for the data_is_deeply method which tests if the decoded HTTP response data structure contains matches for the Data::DPath path value specified, then tests if the first match matches the supplied Perl data structure exactly.
$self->data_match('/results', $data); $self->data_match('/results', $data => 'test description');
The header_is method tests if the HTTP response header specified matches the value specified.
$self->header_is('Server', 'nginx'); $self->header_is('Server', 'nginx' => 'test description');
The header_isnt method tests if the HTTP response header specified does not match the value specified.
$self->header_isnt('Server', 'nginx'); $self->header_isnt('Server', 'nginx' => 'test description');
The header_like method tests if the HTTP response header specified contains matches for the regex value specified.
$self->header_like('Server', qr/nginx/); $self->header_like('Server', qr/nginx/ => 'test description');
The header_unlike method tests if the HTTP response header specified does not contain matches for the regex value specified.
$self->header_unlike('Server', qr/nginx/); $self->header_unlike('Server', qr/nginx/ => 'test description');
The status_is method tests if the HTTP response code matches the value specified.
$self->status_is(404); $self->status_is(404 => 'test description');
The status_isnt method tests if the HTTP response code does not match the value specified.
$self->status_isnt(404); $self->status_isnt(404 => 'test description');
Al Newkirk <anewkirk@ana.io>
This software is copyright (c) 2013 by Al Newkirk.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::Test::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Test::Simple
CPAN shell
perl -MCPAN -e shell install Plack::Test::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.