Test that a lazy attr without a default or builder dies
[gitmo/Moose.git] / t / 060_compat / 001_module_refresh_compat.t
index ab139a0..2eb8e09 100644 (file)
@@ -6,30 +6,31 @@ use warnings;
 use lib 't/lib', 'lib';
 
 use Test::More;
-use Test::Exception;
+use Test::Fatal;
 
-BEGIN {
-    eval "use Module::Refresh;";
-    plan skip_all => "Module::Refresh is required for this test" if $@;        
-    plan tests => 23;    
-}
+use File::Spec;
+use File::Temp 'tempdir';
+
+use Test::Requires {
+    'Module::Refresh' => '0.01', # skip all if not installed
+};
 
 =pod
 
 First lets test some of our simple example modules ...
 
-=cut 
+=cut
 
 my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
 
 do {
     use_ok($_);
-    
+
     is($_->meta->name, $_, '... initialized the meta correctly');
-    
-    lives_ok {
+
+    is( exception {
         Module::Refresh->new->refresh_module($_ . '.pm')
-    } '... successfully refreshed ' . $_;    
+    }, undef, '... successfully refreshed ' );
 } foreach @modules;
 
 =pod
@@ -39,7 +40,10 @@ and actually change the module itself.
 
 =cut
 
-my $test_module_file = 'TestBaz.pm';
+my $dir = tempdir( "MooseTest-XXXXX", CLEANUP => 1, TMPDIR => 1 );
+push @INC, $dir;
+
+my $test_module_file = File::Spec->catdir($dir, 'TestBaz.pm');
 
 my $test_module_source_1 = q|
 package TestBaz;
@@ -57,7 +61,7 @@ has 'foo' => (is => 'rw', isa => 'Int');
 |;
 
 {
-    open FILE, ">", $test_module_file 
+    open FILE, ">", $test_module_file
         || die "Could not open $test_module_file because $!";
     print FILE $test_module_source_1;
     close FILE;
@@ -69,15 +73,15 @@ ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
 ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo');
 
 {
-    open FILE, ">", $test_module_file 
+    open FILE, ">", $test_module_file
         || die "Could not open $test_module_file because $!";
     print FILE $test_module_source_2;
     close FILE;
 }
 
-lives_ok {
-    Module::Refresh->new->refresh_module($test_module_file)
-} '... successfully refreshed ' . $test_module_file;
+is( exception {
+    Module::Refresh->new->refresh_module('TestBaz.pm')
+}, undef, '... successfully refreshed ' );
 
 is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
 ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
@@ -85,7 +89,4 @@ ok(TestBaz->isa('Foo'), '... TestBaz is a Foo');
 
 unlink $test_module_file;
 
-
-
-
-
+done_testing;