NAME
Test::WWW::Mechanize::JSON - Add a JSON and AJAXy methods to the super-class
SYNOPSIS
use Test::More 'no_plan';
use_ok("Test::WWW::Mechanize::JSON") or BAIL_OUT;
my $MECH = Test::WWW::Mechanize::JSON->new(
noproxy => 1,
etc => 'other-params-for-Test::WWW::Mechanize',
);
$MECH->get('http://example.com/json');
my $json_as_perl = $MECH->json_ok or BAIL_OUT Dumper $MECH->response;
$MECH->diag_json;
DESCRIPTION
Extends Test::WWW::Mechanize to test JSON content in response bodies and x-json
headers.
It adds a few HTTP verbs to Mechanize, for convenience.
METHODS: HTTP VERBS
$mech->put
An HTTP 'put' request, extending HTTP::Request::Common.
At the time of wriring, modules that rely on HTTP::Request::Common treat PUT
as a type of GET
, when the spec says it is really a type of POST
:
The fundamental difference between the POST and PUT
requests is reflected in the different meaning of
the Request-URI.
HTTP specification
$mech->delete
An HTTP 'delete' request, extending HTTP::Request::Common.
$mech->options
An HTTP 'options' request, extending HTTP::Request::Common.
$mech->head
An HTTP 'head' request, using HTTP::Request::Common.
METHODS: ASSERTIONS
$mech->json_ok($desc)
Tests that the last received resopnse body is valid JSON.
A default description of "Got JSON from $url" or "Not JSON from $url" is used if none if provided.
Returns the JSON object, that you may perform further tests upon it.
$mech->x_json_ok($desc)
As $mech-
json_ok($desc)> but examines the x-json
header.
any_json_ok( $desc )
Like the other JSON methods, but passes if the response contained JSON in the content or x-json
header.
$mech->diag_json
Like diag, but renders the JSON of body the last request with indentation.
$mech->diag_x_json
Like diag, but renders the JSON from the x-json
header of the last request with indentation.
$mech->utf8_ok( $desc )
Passes if the last response contained a charset=utf-8
definition in its content-type header.
AUTHOR AND COPYRIGHT
Copyright (C) Lee Goddard, 2009/2011.
Available under the same terms as Perl itself.