Test::HTTP::Response - Perl testing module for HTTP responses
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);
0.06
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
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($response);
Takes list of arguments : response object, optional comment
Pass if response has status of 'OK', i.e. 200
status_redirect($response);
Pass if response has status of 'REDIRECT', i.e. 301
status_not_found($response);
Pass if response has status of 'NOT FOUND', i.e. 404
status_error($response);
Pass if response has status of 'OK', i.e. 500
header_matches($response, 'Content-type', 'Text/HTML', 'correct content type');
Test a list of headers at once
headers_match $response, { 'Content-Type' => /text/, 'Content-Length' => sub { $_ > 10 }, 'Cache-Control' => 'private, no-cache, no-store', };
Test all headers in a response. Fails if any header field is left untested.
all_headers_match $response, { 'Content-Type' => /text/, 'Content-Length' => sub { $_ > 10 }, 'Cache-Control' => 'private, no-cache, no-store', };
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
Get cookies from response as a nested hash
my $cookies = extract_cookies($response);
Takes 1 argument : HTTP::Response object
Returns hashref
HTTP::Request
LWP
Plack::Test
Catalyst::Test
Test::HTML::Form
Test::HTTP
Aaron Trevena, <teejay@cpan.org>
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.
To install Test::HTTP::Response, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::HTTP::Response
CPAN shell
perl -MCPAN -e shell install Test::HTTP::Response
For more information on module installation, please visit the detailed CPAN module installation guide.