From: Dave Rolsky Date: Fri, 9 Jul 2010 14:46:06 +0000 (-0500) Subject: Make tests match the order of the instructions for test 03 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=39182c071340a56f55c909d2aac7c6e009fa8b63;p=gitmo%2Fmoose-presentations.git Make tests match the order of the instructions for test 03 Fix answers to match test instructions (first & last name should be required) and test for this. --- diff --git a/moose-class/exercises/answers/03-basic-attributes/Person.pm b/moose-class/exercises/answers/03-basic-attributes/Person.pm index 3a42949..c94f30c 100644 --- a/moose-class/exercises/answers/03-basic-attributes/Person.pm +++ b/moose-class/exercises/answers/03-basic-attributes/Person.pm @@ -10,9 +10,15 @@ has title => ( clearer => 'clear_title', ); -has first_name => ( is => 'rw' ); +has first_name => ( + is => 'rw', + required => 1, +); -has last_name => ( is => 'rw' ); +has last_name => ( + is => 'rw', + required => 1, +); sub BUILDARGS { my $class = shift; diff --git a/moose-class/exercises/t/lib/MooseClass/Tests.pm b/moose-class/exercises/t/lib/MooseClass/Tests.pm index 42a38ee..524445b 100644 --- a/moose-class/exercises/t/lib/MooseClass/Tests.pm +++ b/moose-class/exercises/t/lib/MooseClass/Tests.pm @@ -61,20 +61,16 @@ sub tests02 { sub tests03 { has_meta('Person'); - has_meta('Employee'); - - has_rw_attr( 'Person', 'title' ); - has_rw_attr( 'Employee', 'title', 'overridden' ); - has_rw_attr( 'Employee', 'salary_level' ); - has_ro_attr( 'Employee', 'salary' ); + for my $name ( qw( first_name last_name ) ) { + has_rw_attr( 'Person', $name ); - has_method( 'Employee', '_build_salary' ); + my $attr = Person->meta->get_attribute($name); + ok( $attr && $attr->is_required, + "$name is required in Person" ); + } - ok( - !Employee->meta->has_method('full_name'), - 'Employee no longer implements a full_name method' - ); + has_rw_attr( 'Person', 'title' ); my $person_title_attr = Person->meta->get_attribute('title'); ok( !$person_title_attr->is_required, 'title is not required in Person' ); @@ -87,8 +83,11 @@ sub tests03 { 'Person title attr has a clear_title clearer' ); - my $balance_attr = Person->meta->get_attribute('balance'); - is( $balance_attr->default, 100, 'balance defaults to 100' ); + person03(); + + has_meta('Employee'); + + has_rw_attr( 'Employee', 'title', 'overridden' ); my $employee_title_attr = Employee->meta->get_attribute('title'); is( @@ -96,15 +95,29 @@ sub tests03 { 'title defaults to Worker in Employee' ); - my $salary_level_attr = Employee->meta->get_attribute('salary_level'); - is( $salary_level_attr->default, 1, 'salary_level defaults to 1' ); + ok( + !Employee->meta->has_method('full_name'), + 'Employee no longer implements a full_name method' + ); + + has_ro_attr( 'Employee', 'salary' ); my $salary_attr = Employee->meta->get_attribute('salary'); + ok( $salary_attr->is_lazy, 'salary is lazy' ); ok( !$salary_attr->init_arg, 'no init_arg for salary attribute' ); ok( $salary_attr->has_builder, 'salary attr has a builder' ); - person03(); + has_method( 'Employee', '_build_salary' ); + + has_rw_attr( 'Employee', 'salary_level' ); + + my $salary_level_attr = Employee->meta->get_attribute('salary_level'); + is( $salary_level_attr->default, 1, 'salary_level defaults to 1' ); + employee03(); + + my $balance_attr = Person->meta->get_attribute('balance'); + is( $balance_attr->default, 100, 'balance defaults to 100' ); } sub tests04 {