From: Stevan Little Date: Tue, 22 May 2007 04:09:54 +0000 (+0000) Subject: more tests and tweaks X-Git-Tag: 0.18_01~81 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c25a396fc4e4fbaa12eea8a77233632c3ef5eaa6;p=gitmo%2FMooseX-AttributeHelpers.git more tests and tweaks --- diff --git a/lib/MooseX/AttributeHelpers/Collection.pm b/lib/MooseX/AttributeHelpers/Collection.pm index f27a1ad..e009bde 100644 --- a/lib/MooseX/AttributeHelpers/Collection.pm +++ b/lib/MooseX/AttributeHelpers/Collection.pm @@ -26,8 +26,12 @@ has 'container_type_constraint' => ( my $container_type = $self->container_type; my $constraint = find_type_constraint($container_type); - $constraint = subtype('Object', where { $_->isa($container_type) }) - unless $constraint; + $constraint = subtype( + 'Object', + sub { + $_->isa($container_type) || ($_->can('does') && $_->does($container_type)) + } + ) unless $constraint; return $constraint; } @@ -48,6 +52,7 @@ before 'process_options_for_provides' => sub { }; no Moose; +no Moose::Util::TypeConstraints; 1; diff --git a/t/002_basic_collection.t b/t/002_basic_array.t similarity index 97% rename from t/002_basic_collection.t rename to t/002_basic_array.t index 4b3eddd..0679576 100644 --- a/t/002_basic_collection.t +++ b/t/002_basic_array.t @@ -104,4 +104,4 @@ is_deeply($options->provides, { 'empty' => 'has_options', }, '... got the right provies mapping'); - +is($options->container_type, 'Int', '... got the right container type'); diff --git a/t/003_basic_hash.t b/t/003_basic_hash.t index 7f784df..3748a3f 100644 --- a/t/003_basic_hash.t +++ b/t/003_basic_hash.t @@ -16,11 +16,13 @@ BEGIN { has 'options' => ( metaclass => 'Collection::Hash', is => 'ro', - isa => 'HashRef', + isa => 'HashRef[Str]', default => sub { {} }, provides => { - 'set' => 'set_option', - 'get' => 'get_option', + 'set' => 'set_option', + 'get' => 'get_option', + 'empty' => 'has_options', + 'count' => 'num_options', } ); } @@ -28,12 +30,27 @@ BEGIN { my $stuff = Stuff->new(); isa_ok($stuff, 'Stuff'); +can_ok($stuff, $_) for qw[ + set_option + get_option + has_options + num_options +]; + +ok(!$stuff->has_options, '... we have no options'); +is($stuff->num_options, 0, '... we have no options'); + is_deeply($stuff->options, {}, '... no options yet'); $stuff->set_option(foo => 'bar'); + +ok($stuff->has_options, '... we have options'); +is($stuff->num_options, 1, '... we have 1 option(s)'); is_deeply($stuff->options, { foo => 'bar' }, '... got options now'); $stuff->set_option(bar => 'baz'); + +is($stuff->num_options, 2, '... we have 2 option(s)'); is_deeply($stuff->options, { foo => 'bar', bar => 'baz' }, '... got more options now'); is($stuff->get_option('foo'), 'bar', '... got the right option'); diff --git a/t/004_basic_number.t b/t/004_basic_number.t index 219e21e..519b9f6 100644 --- a/t/004_basic_number.t +++ b/t/004_basic_number.t @@ -31,6 +31,11 @@ BEGIN { } my $real = Real->new; +isa_ok($real, 'Real'); + +can_ok($real, $_) for qw[ + set add sub mul div mod abs +]; is $real->integer, 5, 'Default to five'; diff --git a/t/100_collection_with_roles.t b/t/100_collection_with_roles.t index 88e60c5..a2c8a31 100644 --- a/t/100_collection_with_roles.t +++ b/t/100_collection_with_roles.t @@ -17,7 +17,7 @@ use MooseX::AttributeHelpers; has observers => ( metaclass => 'Collection::Array', is => 'ro', - isa => 'ArrayRef', + isa => 'ArrayRef[Observer]', auto_deref => 1, default => sub { [] }, provides => { 'push' => 'add_observer', count => 'count_observers' } @@ -36,9 +36,7 @@ package Observer; use Moose::Role; -sub update { - die 'Forgot to implement' . "\n"; -} +requires 'update'; ###############################################################################