Redid conversion to Test::Fatal
[gitmo/Moose.git] / t / 030_roles / 001_meta_role.t
index a977ec3..b31ca63 100644 (file)
@@ -3,10 +3,11 @@
 use strict;
 use warnings;
 
-use Test::More tests => 27;
-use Test::Exception;
+use Test::More;
+use Test::Fatal;
 
 use Moose::Meta::Role;
+use Moose::Util::TypeConstraints ();
 
 {
     package FooRole;
@@ -44,9 +45,9 @@ is_deeply(
 
 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
 
-lives_ok {
+is( exception {
     $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
-} '... added the bar attribute okay';
+}, undef, '... added the bar attribute okay' );
 
 is_deeply(
     [ $foo_role->get_attribute_list() ],
@@ -55,14 +56,19 @@ is_deeply(
 
 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
 
-is_deeply(
-    $foo_role->get_attribute('bar'),
-    { is => 'rw', isa => 'Foo' },
-    '... got the correct description of the bar attribute');
-
-lives_ok {
+my $bar = $foo_role->get_attribute('bar');
+is_deeply( $bar->original_options, { is => 'rw', isa => 'Foo' },
+    'original options for bar attribute' );
+my $bar_for_class = $bar->attribute_for_class('Moose::Meta::Attribute');
+is(
+    $bar_for_class->type_constraint,
+    Moose::Util::TypeConstraints::class_type('Foo'),
+    'bar has a Foo class type'
+);
+
+is( exception {
     $foo_role->add_attribute('baz' => (is => 'ro'));
-} '... added the baz attribute okay';
+}, undef, '... added the baz attribute okay' );
 
 is_deeply(
     [ sort $foo_role->get_attribute_list() ],
@@ -71,14 +77,13 @@ is_deeply(
 
 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
 
-is_deeply(
-    $foo_role->get_attribute('baz'),
-    { is => 'ro' },
-    '... got the correct description of the baz attribute');
+my $baz = $foo_role->get_attribute('baz');
+is_deeply( $baz->original_options, { is => 'ro' },
+    'original options for baz attribute' );
 
-lives_ok {
+is( exception {
     $foo_role->remove_attribute('bar');
-} '... removed the bar attribute okay';
+}, undef, '... removed the bar attribute okay' );
 
 is_deeply(
     [ $foo_role->get_attribute_list() ],
@@ -93,9 +98,9 @@ ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribu
 ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier');
 
 my $method = sub { "FooRole::boo:before" };
-lives_ok {
+is( exception {
     $foo_role->add_before_method_modifier('boo' => $method);
-} '... added a method modifier okay';
+}, undef, '... added a method modifier okay' );
 
 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
 is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back');
@@ -104,3 +109,5 @@ is_deeply(
     [ $foo_role->get_method_modifier_list('before') ],
     [ 'boo' ],
     '... got the right list of before method modifiers');
+
+done_testing;