1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!perl
use strict;
use warnings;
use Test::More tests => 10;
use Plack::Test;
use HTTP::Request::Common;
my $before;
{
package OurApp;
use Dancer2 '!pass';
use Test::More;
hook before => sub {
my $ctx = shift;
isa_ok(
$ctx,
'Dancer2::Core::App',
'Context is actually an app now',
);
is( $ctx->name, 'OurApp', 'It is the correct app' );
can_ok( $ctx, 'app' );
my $app = $ctx->app;
isa_ok(
$app,
'Dancer2::Core::App',
'When called ->app, we get te app again',
);
is( $app->name, 'OurApp', 'It is the correct app' );
is( $ctx, $app, 'Same exact application (by reference)' );
$before++;
};
get '/' => sub {'OK'};
}
my $app = OurApp->to_app;
isa_ok( $app, 'CODE', 'Got app' );
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->( GET '/' );
is( $res->code, 200, '[GET /] status OK' );
is( $res->content, 'OK', '[GET /] content OK' );
ok( $before == 1, 'before hook called' );
};
|