diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
commit | 5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch) | |
tree | 298c3d2f08bdfe5689998b11892d72a897985be1 /t/exceptions/exception-lazyattributeneedsadefault.t | |
download | Moose-tarball-master.tar.gz |
Moose-2.1405HEADMoose-2.1405master
Diffstat (limited to 't/exceptions/exception-lazyattributeneedsadefault.t')
-rw-r--r-- | t/exceptions/exception-lazyattributeneedsadefault.t | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/t/exceptions/exception-lazyattributeneedsadefault.t b/t/exceptions/exception-lazyattributeneedsadefault.t new file mode 100644 index 0000000..c0eb4a2 --- /dev/null +++ b/t/exceptions/exception-lazyattributeneedsadefault.t @@ -0,0 +1,66 @@ +use strict; +use warnings; + +use Test::More; +use Test::Fatal; + +use Moose::Util 'throw_exception'; + +{ + package Foo; + use Moose; + + has 'foo' => ( + is => 'ro' + ); + + has 'bar' => ( + is => 'ro' + ); +} + +{ + my $exception = exception { + throw_exception( LazyAttributeNeedsADefault => attribute_name => "foo", + attribute => Foo->meta->get_attribute("bar") + ); + }; + + like( + $exception, + qr/\Qattribute_name (foo) does not match attribute->name (bar)/, + "you have given attribute_name as 'foo' and attribute->name as 'bar'"); + + isa_ok( + $exception, + "Moose::Exception::AttributeNamesDoNotMatch", + "you have given attribute_name as 'foo' and attribute->name as 'bar'"); + + is( + $exception->attribute_name, + "foo", + "you have given attribute_name as 'foo' and attribute->name as 'bar'"); + + is( + $exception->attribute->name, + "bar", + "you have given attribute_name as 'foo' and attribute->name as 'bar'"); +} + +{ + my $exception = exception { + throw_exception("LazyAttributeNeedsADefault"); + }; + + like( + $exception, + qr/\QYou need to give attribute or attribute_name or both/, + "please give either attribute or attribute_name"); + + isa_ok( + $exception, + "Moose::Exception::NeitherAttributeNorAttributeNameIsGiven", + "please give either attribute or attribute_name"); +} + +done_testing; |