diff options
Diffstat (limited to 't/exceptions/moose-meta-method-accessor.t')
-rw-r--r-- | t/exceptions/moose-meta-method-accessor.t | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/t/exceptions/moose-meta-method-accessor.t b/t/exceptions/moose-meta-method-accessor.t new file mode 100644 index 0000000..f42f4d2 --- /dev/null +++ b/t/exceptions/moose-meta-method-accessor.t @@ -0,0 +1,55 @@ +use strict; +use warnings; + +use Test::More; +use Test::Fatal; + +use Moose(); + +{ + { + package Foo; + use Moose; + extends 'Moose::Meta::Method::Accessor'; + } + + my $attr = Class::MOP::Attribute->new("bar"); + Foo->meta->add_attribute($attr); + + my $foo; + my $exception = exception { + $foo = Foo->new( name => "new", + package_name => "Foo", + is_inline => 1, + attribute => $attr, + accessor_type => "writer" + ); + }; + + like( + $exception, + qr/\QCould not generate inline writer because : Could not create writer for 'bar' because Can't locate object method "_eval_environment" via package "Class::MOP::Attribute"/, + "cannot generate writer"); + + isa_ok( + $exception->error, + "Moose::Exception::CouldNotCreateWriter", + "cannot generate writer"); + + isa_ok( + $exception, + "Moose::Exception::CouldNotGenerateInlineAttributeMethod", + "cannot generate writer"); + + is( + $exception->error->attribute_name, + 'bar', + "cannot generate writer"); + + is( + ref($exception->error->instance), + "Foo", + "cannot generate writer"); +} + +done_testing; |