From: Karen Etheridge Date: Fri, 8 Apr 2011 00:53:32 +0000 (-0700) Subject: also test a class whose parent is strict X-Git-Tag: v0.14~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=23cfbce9adb92973d8dc954cb6486be73ed1845e;p=gitmo%2FMooseX-StrictConstructor.git also test a class whose parent is strict --- diff --git a/t/basic.t b/t/basic.t index 6189cda..1738d92 100644 --- a/t/basic.t +++ b/t/basic.t @@ -34,6 +34,16 @@ use Test::More; } { + package StrictSubclass; + + use Moose; + + extends 'Stricter'; + + has 'size' => ( is => 'rw' ); +} + +{ package Tricky; use Moose; @@ -59,7 +69,7 @@ use Test::More; has 'size' => ( is => 'rw', 'init_arg' => undef ); } -my @classes = qw( Standard Stricter Subclass Tricky InitArg ); +my @classes = qw( Standard Stricter Subclass StrictSubclass Tricky InitArg ); with_immutable { is( @@ -85,6 +95,17 @@ with_immutable { ); is( + exception { StrictSubclass->new( thing => 1, size => 'large', ) }, undef, + 'subclass that doesn\'t use strict constructor handles known attributes correctly' + ); + + like( + exception { StrictSubclass->new( thing => 1, bad => 99 ) }, + qr/unknown attribute.+: bad/, + 'subclass that doesn\'t use strict correctly recognizes bad attribute' + ); + + is( exception { Tricky->new( thing => 1, spy => 99 ) }, undef, 'can work around strict constructor by deleting params in BUILD()' ); @@ -96,12 +117,6 @@ with_immutable { ); like( - exception { Subclass->new( thing => 1, bad => 99 ) }, - qr/unknown attribute.+: bad/, - 'subclass constructor blows up on unknown params' - ); - - like( exception { InitArg->new( thing => 1 ) }, qr/unknown attribute.+: thing/, 'InitArg blows up with attribute name'