#!/perl ## no critic (Modules::ProhibitMultiplePackages) use strict; use warnings; use 5.014; # JSON::PP included in CORE. package ConfigChangeTest; use Dancer2; set serializer => 'JSON'; get qr{/info}msx => sub { return { appname => config->{'appname'}, }; }; package main; use Test2::V0 -srand => time, qw(:DEFAULT); use Plack::Test; use HTTP::Request; use JSON; use Dancer2; my $appname = 'ConfigChangeTest'; set appname => $appname; my $test = Plack::Test->create( ConfigChangeTest->to_app ); my $req = HTTP::Request->new( GET => '/api/1/info' ); my $res = $test->request( $req ); ok( $res->is_success, 'Is success' ); # Fails! # appname is the one set in the file `environments/development.yml` or file `config.yml`. is( decode_json $res->content, { appname => $appname, }, 'Is right content' ); done_testing;