From: Dave Rolsky Date: Mon, 22 Jun 2009 19:09:03 +0000 (-0500) Subject: Add a test that Person->full_name actually uses the predicate method X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3647da1b401cff56c5c83bfd6271f3f1bb72e70a;p=gitmo%2Fmoose-presentations.git Add a test that Person->full_name actually uses the predicate method --- diff --git a/moose-class/exercises/t/lib/MooseClass/Tests.pm b/moose-class/exercises/t/lib/MooseClass/Tests.pm index aba82cf..00c7a49 100644 --- a/moose-class/exercises/t/lib/MooseClass/Tests.pm +++ b/moose-class/exercises/t/lib/MooseClass/Tests.pm @@ -321,12 +321,17 @@ sub person03 { is( $person->full_name, 'Bilbo Baggins', 'full_name() is correctly implemented for a Person without a title' ); ok( !$person->has_title, - 'Person has_title predicate is working correctly' ); + 'Person has_title predicate is working correctly (returns false)' ); $person->title('Ringbearer'); - ok( $person->has_title, 'Person has_title predicate is working correctly' ); + ok( $person->has_title, 'Person has_title predicate is working correctly (returns true)' ); + + Person->meta->make_mutable; + my $called = 0; + Person->meta->add_after_method_modifier( 'has_title' => sub { $called++ } ); is( $person->full_name, 'Bilbo Baggins (Ringbearer)', 'full_name() is correctly implemented for a Person with a title' ); + ok( $called, 'full_name in person uses the predicate for the title attribute' ); $person->clear_title; ok( !$person->has_title, 'Person clear_title method cleared the title' );