NAME

Test::HTTP::Response - Perl testing module for HTTP responses

SYNOPSIS

use Test::HTTP::Response;

...

status_matches($response, 200, 'Response is ok');

status_ok($response);

status_redirect($response);

status_not_found($response);

status_error($response);

cookie_matches($response, { key => 'sessionid' },'sessionid exists ok'); # check matching cookie found in response

my $cookies = extract_cookies($response);

VERSION

0.03

DESCRIPTION

Simple Perl testing module for HTTP responses and cookies, inspired by Test::HTTP and designed to work nicely with web framework test tools such as Plack::Test and Catalyst::Test

FUNCTIONS

status_matches

Test that HTTP status of the response is (like) expected value

status_matches($response, 200, 'Response is ok');

Pass when status matches, fail when differs.

Takes 3 arguments : response object, expected HTTP status code (or quoted-regexp pattern), comment.

status_ok

status_ok($response);

Takes list of arguments : response object, optional comment

Pass if response has status of 'OK', i.e. 200

status_redirect

status_redirect($response);

Takes list of arguments : response object, optional comment

Pass if response has status of 'REDIRECT', i.e. 301

status_not_found

status_not_found($response);

Takes list of arguments : response object, optional comment

Pass if response has status of 'NOT FOUND', i.e. 404

status_error

status_error($response);

Takes list of arguments : response object, optional comment

Pass if response has status of 'OK', i.e. 500

header_matches

header_matches($response, 'Content-type', 'Text/HTML', 'correct content type');

Test that a cookie with matching attributes is in the response headers

cookie_matches($response, { key => 'sessionid' },'sessionid exists ok'); # check matching cookie found in response

Passes when match found, fails if no matches found.

Takes a list of arguments filename/response, hashref of attributes and strings or quoted-regexps to match, and optional test comment/name

extract_cookies

Get cookies from response as a nested hash

my $cookies = extract_cookies($response);

Takes 1 argument : HTTP::Response object

Returns hashref

SEE ALSO

HTTP::Request

LWP

Plack::Test

Catalyst::Test

Test::HTML::Form

Test::HTTP

AUTHOR

Aaron Trevena, <teejay@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2009 by Aaron Trevena

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.