Dancer2

 view release on metacpan or  search on metacpan

t/dancer-test.t  view on Meta::CPAN

# who test the tester? We do!

use strict;
use warnings;
use Ref::Util qw<is_arrayref>;
use Path::Tiny ();

BEGIN {
    # Disable route handlers so we can actually test route_exists
    # and route_doesnt_exist. Use config that disables default route handlers.
    $ENV{DANCER_CONFDIR} = Path::Tiny::path( __FILE__ )->parent->child('dancer-test')->stringify;
}

use Test::More tests => 46;

use Dancer2;
use Dancer2::Test;
use Dancer2::Core::Request;
use File::Temp;
use Encode;
use URI::Escape;

$Dancer2::Test::NO_WARN = 1;

my @routes = (
    '/foo',
    [ GET => '/foo' ],
    Dancer2::Core::Request->new(
        env => {
            'psgi.url_scheme' => 'http',
            REQUEST_METHOD    => 'GET',
            QUERY_STRING      => '',
            SERVER_NAME       => 'localhost',
            SERVER_PORT       => 5000,
            SERVER_PROTOCOL   => 'HTTP/1.1',
            SCRIPT_NAME       => '',
            PATH_INFO         => '/foo',
            REQUEST_URI       => '/foo',
        }
    ),
);
my $fighter = Dancer2::Core::Response->new(
    content => 'fighter',
    status  => 404,
);

route_doesnt_exist $_ for (@routes, $fighter);


get '/foo' => sub {'fighter'};

route_exists $_, "route $_ exists" for @routes;

$fighter->status(200);
push @routes, $fighter;

for (@routes) {
    my $response = dancer_response $_;
    isa_ok $response      => 'Dancer2::Core::Response';
    is $response->content => 'fighter';
}

response_content_is $_ => 'fighter', "response_content_is with $_" for @routes;
response_content_isnt $_ => 'platypus', "response_content_isnt with $_"
  for @routes;



( run in 1.538 second using v1.01-cache-2.11-cpan-39bf76dae61 )