Skip to content

Commit

Permalink
more tests for Mojo::Asset::File
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 20, 2013
1 parent 30ddb4b commit 43fa418
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion t/mojo/asset.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use Test::More;
use File::Basename 'dirname';
use File::Spec::Functions 'catdir';
use File::Spec::Functions qw(catdir catfile);
use File::Temp 'tempdir';
use Mojo::Asset::File;
use Mojo::Asset::Memory;
Expand Down Expand Up @@ -145,6 +145,7 @@ $file = Mojo::Asset::File->new;
$file->add_chunk('bcd');
$tmp = Mojo::Asset::File->new;
$tmp->add_chunk('x');
isnt $file->path, $tmp->path, 'different paths';
$path = $tmp->path;
ok -e $path, 'file exists';
undef $tmp;
Expand Down Expand Up @@ -182,6 +183,21 @@ ok !$asset->is_file, 'stored in memory';
is dirname($file->path), $tmpdir, 'same directory';
}

# Custom temporary file
{
my $tmpdir = tempdir CLEANUP => 1;
my $path = catfile $tmpdir, 'test.file';
ok !-e $path, 'file does not exist';
$file = Mojo::Asset::File->new(path => $path);
is $file->path, $path, 'right path';
ok !-e $path, 'file still does not exist';
$file->add_chunk('works!');
ok -e $path, 'file exists';
is $file->slurp, 'works!', 'right content';
undef $file;
ok !-e $path, 'file has been cleaned up';
}

# Temporary file without cleanup
$file = Mojo::Asset::File->new(cleanup => 0)->add_chunk('test');
ok $file->is_file, 'stored in file';
Expand Down

0 comments on commit 43fa418

Please sign in to comment.