Debian Codegraph @

t/issues/gh-650/gh-650.t

raw
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Plack::Test;
8 use HTTP::Request::Common;
9 use Ref::Util qw<is_coderef>;
10
11 BEGIN{
12 # undefine ENV vars used as defaults for app environment in these tests
13 delete $ENV{DANCER_ENVIRONMENT};
14 delete $ENV{PLACK_ENV};
15 }
16
17 {
18 package MyApp;
19
20 use Dancer2;
21
22 set template => 'template_toolkit';
23
24 get '/foo' => sub {
25 template 'environment_setting'
26 };
27 get '/bar' => sub {
28 set environment => 'development';
29 template 'environment_setting'
30 };
31 }
32
33 my $app = Dancer2->psgi_app;
34 ok( is_coderef($app), 'Got app' );
35
36 test_psgi $app, sub {
37 my $cb = shift;
38 my $res;
39
40 $res = $cb->(GET '/foo');
41 is $res->code, 200, 'Successful request';
42 like $res->content, qr/development/, 'Correct content';
43
44 $res = $cb->(GET '/bar');
45 is $res->code, 200, 'Successful request';
46 like $res->content, qr/development/, 'Correct content';
47 };
48
49 done_testing();