1. Diab Jerius
  2. Hg::Lib

Commits

Diab Jerius  committed 5b4c066

the TempDir role now creates a new directory for each test

  • Participants
  • Parent commits 79b3232
  • Branches default

Comments (0)

Files changed (1)

File t/lib/Test/Hg/Lib/Role/TempDir.pm

View file
 package Test::Hg::Lib::Role::TempDir;
 
 use Moo::Role;
-use Cwd qw/getcwd/;
-use File::pushd 'tempd';
+
+use File::pushd ();
 
 has tempdir => (
-    is      => 'ro',
-    default => sub { tempd() },
-    clearer => 1,
+    is       => 'lazy',
+    init_arg => undef,
+    clearer  => 1,
 );
 
+# create new tempdir before each test
+
+sub _build_tempdir {
+
+    File::pushd::tempd();
+
+}
+
+before each_test => sub {
+
+    shift->tempdir;
+
+};
+
+after each_test => sub {
+
+    shift->clear_tempdir;
+
+};
+
 1;