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/moose-meta-role-composite.t | |
download | Moose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz |
Moose-2.1405HEADMoose-2.1405master
Diffstat (limited to 't/exceptions/moose-meta-role-composite.t')
-rw-r--r-- | t/exceptions/moose-meta-role-composite.t | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/t/exceptions/moose-meta-role-composite.t b/t/exceptions/moose-meta-role-composite.t new file mode 100644 index 0000000..05ae6ae --- /dev/null +++ b/t/exceptions/moose-meta-role-composite.t @@ -0,0 +1,84 @@ +use strict; +use warnings; + +use Test::More; +use Test::Fatal; + +use Moose(); + +{ + my $exception = exception { + my $rolesComp = Moose::Meta::Role::Composite->new(roles => ["foo"]); + }; + + like( + $exception, + qr/\QThe list of roles must be instances of Moose::Meta::Role, not foo/, + "'foo' is not an instance of Moose::Meta::Role"); + + isa_ok( + $exception, + "Moose::Exception::RolesListMustBeInstancesOfMooseMetaRole", + "'foo' is not an instance of Moose::Meta::Role"); + + is( + $exception->role, + "foo", + "'foo' is not an instance of Moose::Meta::Role"); +} + +{ + { + package Foo; + use Moose::Role; + } + + my $rolesComp = Moose::Meta::Role::Composite->new(roles => [Foo->meta]); + my $exception = exception { + $rolesComp->add_method; + }; + + like( + $exception, + qr/You must define a method name/, + "no method name given to add_method"); + + isa_ok( + $exception, + "Moose::Exception::MustDefineAMethodName", + "no method name given to add_method"); + + is( + $exception->instance, + $rolesComp, + "no method name given to add_method"); +} + +{ + { + package Foo; + use Moose::Role; + } + + my $rolesComp = Moose::Meta::Role::Composite->new(roles => [Foo->meta]); + my $exception = exception { + $rolesComp->reinitialize; + }; + + like( + $exception, + qr/Moose::Meta::Role::Composite instances can only be reinitialized from an existing metaclass instance/, + "no metaclass instance is given"); + + isa_ok( + $exception, + "Moose::Exception::CannotInitializeMooseMetaRoleComposite", + "no metaclass instance is given"); + + is( + $exception->role_composite, + $rolesComp, + "no metaclass instance is given"); +} + +done_testing; |