adding ->parent_registry to the TC registry object
[gitmo/Moose.git] / t / 030_roles / 004_role_composition_errors.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 11;
7 use Test::Exception;
8
9 BEGIN {  
10     use_ok('Moose');               
11 }
12
13 {
14     package Foo::Role;
15     use Moose::Role;
16     
17     requires 'foo';
18 }
19
20 is_deeply(
21     [ sort Foo::Role->meta->get_required_method_list ],
22     [ 'foo' ],
23     '... the Foo::Role has a required method (foo)');
24
25 # classes which does not implement required method
26 {
27     package Foo::Class;
28     use Moose;
29     
30     ::dies_ok { with('Foo::Role') } '... no foo method implemented by Foo::Class';
31 }
32
33 # class which does implement required method
34 {
35     package Bar::Class;
36     use Moose;
37     
38     ::dies_ok  { with('Foo::Class') } '... cannot consume a class, it must be a role';
39     ::lives_ok { with('Foo::Role')  } '... has a foo method implemented by Bar::Class';
40     
41     sub foo { 'Bar::Class::foo' }
42 }
43
44 # role which does implement required method
45 {
46     package Bar::Role;
47     use Moose::Role;
48     
49     ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Role';
50     
51     sub foo { 'Bar::Role::foo' }
52 }
53
54 is_deeply(
55     [ sort Bar::Role->meta->get_required_method_list ],
56     [],
57     '... the Bar::Role has not inherited the required method from Foo::Role');
58
59 # role which does not implement required method
60 {
61     package Baz::Role;
62     use Moose::Role;
63     
64     ::lives_ok { with('Foo::Role') } '... no foo method implemented by Baz::Role';
65 }
66
67 is_deeply(
68     [ sort Baz::Role->meta->get_required_method_list ],
69     [ 'foo' ],
70     '... the Baz::Role has inherited the required method from Foo::Role');
71     
72 # classes which does not implement required method
73 {
74     package Baz::Class;
75     use Moose;
76
77     ::dies_ok { with('Baz::Role') } '... no foo method implemented by Baz::Class2';
78 }
79
80 # class which does implement required method
81 {
82     package Baz::Class2;
83     use Moose;
84
85     ::lives_ok { with('Baz::Role') } '... has a foo method implemented by Baz::Class2';
86
87     sub foo { 'Baz::Class2::foo' }
88 }    
89     
90