Merge 'Moose-moosex_compile_support' into 'trunk'
[gitmo/Moose.git] / t / 030_roles / 013_method_aliasing_during_composition.t
index 59130e6..c0587fe 100644 (file)
@@ -26,10 +26,18 @@ BEGIN {
     ::lives_ok {
         with 'My::Role' => { alias => { bar => 'role_bar' } };
     } '... this succeeds';
+    
+    package My::Class::Failure;
+    use Moose;
+
+    ::throws_ok {
+        with 'My::Role' => { alias => { bar => 'role_bar' } };
+    } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds';    
+    
+    sub role_bar { 'FAIL' }
 }
 
-ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
-ok(!My::Class->meta->has_method('bar'), '... but we dont get bar');
+ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar role_bar);
 
 {
     package My::OtherRole;
@@ -40,10 +48,19 @@ ok(!My::Class->meta->has_method('bar'), '... but we dont get bar');
     } '... this succeeds';
 
     sub bar { 'My::OtherRole::bar' }
+    
+    package My::OtherRole::Failure;
+    use Moose::Role;
+
+    ::throws_ok {
+        with 'My::Role' => { alias => { bar => 'role_bar' } };
+    } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds';    
+    
+    sub role_bar { 'FAIL' }    
 }
 
-ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz role_bar);
-ok(!My::OtherRole->meta->requires_method('bar'), '... and the &bar method is not required');
+ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
+ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
 ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');