Skip to content

Commit

Permalink
protect several tests from the local environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Apr 1, 2014
1 parent b152c4d commit b6b59c0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions t/mojo/daemon.t
Expand Up @@ -16,18 +16,20 @@ use Mojolicious;

# Timeout
{
local $ENV{MOJO_INACTIVITY_TIMEOUT};
is(Mojo::Server::Daemon->new->inactivity_timeout, 15, 'right value');
local $ENV{MOJO_INACTIVITY_TIMEOUT} = 25;
$ENV{MOJO_INACTIVITY_TIMEOUT} = 25;
is(Mojo::Server::Daemon->new->inactivity_timeout, 25, 'right value');
$ENV{MOJO_INACTIVITY_TIMEOUT} = 0;
is(Mojo::Server::Daemon->new->inactivity_timeout, 0, 'right value');
}

# Listen
{
local $ENV{MOJO_LISTEN};
is_deeply(Mojo::Server::Daemon->new->listen,
['http://*:3000'], 'right value');
local $ENV{MOJO_LISTEN} = 'http://localhost:8080';
$ENV{MOJO_LISTEN} = 'http://localhost:8080';
is_deeply(Mojo::Server::Daemon->new->listen,
['http://localhost:8080'], 'right value');
$ENV{MOJO_LISTEN} = 'http://*:80,https://*:443';
Expand Down
2 changes: 2 additions & 0 deletions t/mojo/home.t
Expand Up @@ -10,6 +10,8 @@ use List::Util 'first';
use Mojo::HelloWorld;
use Mojo::Home;

local $ENV{MOJO_HOME};

# ENV detection
{
local $ENV{MOJO_HOME} = '.';
Expand Down
9 changes: 6 additions & 3 deletions t/mojo/user_agent.t
Expand Up @@ -58,16 +58,19 @@ any '/method' => {inline => '<%= $self->req->method =%>'};

# Timeouts
{
local $ENV{MOJO_CONNECT_TIMEOUT};
is(Mojo::UserAgent->new->connect_timeout, 10, 'right value');
local $ENV{MOJO_CONNECT_TIMEOUT} = 25;
$ENV{MOJO_CONNECT_TIMEOUT} = 25;
is(Mojo::UserAgent->new->connect_timeout, 25, 'right value');
local $ENV{MOJO_INACTIVITY_TIMEOUT};
is(Mojo::UserAgent->new->inactivity_timeout, 20, 'right value');
local $ENV{MOJO_INACTIVITY_TIMEOUT} = 25;
$ENV{MOJO_INACTIVITY_TIMEOUT} = 25;
is(Mojo::UserAgent->new->inactivity_timeout, 25, 'right value');
$ENV{MOJO_INACTIVITY_TIMEOUT} = 0;
is(Mojo::UserAgent->new->inactivity_timeout, 0, 'right value');
local $ENV{MOJO_REQUEST_TIMEOUT};
is(Mojo::UserAgent->new->request_timeout, 0, 'right value');
local $ENV{MOJO_REQUEST_TIMEOUT} = 25;
$ENV{MOJO_REQUEST_TIMEOUT} = 25;
is(Mojo::UserAgent->new->request_timeout, 25, 'right value');
$ENV{MOJO_REQUEST_TIMEOUT} = 0;
is(Mojo::UserAgent->new->request_timeout, 0, 'right value');
Expand Down
3 changes: 2 additions & 1 deletion t/mojo/util.t
Expand Up @@ -422,11 +422,12 @@ is tablify([['foo', 'bar', 'baz'], ['yada', 'yada', 'yada']]),
my ($warn, $die) = @_;
local $SIG{__WARN__} = sub { $warn = shift };
local $SIG{__DIE__} = sub { $die = shift };
local $ENV{MOJO_FATAL_DEPRECATIONS};
is Mojo::DeprecationTest::foo(), 'bar', 'right result';
like $warn, qr/foo is DEPRECATED at .*util\.t line \d+/, 'right warning';
ok !$die, 'no exception';
($warn, $die) = ();
local $ENV{MOJO_FATAL_DEPRECATIONS} = 1;
$ENV{MOJO_FATAL_DEPRECATIONS} = 1;
ok !eval { Mojo::DeprecationTest::foo() }, 'no result';
ok !$warn, 'no warning';
like $die, qr/foo is DEPRECATED at .*util\.t line \d+/, 'right exception';
Expand Down
3 changes: 2 additions & 1 deletion t/mojolicious/json_config_lite_app.t
Expand Up @@ -60,9 +60,10 @@ is app->config('it'), 'works', 'right value';

# No config file, no default
{
local $ENV{MOJO_CONFIG};
ok !(eval { plugin JSONConfig => {file => 'nonexistent'} }),
'no config file';
local $ENV{MOJO_CONFIG} = 'nonexistent';
$ENV{MOJO_CONFIG} = 'nonexistent';
ok !(eval { plugin 'JSONConfig' }), 'no config file';
}

Expand Down

0 comments on commit b6b59c0

Please sign in to comment.