X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F030_roles%2F002_role.t;h=67dcf4494ef99ac540a7ba140397df2520fc8bce;hp=448d4921c8e287da005b0281ec44b799e1c13782;hb=739525d0421188856c45329c8f001e9fbe0b30b2;hpb=8a168350bb0fea8bdae0034bc89fcdbe81f85ddc diff --git a/t/030_roles/002_role.t b/t/030_roles/002_role.t index 448d492..67dcf44 100755 --- a/t/030_roles/002_role.t +++ b/t/030_roles/002_role.t @@ -3,15 +3,18 @@ use strict; use warnings; -use Test::More tests => 36; +use Test::More tests => 40; use Test::Exception; +use lib 't/lib'; +use Test::Mouse; # Mouse::Meta::Module->version + =pod NOTE: Should we be testing here that the has & override -are injecting their methods correctly? In other +are injecting their methods correctly? In other words, should 'has_method' return true for them? =cut @@ -19,46 +22,44 @@ words, should 'has_method' return true for them? { package FooRole; use Mouse::Role; - + our $VERSION = '0.01'; - + has 'bar' => (is => 'rw', isa => 'Foo'); - has 'baz' => (is => 'ro'); - + has 'baz' => (is => 'ro'); + sub foo { 'FooRole::foo' } - sub boo { 'FooRole::boo' } - + sub boo { 'FooRole::boo' } + before 'boo' => sub { "FooRole::boo:before" }; - - after 'boo' => sub { "FooRole::boo:after1" }; - after 'boo' => sub { "FooRole::boo:after2" }; - - around 'boo' => sub { "FooRole::boo:around" }; - - override 'bling' => sub { "FooRole::bling:override" }; - override 'fling' => sub { "FooRole::fling:override" }; - + + after 'boo' => sub { "FooRole::boo:after1" }; + after 'boo' => sub { "FooRole::boo:after2" }; + + around 'boo' => sub { "FooRole::boo:around" }; + + override 'bling' => sub { "FooRole::bling:override" }; + override 'fling' => sub { "FooRole::fling:override" }; + ::dies_ok { extends() } '... extends() is not supported'; - ::dies_ok { augment() } '... augment() is not supported'; - ::dies_ok { inner() } '... inner() is not supported'; + ::dies_ok { augment() } '... augment() is not supported'; + ::dies_ok { inner() } '... inner() is not supported'; no Mouse::Role; } my $foo_role = FooRole->meta; isa_ok($foo_role, 'Mouse::Meta::Role'); -SKIP: { skip "Mouse: doesn't use Class::MOP" => 1; -isa_ok($foo_role, 'Class::MOP::Module'); -} +#isa_ok($foo_role, 'Class::MOP::Module'); is($foo_role->name, 'FooRole', '... got the right name of FooRole'); -is($foo_role->version, '0.01', '... got the right version of FooRole'); +is($foo_role->version, '0.01', '... got the right version of FooRole'); # methods ... -TODO: { todo_skip "Mouse: not yet implemented" => 6; -ok($foo_role->has_method('foo'), '... FooRole has the foo method'); -is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method'); + +ok($foo_role->has_method('foo'), '... FooRole has the foo method'); +is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method'); isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method'); @@ -66,7 +67,6 @@ ok($foo_role->has_method('boo'), '... FooRole has the boo method'); is($foo_role->get_method('boo')->body, \&FooRole::boo, '... FooRole got the boo method'); isa_ok($foo_role->get_method('boo'), 'Mouse::Meta::Role::Method'); -} is_deeply( [ sort $foo_role->get_method_list() ], @@ -85,21 +85,38 @@ is_deeply( ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute'); -is $foo_role->get_attribute('bar')->{is}, 'rw', '... got the correct description of the bar attribute'; +my $bar_attr = $foo_role->get_attribute('bar'); +is($bar_attr->{is}, 'rw', + 'bar attribute is rw'); +is($bar_attr->{isa}, 'Foo', + 'bar attribute isa Foo'); +{ + local $TODO = 'definition_context is not yet implemented'; + is(ref($bar_attr->{definition_context}), 'HASH', + 'bar\'s definition context is a hash'); + is($bar_attr->{definition_context}->{package}, 'FooRole', + 'bar was defined in FooRole'); +} ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute'); -is( - $foo_role->get_attribute('baz')->{is}, - 'ro', - '... got the correct description of the baz attribute'); +my $baz_attr = $foo_role->get_attribute('baz'); +is($baz_attr->{is}, 'ro', + 'baz attribute is ro'); + +{ + local $TODO = 'definition_context is not yet implemented'; + is(ref($baz_attr->{definition_context}), 'HASH', + 'bar\'s definition context is a hash'); + is($baz_attr->{definition_context}->{package}, 'FooRole', + 'baz was defined in FooRole'); +} # method modifiers -TODO: { todo_skip "Mouse: not yet implemented" => 15; ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier'); -is(($foo_role->get_before_method_modifiers('boo'))[0]->(), - "FooRole::boo:before", +is(($foo_role->get_before_method_modifiers('boo'))[0]->(), + "FooRole::boo:before", '... got the right method back'); is_deeply( @@ -108,21 +125,21 @@ is_deeply( '... got the right list of before method modifiers'); ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier'); -is(($foo_role->get_after_method_modifiers('boo'))[0]->(), - "FooRole::boo:after1", +is(($foo_role->get_after_method_modifiers('boo'))[0]->(), + "FooRole::boo:after1", + '... got the right method back'); +is(($foo_role->get_after_method_modifiers('boo'))[1]->(), + "FooRole::boo:after2", '... got the right method back'); -is(($foo_role->get_after_method_modifiers('boo'))[1]->(), - "FooRole::boo:after2", - '... got the right method back'); is_deeply( [ $foo_role->get_method_modifier_list('after') ], [ 'boo' ], '... got the right list of after method modifiers'); - + ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier'); -is(($foo_role->get_around_method_modifiers('boo'))[0]->(), - "FooRole::boo:around", +is(($foo_role->get_around_method_modifiers('boo'))[0]->(), + "FooRole::boo:around", '... got the right method back'); is_deeply( @@ -130,17 +147,16 @@ is_deeply( [ 'boo' ], '... got the right list of around method modifiers'); - ## overrides ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier'); -is($foo_role->get_override_method_modifier('bling')->(), - "FooRole::bling:override", +is($foo_role->get_override_method_modifier('bling')->(), + "FooRole::bling:override", '... got the right method back'); ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier'); -is($foo_role->get_override_method_modifier('fling')->(), - "FooRole::fling:override", +is($foo_role->get_override_method_modifier('fling')->(), + "FooRole::fling:override", '... got the right method back'); is_deeply( @@ -148,4 +164,3 @@ is_deeply( [ 'bling', 'fling' ], '... got the right list of override method modifiers'); -}