| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use Test::More tests => 4; |
| 5 |
use Plack::Test; |
| 6 |
use HTTP::Request::Common; |
| 7 |
use Ref::Util qw<is_coderef>; |
| 8 |
|
| 9 |
{ |
| 10 |
package MyApp; |
| 11 |
use Dancer2; |
| 12 |
set serializer => 'JSON'; |
| 13 |
get '/json' => sub { +{ bar => 'baz' } }; |
| 14 |
} |
| 15 |
|
| 16 |
my $app = MyApp->to_app; |
| 17 |
ok( is_coderef($app), 'Got app' ); |
| 18 |
|
| 19 |
test_psgi $app, sub { |
| 20 |
my $cb = shift; |
| 21 |
|
| 22 |
{ |
| 23 |
# Response with implicit call to the serializer |
| 24 |
my $res = $cb->( GET '/json' ); |
| 25 |
is( $res->code, 200, '[/json] Correct status' ); |
| 26 |
is( $res->content, '{"bar":"baz"}', '[/json] Correct content' ); |
| 27 |
is( |
| 28 |
$res->headers->content_type, |
| 29 |
'application/json', |
| 30 |
'[/json] Correct content-type headers', |
| 31 |
); |
| 32 |
} |
| 33 |
}; |