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