Dancer2
view release on metacpan or search on metacpan
lib/Dancer2/Test.pm view on Meta::CPAN
package Dancer2::Test;
# ABSTRACT: Useful routines for testing Dancer2 apps
$Dancer2::Test::VERSION = '2.1.0';
use strict;
use warnings;
use Carp qw<carp croak>;
use Test::More;
use Test::Builder;
use URI::Escape;
use Data::Dumper;
use File::Temp;
use Ref::Util qw<is_arrayref>;
use parent 'Exporter';
our @EXPORT = qw(
dancer_response
response_content_is
response_content_isnt
response_content_is_deeply
response_content_like
response_content_unlike
response_status_is
response_status_isnt
response_headers_include
response_headers_are_deeply
response_is_file
route_exists
route_doesnt_exist
is_pod_covered
route_pod_coverage
);
#dancer1 also has read_logs, response_redirect_location_is
#cf. https://github.com/PerlDancer2/Dancer22/issues/25
use Dancer2::Core::MIME;
use Dancer2::Core::Dispatcher;
use Dancer2::Core::Request;
# singleton to store all the apps
my $_dispatcher = Dancer2::Core::Dispatcher->new;
# prevent deprecation warnings
our $NO_WARN = 0;
# can be called with the ($method, $path, $option) triplet,
# or can be fed a request object directly, or can be fed
# a single string, assumed to be [ GET => $string ]
# or can be fed a response (which is passed through without
# any modification)
sub dancer_response {
croak 'DEPRECATED: Dancer2::Test. Please use Plack::Test instead'
unless $NO_WARN;
_find_dancer_apps_for_dispatcher();
# useful for the high-level tests
return $_[0] if ref $_[0] eq 'Dancer2::Core::Response';
my ( $request, $env ) =
ref $_[0] eq 'Dancer2::Core::Request'
? _build_env_from_request(@_)
: _build_request_from_env(@_);
# override the set_request so it actually sets our request instead
( run in 0.800 second using v1.01-cache-2.11-cpan-39bf76dae61 )