X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F030_roles%2Ffailing%2F012_method_exclusion_in_composition.t;fp=t%2F030_roles%2Ffailing%2F012_method_exclusion_in_composition.t;h=d852b17e12e22d1c35567d2324cea13b11647714;hp=0000000000000000000000000000000000000000;hb=9864f0e4ba233c5f30ad6dc7c484ced43d883d27;hpb=8845df4dd6432e3164d078ade741409061adae9f diff --git a/t/030_roles/failing/012_method_exclusion_in_composition.t b/t/030_roles/failing/012_method_exclusion_in_composition.t new file mode 100644 index 0000000..d852b17 --- /dev/null +++ b/t/030_roles/failing/012_method_exclusion_in_composition.t @@ -0,0 +1,115 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 19; +use Test::Exception; + + + +{ + package My::Role; + use Mouse::Role; + + sub foo { 'Foo::foo' } + sub bar { 'Foo::bar' } + sub baz { 'Foo::baz' } + + package My::Class; + use Mouse; + + with 'My::Role' => { -excludes => 'bar' }; +} + +ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz); +ok(!My::Class->meta->has_method('bar'), '... but we excluded bar'); + +{ + package My::OtherRole; + use Mouse::Role; + + with 'My::Role' => { -excludes => 'foo' }; + + sub foo { 'My::OtherRole::foo' } + sub bar { 'My::OtherRole::bar' } +} + +ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz); + +ok(!My::OtherRole->meta->requires_method('foo'), '... and the &foo method is not required'); +ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required'); + +{ + package Foo::Role; + use Mouse::Role; + + sub foo { 'Foo::Role::foo' } + + package Bar::Role; + use Mouse::Role; + + sub foo { 'Bar::Role::foo' } + + package Baz::Role; + use Mouse::Role; + + sub foo { 'Baz::Role::foo' } + + package My::Foo::Class; + use Mouse; + + ::lives_ok { + with 'Foo::Role' => { -excludes => 'foo' }, + 'Bar::Role' => { -excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; + + package My::Foo::Class::Broken; + use Mouse; + + ::throws_ok { + with 'Foo::Role', + 'Bar::Role' => { -excludes => 'foo' }, + 'Baz::Role'; + } qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, + '... composed our roles correctly'; +} + +{ + my $foo = My::Foo::Class->new; + isa_ok($foo, 'My::Foo::Class'); + can_ok($foo, 'foo'); + is($foo->foo, 'Baz::Role::foo', '... got the right method'); +} + +{ + package My::Foo::Role; + use Mouse::Role; + + ::lives_ok { + with 'Foo::Role' => { -excludes => 'foo' }, + 'Bar::Role' => { -excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; +} + +ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method"); +ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required'); + +{ + package My::Foo::Role::Other; + use Mouse::Role; + + ::lives_ok { + with 'Foo::Role', + 'Bar::Role' => { -excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; +} + +ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method"); +ok(My::Foo::Role::Other->meta->requires_method('foo'), '... and the &foo method is required'); + + +