Skip to content

Commit

Permalink
fix: make sure messages cache directory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwenner committed Oct 20, 2024
1 parent b141851 commit de5eb3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/Comics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use DateTime;
use File::Slurper;
use File::Find;
use File::Util;
use File::Basename;
use File::Path;
use JSON;

use Comic;
Expand Down Expand Up @@ -604,6 +606,8 @@ sub _save_messages {
my ($filename, $messages) = @ARG;

my $json = encode_json($messages);
my ($file, $dirs) = fileparse($filename);
File::Path::make_path($dirs);
File::Slurper::write_text($filename, $json);
return;
}
Expand Down
7 changes: 6 additions & 1 deletion t/comics.t
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ sub has_default_message_file_name : Tests {
}


sub restores_messages_does_nothing_if_nio_messages_for_that_comic_stored : Tests {
sub restores_messages_does_nothing_if_no_messages_for_that_comic_stored : Tests {
MockComic::fake_file('generated/check-messages.json', '{"not-some-comic.svg": ["some problem"]}');
my $comic = MockComic::make_comic();
my $generator = DummyGenerator->new();
Expand Down Expand Up @@ -162,6 +162,10 @@ sub persists_messages_to_file : Tests {
my ($self, $comic) = @_;
return $comic->{srcFile} eq 'old_comic.svg';
};
my @mkdirs;
local *File::Path::make_path = sub {
push @mkdirs, @_;
};
local *Comic::check = sub {
my ($self) = @_;
$self->warning('new problem');
Expand All @@ -173,6 +177,7 @@ sub persists_messages_to_file : Tests {
push @{$comics->{comics}}, $old_comic, $new_comic;
$comics->run_all_checks();

is_deeply(\@mkdirs, ['generated/'], 'should have created directory');
MockComic::assert_wrote_file_json('generated/check-messages.json', {
"old_comic.svg" => ["old problem"],
"new_comic.svg" => ['new problem'],
Expand Down

0 comments on commit de5eb3f

Please sign in to comment.