From: Dave Rolsky Date: Fri, 18 Nov 2011 19:36:07 +0000 (-0600) Subject: Add failing test for initializer with class attr X-Git-Tag: v0.27~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=21035624ef44c6cfba4255e1ccdc7a472c472eef;p=gitmo%2FMooseX-ClassAttribute.git Add failing test for initializer with class attr --- diff --git a/t/12-with-initializer.t b/t/12-with-initializer.t new file mode 100644 index 0000000..61545c8 --- /dev/null +++ b/t/12-with-initializer.t @@ -0,0 +1,80 @@ +use strict; +use warnings; +use Test::More; + +{ + package ClassFoo; + + use Moose; + use MooseX::ClassAttribute; + + class_has 'chas' => ( + isa => 'Int', + is => 'ro', + default => 1, + initializer => sub { $_[2]->( $_[1] + 1 ) } + ); +} + +{ + package ClassBar; + use Moose; + + has 'chas' => ( + isa => 'Int', + is => 'ro', + default => 1, + initializer => sub { $_[2]->( $_[1] + 1 ) } + ); +} + +{ + package ClassBaz; + use Moose; + use MooseX::ClassAttribute; + + class_has 'chas' => ( + isa => 'Str', + is => 'rw', + default => 'Foobar', + trigger => sub { die __PACKAGE__ } + ); +} + +{ + package ClassQuz; + use Moose; + + has 'chas' => ( + isa => 'Str', + is => 'rw', + default => 'Foobar', + trigger => sub { die __PACKAGE__ } + ); +} + +{ + local $TODO + = 'Class attributes with an initializer are not initialized properly'; + + is( + ClassFoo->chas, 2, + "ClassFoo's class_has (ClassAttribute) initializer fires" + ); +} + +is( + ClassBar->new->chas, 2, + "ClassBar's has (non-ClassAttribute) initializer fires" +); + +eval { ClassBaz->new->chas('foobar') }; +like( + $@, qr/ClassBaz/, + "ClassBaz's class_has (ClassAttribute) trigger fires" +); + +eval { ClassQuz->new->chas('foobar') }; +like( $@, qr/ClassQuz/, "ClassQuz's has (non-ClassAttribute) trigger fires" ); + +done_testing();