| 1 |
use Test::More; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Plack::Test; |
| 5 |
use HTTP::Request::Common; |
| 6 |
use Capture::Tiny 'capture_stderr'; |
| 7 |
use Ref::Util qw<is_coderef>; |
| 8 |
|
| 9 |
{ |
| 10 |
package App; |
| 11 |
use Dancer2; |
| 12 |
|
| 13 |
set logger => 'console'; |
| 14 |
|
| 15 |
hook 'before' => sub { |
| 16 |
die 'test die inside a before hook'; |
| 17 |
print STDERR "error message not caught in the before hook\n"; |
| 18 |
}; |
| 19 |
|
| 20 |
get '/' => sub { |
| 21 |
print STDERR "error message not caught in the route handler\n"; |
| 22 |
}; |
| 23 |
} |
| 24 |
|
| 25 |
my $app = App->to_app; |
| 26 |
ok( is_coderef($app), 'Got app' ); |
| 27 |
|
| 28 |
test_psgi $app, sub { |
| 29 |
my $cb = shift; |
| 30 |
my $message = capture_stderr { $cb->( GET '/' ) }; |
| 31 |
|
| 32 |
like |
| 33 |
$message, |
| 34 |
qr/test die inside a before hook/, |
| 35 |
'Got error message when a before hook dies'; |
| 36 |
}; |
| 37 |
|
| 38 |
done_testing; |