From: gfx Date: Mon, 21 Sep 2009 03:36:01 +0000 (+0900) Subject: Fix tests for accessors X-Git-Tag: 0.32~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a2096df637b33d3794ee12835a24ea8fd2acb978;p=gitmo%2FMouse.git Fix tests for accessors --- diff --git a/t/007-attributes.t b/t/007-attributes.t index fdb3ed3..4edd2d0 100644 --- a/t/007-attributes.t +++ b/t/007-attributes.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 10; +use Test::More tests => 15; use Test::Exception; do { @@ -19,6 +19,12 @@ do { has 'z' => ( is => 'rw', ); + + has 'attr' => ( + accessor => 'rw_attr', + reader => 'read_attr', + writer => 'write_attr', + ); }; ok(!Class->can('x'), "No accessor is injected if 'is' has no value"); @@ -41,3 +47,11 @@ is($object->z, undef); is($object->z(10), 10); is($object->z, 10); +can_ok($object, qw(rw_attr read_attr write_attr)); +$object->write_attr(42); +is $object->rw_attr, 42; +is $object->read_attr, 42; +$object->rw_attr(100); +is $object->rw_attr, 100; +is $object->read_attr, 100; + diff --git a/t/033-readwrite.t b/t/033-readwrite.t deleted file mode 100644 index 6a15fe9..0000000 --- a/t/033-readwrite.t +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 4; -use Test::Exception; - -do { - package Class; - use Mouse; - - # We want this attr to have a reader and writer with unconventional names, - # and not the default rw_attr method. -- rjbs, 2008-12-04 - has 'rw_attr' => ( - is => 'rw', - reader => 'read_attr', - writer => 'write_attr', - ); -}; - -my $object = Class->new; - -TODO: { - local $TODO = 'requires some refactoring to implement'; - - ok( - !$object->can('rw_attr'), - "no rw_attr method because wasn't 'is' ro or rw" - ); - ok($object->can('read_attr'), "did get a reader"); - ok($object->can('write_attr'), "did get a writer"); - - # eliminate these eval{} when out of TODO - eval { $object->write_attr(2); }; - - is( - eval { $object->read_attr }, - 2, - "writing to the object worked", - ); -}