DESCRIPTION

This module provides test helpers for testing Dancer apps.

Be careful, the module loading order in the example above is very important. Make sure to use Dancer::Testafter importing the application package otherwise your appdir will be automatically set to lib and your test script won't be able to find views, conffiles and other application content.

For all test methods, the first argument can be either an array ref of the method and route, or a scalar containing the route (in which case the method is assumed to be GET), or a Dancer::Response object.

$params is a hashref, $body is a string and $headers can be an arrayref or a HTTP::Headers object, $files is an arrayref of hashref, containing some files to upload.

A good reason to use this function is for testing POST requests. Since POST requests may not be idempotent, it is necessary to capture the content and status in one shot. Calling the response_status_is and response_content_is functions in succession would make two requests, each of which could alter the state of the application and cause Schrodinger's cat to die.

my $response = dancer_response POST => '/widgets';
is $response->{status}, 202, "response for POST /widgets is 202";
is $response->{content}, "Widget #1 has been scheduled for creation",
"response content looks good for first POST /widgets";
$response = dancer_response POST => '/widgets';
is $response->{status}, 202, "response for POST /widgets is 202";
is $response->{content}, "Widget #2 has been scheduled for creation",
"response content looks good for second POST /widgets";