X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F046-rebless.t;h=5ee4b7ce1f0f46c295d118ed69eac88dae9802df;hb=361c5bc4c9e1dc0f1d8e64bb649396b124b4c55d;hp=a461ed69615234ba40f4e44753f6371656a03392;hpb=3d9e46468e384bb12661e1b9df7a22ab8f8ee839;p=gitmo%2FClass-MOP.git diff --git a/t/046-rebless.t b/t/046-rebless.t index a461ed6..5ee4b7c 100644 --- a/t/046-rebless.t +++ b/t/046-rebless.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 36; +use Test::More tests => 27; use Test::Exception; use Scalar::Util 'blessed'; @@ -37,26 +37,17 @@ is($foo->whoami, "parent", 'Parent->whoami gives parent'); is($foo->parent, "parent", 'Parent->parent gives parent'); dies_ok { $foo->child } "Parent->child method doesn't exist"; -$foo->meta->rebless_instance($foo, "Child"); +Child->meta->rebless_instance($foo); is(blessed($foo), 'Child', 'rebless_instance really reblessed the instance'); is($foo->whoami, "child", 'reblessed->whoami gives child'); is($foo->parent, "parent", 'reblessed->parent gives parent'); is($foo->child, "child", 'reblessed->child gives child'); -$foo->meta->rebless_instance($foo, "LeftField"); -is(blessed($foo), 'LeftField', "rebless_instance doesn't have to work on subclasses"); -is($foo->whoami, "leftfield", "reblessed->whoami gives leftfield"); -is($foo->myhax, "areleet", "new method works fine"); -dies_ok { $foo->parent } "LeftField->parent method doesn't exist"; -dies_ok { $foo->child } "LeftField->child method doesn't exist"; - -$foo->meta->rebless_instance($foo, "NonExistent"); -is(blessed($foo), 'NonExistent', "rebless_instance doesn't require an already-existing package"); -ok($foo->isa('NonExistent'), "still have a blessed reference"); -dies_ok { $foo->whoami } "NonExistent->whoami method doesn't exist"; -dies_ok { $foo->myhax } "NonExistent->myhax method doesn't exist"; -dies_ok { $foo->parent } "NonExistent->parent method doesn't exist"; -dies_ok { $foo->child } "NonExistent->child method doesn't exist"; +throws_ok { LeftField->meta->rebless_instance($foo, "LeftField") } + qr/You may rebless only into a subclass of \(Child\), of which \(LeftField\) isn't\./; + +throws_ok { Class::MOP::Class->initialize("NonExistent")->rebless_instance($foo) } + qr/You may rebless only into a subclass of \(Child\), of which \(NonExistent\) isn't\./; # make sure our ->meta is still sane my $bar = Parent->new; @@ -70,7 +61,7 @@ ok($bar->meta->has_method('parent'), 'metaclass has "parent" method'); is(blessed($bar->meta->new_object), 'Parent', 'new_object gives a Parent'); -$bar->meta->rebless_instance($bar, "Child"); +Child->meta->rebless_instance($bar); is(blessed($bar), 'Child', "rebless really reblessed"); is(blessed($bar->meta), 'Class::MOP::Class', "meta gives a Class::MOP::Class"); is($bar->meta->name, 'Child', "this Class::MOP::Class instance is for Child");