X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fbasics%2Frebless.t;h=17808d202fa155dab67e794337fa55971519758c;hb=b57ec19fc43e268a5bffb0776fd431351157f4b3;hp=be8e2423a3e09009d6396460281f137f831f5011;hpb=a386d3e3d7726d8dd474a9ccb112ac1eb8a54eaf;p=gitmo%2FMoose.git diff --git a/t/basics/rebless.t b/t/basics/rebless.t index be8e242..17808d2 100644 --- a/t/basics/rebless.t +++ b/t/basics/rebless.t @@ -5,6 +5,7 @@ use warnings; use Test::More; use Test::Fatal; +use Test::Moose qw(with_immutable); use Scalar::Util 'blessed'; use Moose::Util::TypeConstraints; @@ -52,30 +53,37 @@ subtype 'Positive' ); } -my $foo = Parent->new; -my $bar = Parent->new; +my @classes = qw(Parent Child); -is(blessed($foo), 'Parent', 'Parent->new gives a Parent object'); -is($foo->name, undef, 'No name yet'); -is($foo->lazy_classname, 'Parent', "lazy attribute initialized"); -is( exception { $foo->type_constrained(10.5) }, undef, "Num type constraint for now.." ); +with_immutable +{ + my $foo = Parent->new; + my $bar = Parent->new; + + is(blessed($foo), 'Parent', 'Parent->new gives a Parent object'); + is($foo->name, undef, 'No name yet'); + is($foo->lazy_classname, 'Parent', "lazy attribute initialized"); + is( exception { $foo->type_constrained(10.5) }, undef, "Num type constraint for now.." ); -# try to rebless, except it will fail due to Child's stricter type constraint -like( exception { Child->meta->rebless_instance($foo) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed because of type check' ); -like( exception { Child->meta->rebless_instance($bar) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 5\.5/, '... this failed because of type check' ); + # try to rebless, except it will fail due to Child's stricter type constraint + like( exception { Child->meta->rebless_instance($foo) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed because of type check' ); + like( exception { Child->meta->rebless_instance($bar) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 5\.5/, '... this failed because of type check' ); -$foo->type_constrained(10); -$bar->type_constrained(5); + $foo->type_constrained(10); + $bar->type_constrained(5); -Child->meta->rebless_instance($foo); -Child->meta->rebless_instance($bar); + Child->meta->rebless_instance($foo); + Child->meta->rebless_instance($bar); -is(blessed($foo), 'Child', 'successfully reblessed into Child'); -is($foo->name, 'Junior', "Child->name's default came through"); + is(blessed($foo), 'Child', 'successfully reblessed into Child'); + is($foo->name, 'Junior', "Child->name's default came through"); -is($foo->lazy_classname, 'Parent', "lazy attribute was already initialized"); -is($bar->lazy_classname, 'Child', "lazy attribute just now initialized"); + is($foo->lazy_classname, 'Parent', "lazy attribute was already initialized"); + is($bar->lazy_classname, 'Child', "lazy attribute just now initialized"); -like( exception { $foo->type_constrained(10.5) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed because of type check' ); + like( exception { $foo->type_constrained(10.5) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed because of type check' ); + +} +@classes; done_testing;