X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F030_roles%2F017_extending_role_attrs.t;h=720dd0f8e6406e99dc9ab00caa04b43dd44f2f6b;hb=refs%2Fheads%2Fabandoned%2Fdeath_to_all_ellipses;hp=9b46f59e6bb4667d4a911d692450beb5b3e2eb3e;hpb=08380fdb9f79107ab7aaf353edd03757ad3e8400;p=gitmo%2FMoose.git diff --git a/t/030_roles/017_extending_role_attrs.t b/t/030_roles/017_extending_role_attrs.t index 9b46f59..720dd0f 100644 --- a/t/030_roles/017_extending_role_attrs.t +++ b/t/030_roles/017_extending_role_attrs.t @@ -10,7 +10,7 @@ use Test::Exception; =pod -This basically just makes sure that using +name +This basically just makes sure that using +name on role attributes works right. =cut @@ -18,27 +18,27 @@ on role attributes works right. { package Foo::Role; use Moose::Role; - + has 'bar' => ( is => 'rw', - isa => 'Int', + isa => 'Int', default => sub { 10 }, ); - + package Foo; use Moose; - + with 'Foo::Role'; - + ::lives_ok { has '+bar' => (default => sub { 100 }); - } '... extended the attribute successfully'; + } 'extended the attribute successfully'; } my $foo = Foo->new; isa_ok($foo, 'Foo'); -is($foo->bar, 100, '... got the extended attribute'); +is($foo->bar, 100, 'got the extended attribute'); { @@ -64,7 +64,7 @@ is($foo->bar, 100, '... got the extended attribute'); my $bar = Bar->new(foo => 42); isa_ok($bar, 'Bar'); -is($bar->foo, 42, '... got the extended attribute'); +is($bar->foo, 42, 'got the extended attribute'); $bar->foo(100); is($bar->foo, 100, "... can change the attribute's value to an Int"); @@ -95,11 +95,11 @@ is($bar->foo, 100, "... still has the old Int value"); my $baz = Baz->new(baz => 99); isa_ok($baz, 'Baz'); -is($baz->baz, 99, '... got the extended attribute'); +is($baz->baz, 99, 'got the extended attribute'); $baz->baz('Foo'); is($baz->baz, 'Foo', "... can change the attribute's value to a ClassName"); -throws_ok { $baz->baz("zonk") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName \| Int' failed with value zonk at /; +throws_ok { $baz->baz("zonk") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' failed with value zonk at /; is_deeply($baz->baz, 'Foo', "... still has the old ClassName value"); @@ -131,16 +131,16 @@ is_deeply($baz->baz, 'Foo', "... still has the old ClassName value"); my $quux = Quux->new(quux => 99); isa_ok($quux, 'Quux'); -is($quux->quux, 99, '... got the extended attribute'); +is($quux->quux, 99, 'got the extended attribute'); $quux->quux(100); is($quux->quux, 100, "... can change the attribute's value to an Int"); $quux->quux(["hi"]); is_deeply($quux->quux, ["hi"], "... can change the attribute's value to an ArrayRef"); -throws_ok { $quux->quux("quux") } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef \| Positive' failed with value quux at /; +throws_ok { $quux->quux("quux") } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' failed with value quux at /; is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); -throws_ok { $quux->quux({a => 1}) } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef \| Positive' failed with value HASH\(\w+\) at /; +throws_ok { $quux->quux({a => 1}) } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' failed with value HASH\(\w+\) at /; is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); @@ -151,6 +151,7 @@ is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); for (1..3) { has "err$_" => ( isa => 'Str | Int', + is => 'bare', ); }