Dancer2
view release on metacpan or search on metacpan
t/classes/Dancer2-Core-Role-HasEnvironment/with.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Carp 'croak';
use Path::Tiny qw< path >;
use Dancer2::Core::Runner;
# undefine ENV vars used as defaults for app environment in these tests
local $ENV{DANCER_ENVIRONMENT};
local $ENV{PLACK_ENV};
my $runner = Dancer2::Core::Runner->new();
my $location = path( __FILE__ )->parent->child('config')->stringify;
my $location2 = path( __FILE__ )->parent->child('config2')->stringify;
{
package Dancer2::Test::TestRoleOne;
use Moo;
with 'Dancer2::Core::Role::HasEnvironment';
}
{
undef $ENV{DANCER_ENVIRONMENT};
undef $ENV{PLACK_ENV};
my $test_one = Dancer2::Test::TestRoleOne->new();
is( $test_one->environment, 'development', 'Default env is OK' );
}
{
$ENV{DANCER_ENVIRONMENT} = 'staging';
undef $ENV{PLACK_ENV};
my $test_one = Dancer2::Test::TestRoleOne->new();
is( $test_one->environment, q{staging}, 'Dancer env is OK when dancer env has value and plack env is not defined' );
}
{
$ENV{DANCER_ENVIRONMENT} = 'staging';
$ENV{PLACK_ENV} = 'other_env';
my $test_one = Dancer2::Test::TestRoleOne->new();
is( $test_one->environment, q{staging}, 'Dancer env is OK when dancer and plack env vars are both used' );
}
{
undef $ENV{DANCER_ENVIRONMENT};
$ENV{PLACK_ENV} = 'plack_env';
my $test_one = Dancer2::Test::TestRoleOne->new();
is( $test_one->environment, q{plack_env}, 'Dancer env is OK when dancer env var is not defined' );
}
{
$ENV{DANCER_ENVIRONMENT} = '';
$ENV{PLACK_ENV} = 'plack_env';
my $test_one = Dancer2::Test::TestRoleOne->new();
is( $test_one->environment, q{plack_env}, 'Dancer env is OK when one env var is empty string' );
}
{
$ENV{DANCER_ENVIRONMENT} = '';
$ENV{PLACK_ENV} = '';
my $test_one = Dancer2::Test::TestRoleOne->new();
is( $test_one->environment, q{development}, 'Dancer env is OK when both env vars are empty string' );
}
done_testing;
( run in 1.060 second using v1.01-cache-2.11-cpan-54e63673c56 )