Debian Codegraph @

t/dsl/any.t

raw
1 use strict;
2 use warnings;
3 use Test::More tests => 2;
4 use Plack::Test;
5 use HTTP::Request::Common;
6
7 {
8 package App;
9 use Dancer2;
10 any [ 'get', 'post' ] => '/test' => sub { request->method };
11 any '/all' => sub { request->method };
12 }
13
14 my $test = Plack::Test->create( App->to_app );
15
16 subtest 'any with params' => sub {
17 my @success = qw<GET POST>;
18 my @fails = qw<PUT DELETE OPTIONS PATCH NONEXIST>;
19
20 foreach my $method (@success) {
21 my $req = HTTP::Request->new( $method => '/test' );
22 is(
23 $test->request($req)->content,
24 $method,
25 "Method $method works",
26 );
27 }
28
29 foreach my $method (@fails) {
30 my $req = HTTP::Request->new( $method => '/test' );
31 ok(
32 ! $test->request($req)->is_success,
33 "Method $method doesn't exist",
34 );
35 }
36 };
37
38 subtest 'any without params' => sub {
39 foreach my $method ( qw<GET POST PUT DELETE OPTIONS PATCH> ) {
40 my $req = HTTP::Request->new( $method => '/all' );
41 is(
42 $test->request($req)->content,
43 $method,
44 "Method $method works",
45 );
46 }
47 };
48