File: | t/03-dev-error.t |
Coverage: | 87.1% |
line | stmt | time | code |
---|---|---|---|
1 | 1 1 1 | 8925 4 50 | use strict; |
2 | 1 1 1 | 7 2 57 | use warnings; |
3 | 1 1 1 | 828 4796 121 | use Try::Tiny; |
4 | 1 1 1 | 916 32405 14 | use Test::More tests => 9; |
5 | 1 1 1 | 1323 159 365658 | use Dancer::Plugin::BeforeRoute; |
6 | |||
7 | my @cases = ( | ||
8 | { subject => "missing method", | ||
9 | path => "/foobar", | ||
10 | 0 | 0 | subref => sub { }, |
11 | error => qr/missing method/, | ||
12 | }, | ||
13 | { subject => "single method", | ||
14 | method => "get", | ||
15 | path => "/foobar", | ||
16 | 0 | 0 | subref => sub { }, |
17 | }, | ||
18 | { subject => "multiple methods", | ||
19 | methods => [ "get", "post", "put", "del" ], | ||
20 | path => "/foobar", | ||
21 | 0 | 0 | subref => sub { }, |
22 | }, | ||
23 | { subject => "missing path", | ||
24 | methods => "put", | ||
25 | 0 | 0 | subref => sub { }, |
26 | 1 | 61 | error => qr/missing path/, |
27 | }, | ||
28 | { subject => "missing subref", | ||
29 | methods => "del", | ||
30 | path => "/foobar", | ||
31 | error => qr/missing a subref/, | ||
32 | }, | ||
33 | ); | ||
34 | |||
35 | 1 | 5 | foreach my $case (@cases) { |
36 | try { | ||
37 | 5 | 303 | my $methods = $case->{method} || $case->{methods}; |
38 | 5 | 25 | my ( $path, $subref, @methods ) |
39 | = Dancer::Plugin::BeforeRoute::_args( $methods, | ||
40 | @$case{qw( path subref )} ); | ||
41 | 2 | 8 | if ( $case->{method} ) { |
42 | 1 | 9 | is_deeply [ $case->{method} ], \@methods, |
43 | "$case->{subject} - method ok"; | ||
44 | } | ||
45 | elsif ( $case->{methods} ) { | ||
46 | 1 | 7 | is_deeply $case->{methods}, \@methods, |
47 | "$case->{subject} - methods ok"; | ||
48 | } | ||
49 | 2 | 1836 | is $case->{path}, $path, "$case->{subject} - path ok"; |
50 | 2 | 933 | is $case->{subref}, $subref, "$case->{subject} - got a subref"; |
51 | } | ||
52 | catch { | ||
53 | 3 | 46 | my $error = $_; |
54 | 3 | 16 | like $error, $case->{error}, $case->{subject}; |
55 | } | ||
56 | 5 | 2029 | } |