The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Plack::Test::Simple::Transaction - PSGI Automated Application Testing Layer

VERSION

version 0.02

SYNOPSIS

    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;

DESCRIPTION

Plack::Test::Simple::Transaction is a container for testing HTTP transactions against a PSGI web application.

ATTRIBUTES

data

The data attribute contains the pre-processed data found in the HTTP response body.

psgi

The psgi attribute contains a coderef containing the PSGI compliant application code.

request

The request attribute contains the HTTP::Request object which will be used to process the HTTP requests.

response

The response attribute contains the HTTP::Response object which will be automatically set upon resolving the corresponding HTTP requests.

METHODS

content_is

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');

content_isnt

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');

content_like

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');

content_unlike

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');

data_has

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');

data_hasnt

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');

data_is_deeply

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');

data_match

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');

header_is

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');

header_isnt

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');

header_like

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');

header_unlike

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');

status_is

The status_is method tests if the HTTP response code matches the value specified.

    $self->status_is(404);
    $self->status_is(404 => 'test description');

status_isnt

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');

AUTHOR

Al Newkirk <anewkirk@ana.io>

COPYRIGHT AND LICENSE

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.