Commit | Line | Data |
e46edf94 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
687e52bb |
6 | use Test::More tests => 11; |
e46edf94 |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('Moose'); |
11 | } |
12 | |
13 | { |
14 | package Foo::Role; |
e46edf94 |
15 | use Moose::Role; |
16 | |
17 | requires 'foo'; |
18 | } |
19 | |
fa1be058 |
20 | is_deeply( |
21 | [ sort Foo::Role->meta->get_required_method_list ], |
22 | [ 'foo' ], |
23 | '... the Foo::Role has a required method (foo)'); |
24 | |
e46edf94 |
25 | # classes which does not implement required method |
26 | { |
27 | package Foo::Class; |
e46edf94 |
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; |
e46edf94 |
36 | use Moose; |
37 | |
687e52bb |
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'; |
e46edf94 |
40 | |
41 | sub foo { 'Bar::Class::foo' } |
42 | } |
43 | |
44 | # role which does implement required method |
45 | { |
46 | package Bar::Role; |
e46edf94 |
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 | |
fa1be058 |
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 | |
e46edf94 |
59 | # role which does not implement required method |
60 | { |
61 | package Baz::Role; |
fa1be058 |
62 | use Moose::Role; |
e46edf94 |
63 | |
581674fc |
64 | ::lives_ok { with('Foo::Role') } '... no foo method implemented by Baz::Role'; |
e46edf94 |
65 | } |
66 | |
fa1be058 |
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; |
fa1be058 |
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; |
fa1be058 |
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 | |