File: 03_exceptions.t

package info (click to toggle)
libdancer-perl 1.3521%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,460 kB
  • sloc: perl: 7,436; xml: 2,211; sh: 54; makefile: 32; sql: 5
file content (38 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (6)
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
use strict;
use warnings;
use Test::More import => ['!pass'];

use Dancer ':syntax';
use Dancer::Test;

BEGIN { use_ok('Dancer::Exception', ':all'); }

set views => path( 't', '25_exceptions', 'views' );

{
    # raise in hook but catch it from route
    my $flag = 0;
    my $properly_caught_error = 0;
    hook before_template_render => sub {
        $flag++
          or raise Generic => 'foo5';
    };
    get '/raise_in_hook' => sub {
        try {
            # should raise
            template 'index', { foo => 'baz5' };
        } catch {
            $properly_caught_error = 1;
            # won't raise, flag is > 0
            template 'index', { foo => 'baz5' };
        }
    };
    route_exists [ GET => '/raise_in_hook' ];
    $flag = 0;
    response_status_is( [ GET => '/raise_in_hook' ], 200 => "route didn't error");
    is $properly_caught_error, 1, 'properly caught exception';
    $flag = 0;
    response_content_like( [ GET => '/raise_in_hook' ], qr|foo => baz5| );
}

done_testing();