convert all uses of Test::Exception to Test::Fatal.
[gitmo/Moose.git] / t / 020_attributes / 010_attribute_delegation.t
index 16ec30e..c2f50b9 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use Test::More;
-use Test::Exception;
+use Test::Fatal;
 
 
 # -------------------------------------------------------------------
@@ -77,9 +77,9 @@ isa_ok($foo, 'Foo');
 
 is($foo->bar, 25, '... got the right foo->bar');
 
-lives_ok {
+ok ! exception {
     $bar->foo($foo);
-} '... assigned the new Foo to Bar->foo';
+}, '... assigned the new Foo to Bar->foo';
 
 is($bar->foo, $foo, '... assigned bar->foo with the new Foo');
 
@@ -243,6 +243,15 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop');
         handles => 'Foo::Bar',
     );
 
+    package Foo::OtherThing;
+    use Moose;
+    use Moose::Util::TypeConstraints;
+
+    has 'other_thing' => (
+        is      => 'rw',
+        isa     => 'Foo::Baz',
+        handles => Moose::Util::TypeConstraints::find_type_constraint('Foo::Bar'),
+    );
 }
 
 {
@@ -259,6 +268,19 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop');
     is($foo->thing->baz, 'Foo::Baz::BAZ', '... got the right value');
 }
 
+{
+    my $foo = Foo::OtherThing->new(other_thing => Foo::Baz->new);
+    isa_ok($foo, 'Foo::OtherThing');
+    isa_ok($foo->other_thing, 'Foo::Baz');
+
+    ok($foo->meta->has_method('foo'), '... we have the method we expect');
+    ok($foo->meta->has_method('bar'), '... we have the method we expect');
+    ok(!$foo->meta->has_method('baz'), '... we dont have the method we expect');
+
+    is($foo->foo, 'Foo::Baz::FOO', '... got the right value');
+    is($foo->bar, 'Foo::Baz::BAR', '... got the right value');
+    is($foo->other_thing->baz, 'Foo::Baz::BAZ', '... got the right value');
+}
 # -------------------------------------------------------------------
 # AUTOLOAD & handles
 # -------------------------------------------------------------------
@@ -301,13 +323,13 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop');
     package Goorch::Autoloaded;
     use Moose;
 
-    ::dies_ok {
+    ::ok ::exception {
         has 'foo' => (
             is      => 'rw',
             default => sub { Foo::Autoloaded->new },
             handles => qr/bar/
         );
-    } '... you cannot delegate to AUTOLOADED class with regexp';
+    }, '... you cannot delegate to AUTOLOADED class with regexp';
 }
 
 # check HASH based delegation w/ AUTOLOAD
@@ -346,9 +368,9 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop');
 
     is($foo->bar, 25, '... got the right foo->bar');
 
-    lives_ok {
+    ok ! exception {
         $bar->foo($foo);
-    } '... assigned the new Foo to Bar->foo';
+    }, '... assigned the new Foo to Bar->foo';
 
     is($bar->foo, $foo, '... assigned bar->foo with the new Foo');
 
@@ -392,9 +414,9 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop');
 
     is($foo->bar, 25, '... got the right foo->bar');
 
-    lives_ok {
+    ok ! exception {
         $baz->foo($foo);
-    } '... assigned the new Foo to Baz->foo';
+    }, '... assigned the new Foo to Baz->foo';
 
     is($baz->foo, $foo, '... assigned baz->foo with the new Foo');
 
@@ -423,15 +445,15 @@ is($car->stop, 'Engine::stop', '... got the right value from ->stop');
 # not an object
 {
     my $i = Bar->new(foo => undef);
-    throws_ok { $i->foo_bar } qr/is not defined/,
+    like exception { $i->foo_bar }, qr/is not defined/,
         'useful error from unblessed reference';
 
     my $j = Bar->new(foo => []);
-    throws_ok { $j->foo_bar } qr/is not an object \(got 'ARRAY/,
+    like exception { $j->foo_bar }, qr/is not an object \(got 'ARRAY/,
         'useful error from unblessed reference';
 
     my $k = Bar->new(foo => "Foo");
-    lives_ok { $k->foo_baz } "but not for class name";
+    ok ! exception { $k->foo_baz }, "but not for class name";
 }
 
 done_testing;