remove trailing whitespace
[gitmo/Moose.git] / t / 030_roles / 013_method_aliasing_in_composition.t
index 42d3400..4e5c25a 100644 (file)
@@ -3,12 +3,10 @@
 use strict;
 use warnings;
 
-use Test::More tests => 31;
+use Test::More tests => 35;
 use Test::Exception;
 
-BEGIN {
-    use_ok('Moose');
-}
+
 
 {
     package My::Role;
@@ -17,7 +15,7 @@ BEGIN {
     sub foo { 'Foo::foo' }
     sub bar { 'Foo::bar' }
     sub baz { 'Foo::baz' }
-    
+
     requires 'role_bar';
 
     package My::Class;
@@ -26,14 +24,14 @@ 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';    
-    
+    } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds';
+
     sub role_bar { 'FAIL' }
 }
 
@@ -48,55 +46,67 @@ ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar ro
     } '... 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' }    
+    } 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 baz role_bar);
-ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
+ok(!My::OtherRole->meta->requires_method('bar'), '... and the &bar method is not required');
 ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
 
 {
+    package My::AliasingRole;
+    use Moose::Role;
+
+    ::lives_ok {
+        with 'My::Role' => { alias => { bar => 'role_bar' } };
+    } '... this succeeds';
+}
+
+ok(My::AliasingRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
+ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is required');
+
+{
     package Foo::Role;
     use Moose::Role;
-    
+
     sub foo { 'Foo::Role::foo' }
-    
+
     package Bar::Role;
     use Moose::Role;
-    
-    sub foo { 'Bar::Role::foo' }    
+
+    sub foo { 'Bar::Role::foo' }
 
     package Baz::Role;
     use Moose::Role;
-    
-    sub foo { 'Baz::Role::foo' }   
-    
+
+    sub foo { 'Baz::Role::foo' }
+
     package My::Foo::Class;
     use Moose;
-    
+
     ::lives_ok {
         with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
-             'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, 
+             'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' },
              'Baz::Role';
-    } '... composed our roles correctly';   
-    
+    } '... composed our roles correctly';
+
     package My::Foo::Class::Broken;
     use Moose;
-    
+
     ::throws_ok {
         with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
-             'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, 
+             'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
              'Baz::Role';
-    } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo_foo\' to be implemented by \'My::Foo::Class::Broken\'/, 
-      '... composed our roles correctly';    
+    } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo_foo\' to be implemented by \'My::Foo::Class::Broken\'/,
+      '... composed our roles correctly';
 }
 
 {
@@ -104,8 +114,8 @@ ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar met
     isa_ok($foo, 'My::Foo::Class');
     can_ok($foo, $_) for qw/foo foo_foo bar_foo/;
     is($foo->foo, 'Baz::Role::foo', '... got the right method');
-    is($foo->foo_foo, 'Foo::Role::foo', '... got the right method');    
-    is($foo->bar_foo, 'Bar::Role::foo', '... got the right method');        
+    is($foo->foo_foo, 'Foo::Role::foo', '... got the right method');
+    is($foo->bar_foo, 'Bar::Role::foo', '... got the right method');
 }
 
 {
@@ -114,7 +124,7 @@ ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar met
 
     ::lives_ok {
         with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
-             'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, 
+             'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' },
              'Baz::Role';
     } '... composed our roles correctly';
 }
@@ -129,7 +139,7 @@ ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not
 
     ::lives_ok {
         with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
-             'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, 
+             'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
              'Baz::Role';
     } '... composed our roles correctly';
 }