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