X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fhas-array.t;h=173ca6b30c5c749505c3635408c3a127226ba6a9;hb=master;hp=3d2d91fa208ea5d3172ba2042fedd3a682af85e6;hpb=1d17c7c12c2283c4daae3a9439a0aa629e743d73;p=gitmo%2FMoo.git diff --git a/t/has-array.t b/t/has-array.t index 3d2d91f..173ca6b 100644 --- a/t/has-array.t +++ b/t/has-array.t @@ -1,21 +1,19 @@ -use Test::More tests => 4; +use strictures; +use Test::More; +use Test::Fatal; -ok(eval { +is(exception { package Local::Test::Role1; use Moo::Role; has [qw/ attr1 attr2 /] => (is => 'ro'); - 1; -}, 'has \@attrs works in roles') - or diag "EVAL FAILED: $@"; +}, undef, 'has \@attrs works in roles'); -ok eval { +is(exception { package Local::Test::Class1; use Moo; with 'Local::Test::Role1'; has [qw/ attr3 attr4 /] => (is => 'ro'); - 1; -}, 'has \@attrs works in classes' - or diag "EVAL FAILED: $@"; +}, undef, 'has \@attrs works in classes'); my $obj = new_ok 'Local::Test::Class1' => [ attr1 => 1, @@ -28,3 +26,19 @@ can_ok( $obj, qw( attr1 attr2 attr3 attr4 ), ); + +like(exception { + package Local::Test::Role2; + use Moo::Role; + has [qw/ attr1 attr2 /] => (is => 'ro', 'isa'); +}, qr/^Invalid options for 'attr1', 'attr2' attribute\(s\): even number of arguments expected, got 3/, + 'correct exception when has given bad parameters in role'); + +like(exception { + package Local::Test::Class2; + use Moo; + has [qw/ attr3 attr4 /] => (is => 'ro', 'isa'); +}, qr/^Invalid options for 'attr3', 'attr4' attribute\(s\): even number of arguments expected, got 3/, + 'correct exception when has given bad parameters in class'); + +done_testing;