Revert "Hash accessor should accept more than 2 arguments"
[gitmo/Moose.git] / t / 040_type_constraints / 009_union_types_and_coercions.t
index 4066ff8..1bf35f2 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use Test::More;
-use Test::Exception;
+use Test::Fatal;
 
 use Test::Requires {
     'IO::String' => '0.01', # skip all if not installed
@@ -79,9 +79,9 @@ use Test::Requires {
 
     is($email->as_string, '... this is my body ...', '... got correct string');
 
-    lives_ok {
+    is( exception {
         $email->raw_body('... this is the next body ...');
-    } '... this will coerce correctly';
+    }, undef, '... this will coerce correctly' );
 
     isa_ok($email->raw_body, 'IO::String');
 
@@ -100,9 +100,9 @@ use Test::Requires {
 
     my $str2 = '... this is the next body (ref) ...';
 
-    lives_ok {
+    is( exception {
         $email->raw_body(\$str2);
-    } '... this will coerce correctly';
+    }, undef, '... this will coerce correctly' );
 
     isa_ok($email->raw_body, 'IO::String');
 
@@ -122,9 +122,9 @@ use Test::Requires {
 
     my $io_str2 = IO::String->new('... this is the next body (IO::String) ...');
 
-    lives_ok {
+    is( exception {
         $email->raw_body($io_str2);
-    } '... this will coerce correctly';
+    }, undef, '... this will coerce correctly' );
 
     isa_ok($email->raw_body, 'IO::String');
     is($email->raw_body, $io_str2, '... and it is the one we expected');
@@ -161,17 +161,6 @@ use Test::Requires {
     use Moose;
     use Moose::Util::TypeConstraints;
 
-    has nothing => (
-        is  => 'ro',
-        isa => 'Undef | Undef',
-    );
-
-    has nothing2 => (
-        is     => 'ro',
-        isa    => 'Undef | Undef',
-        coerce => 1,
-    );
-
     subtype 'Coerced' => as 'ArrayRef';
     coerce 'Coerced'
         => from 'Value'
@@ -185,26 +174,14 @@ use Test::Requires {
 }
 
 {
-    throws_ok { Foo->new( nothing => 1 ) }
-    qr/\QValidation failed for 'Undef|Undef' with value 1/,
-        'Cannot pass defined value for nothing attribute';
-
-    throws_ok { Foo->new( nothing2 => 1 ) }
-    qr/\QValidation failed for 'Undef|Undef' with value 1/,
-        'Cannot pass defined value for nothing2 attribute';
-
-    {
-        my $foo;
-        lives_ok { $foo = Foo->new( carray => 1 ) }
-            'Can pass non-ref value for carray';
-        is_deeply(
-            $foo->carray, [1],
-            'carray was coerced to an array ref'
-        );
-    }
+    my $foo;
+    is( exception { $foo = Foo->new( carray => 1 ) }, undef, 'Can pass non-ref value for carray' );
+    is_deeply(
+        $foo->carray, [1],
+        'carray was coerced to an array ref'
+    );
 
-    throws_ok { Foo->new( carray => {} ) } qr/\QValidation failed for 'Coerced|Coerced' with value \E(?!undef)/,
-        'Cannot pass a hash ref for carray attribute, and hash ref is not coerced to an undef';
+    like( exception { Foo->new( carray => {} ) }, qr/\QValidation failed for 'Coerced|Coerced' with value \E(?!undef)/, 'Cannot pass a hash ref for carray attribute, and hash ref is not coerced to an undef' );
 }
 
 done_testing;