5d1195ea05cca0a1f8849d8bc3ce023a7d2b1225
[gitmo/Moose.git] / t / 041_role.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 25;
7 use Test::Exception;
8
9 BEGIN {  
10     use_ok('Moose::Role');               
11 }
12
13 =pod
14
15 NOTE:
16
17 Should we be testing here that the has & override
18 are injecting their methods correctly? In other 
19 words, should 'has_method' return true for them?
20
21 =cut
22
23 {
24     package FooRole;
25     use Moose::Role;
26     
27     our $VERSION = '0.01';
28     
29     has 'bar' => (is => 'rw', isa => 'Foo');
30     has 'baz' => (is => 'ro');    
31     
32     sub foo { 'FooRole::foo' }
33     sub boo { 'FooRole::boo' }    
34    
35     ::dies_ok { extends() } '... extends() is not supported';
36     ::dies_ok { augment() } '... augment() is not supported';
37     ::dies_ok { inner() } '... inner() is not supported';
38     ::dies_ok { overrides() } '... overrides() is not supported';
39     ::dies_ok { super() } '... super() is not supported';
40     ::dies_ok { after() } '... after() is not supported';
41     ::dies_ok { before() } '... before() is not supported';
42     ::dies_ok { around() } '... around() is not supported';
43 }
44
45 my $foo_role = FooRole->meta;
46 isa_ok($foo_role, 'Moose::Meta::Role');
47
48 isa_ok($foo_role->_role_meta, 'Class::MOP::Class');
49
50 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
51 is($foo_role->version, '0.01', '... got the right version of FooRole');
52
53 # methods ...
54
55 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
56 is($foo_role->get_method('foo'), \&FooRole::foo, '... FooRole got the foo method');
57
58 isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method');
59
60 ok($foo_role->has_method('boo'), '... FooRole has the boo method');
61 is($foo_role->get_method('boo'), \&FooRole::boo, '... FooRole got the boo method');
62
63 isa_ok($foo_role->get_method('boo'), 'Moose::Meta::Role::Method');
64
65 is_deeply(
66     [ sort $foo_role->get_method_list() ],
67     [ 'boo', 'foo' ],
68     '... got the right method list');
69     
70 # attributes ...
71
72 is_deeply(
73     [ sort $foo_role->get_attribute_list() ],
74     [ 'bar', 'baz' ],
75     '... got the right attribute list');
76
77 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
78
79 is_deeply(
80     $foo_role->get_attribute('bar'),
81     { is => 'rw', isa => 'Foo' },
82     '... got the correct description of the bar attribute');
83
84 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
85
86 is_deeply(
87     $foo_role->get_attribute('baz'),
88     { is => 'ro' },
89     '... got the correct description of the baz attribute');
90