fixed test count
[gitmo/Mouse.git] / t / 030_roles / 002_role.t
CommitLineData
67199842 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 36;
7use Test::Exception;
8
9=pod
10
11NOTE:
12
13Should we be testing here that the has & override
14are injecting their methods correctly? In other
15words, should 'has_method' return true for them?
16
17=cut
18
19{
20 package FooRole;
21 use Mouse::Role;
22
23 our $VERSION = '0.01';
24
25 has 'bar' => (is => 'rw', isa => 'Foo');
26 has 'baz' => (is => 'ro');
27
28 sub foo { 'FooRole::foo' }
29 sub boo { 'FooRole::boo' }
30
31 before 'boo' => sub { "FooRole::boo:before" };
32
33 after 'boo' => sub { "FooRole::boo:after1" };
34 after 'boo' => sub { "FooRole::boo:after2" };
35
36 around 'boo' => sub { "FooRole::boo:around" };
37
38 override 'bling' => sub { "FooRole::bling:override" };
39 override 'fling' => sub { "FooRole::fling:override" };
40
41 ::dies_ok { extends() } '... extends() is not supported';
42 ::dies_ok { augment() } '... augment() is not supported';
43 ::dies_ok { inner() } '... inner() is not supported';
44
45 no Mouse::Role;
46}
47
48my $foo_role = FooRole->meta;
49isa_ok($foo_role, 'Mouse::Meta::Role');
50SKIP: { skip "Mouse: doesn't use Class::MOP" => 1;
51isa_ok($foo_role, 'Class::MOP::Module');
52}
53
54is($foo_role->name, 'FooRole', '... got the right name of FooRole');
55is($foo_role->version, '0.01', '... got the right version of FooRole');
56
57# methods ...
58
59TODO: { todo_skip "Mouse: not yet implemented" => 6;
60ok($foo_role->has_method('foo'), '... FooRole has the foo method');
61is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
62
63isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method');
64
65ok($foo_role->has_method('boo'), '... FooRole has the boo method');
66is($foo_role->get_method('boo')->body, \&FooRole::boo, '... FooRole got the boo method');
67
68isa_ok($foo_role->get_method('boo'), 'Mouse::Meta::Role::Method');
69}
70
71is_deeply(
72 [ sort $foo_role->get_method_list() ],
73 [ 'boo', 'foo' ],
74 '... got the right method list');
75
76ok(FooRole->can('foo'), "locally defined methods are still there");
77ok(!FooRole->can('has'), "sugar was unimported");
78
79# attributes ...
80
81is_deeply(
82 [ sort $foo_role->get_attribute_list() ],
83 [ 'bar', 'baz' ],
84 '... got the right attribute list');
85
86ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
87
88is_deeply(
89 $foo_role->get_attribute('bar'),
90 { is => 'rw', isa => 'Foo' },
91 '... got the correct description of the bar attribute');
92
93ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
94
95is_deeply(
96 $foo_role->get_attribute('baz'),
97 { is => 'ro' },
98 '... got the correct description of the baz attribute');
99
100# method modifiers
101TODO: { todo_skip "Mouse: not yet implemented" => 15;
102
103ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
104is(($foo_role->get_before_method_modifiers('boo'))[0]->(),
105 "FooRole::boo:before",
106 '... got the right method back');
107
108is_deeply(
109 [ $foo_role->get_method_modifier_list('before') ],
110 [ 'boo' ],
111 '... got the right list of before method modifiers');
112
113ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier');
114is(($foo_role->get_after_method_modifiers('boo'))[0]->(),
115 "FooRole::boo:after1",
116 '... got the right method back');
117is(($foo_role->get_after_method_modifiers('boo'))[1]->(),
118 "FooRole::boo:after2",
119 '... got the right method back');
120
121is_deeply(
122 [ $foo_role->get_method_modifier_list('after') ],
123 [ 'boo' ],
124 '... got the right list of after method modifiers');
125
126ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier');
127is(($foo_role->get_around_method_modifiers('boo'))[0]->(),
128 "FooRole::boo:around",
129 '... got the right method back');
130
131is_deeply(
132 [ $foo_role->get_method_modifier_list('around') ],
133 [ 'boo' ],
134 '... got the right list of around method modifiers');
135
136
137## overrides
138
139ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier');
140is($foo_role->get_override_method_modifier('bling')->(),
141 "FooRole::bling:override",
142 '... got the right method back');
143
144ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier');
145is($foo_role->get_override_method_modifier('fling')->(),
146 "FooRole::fling:override",
147 '... got the right method back');
148
149is_deeply(
150 [ sort $foo_role->get_method_modifier_list('override') ],
151 [ 'bling', 'fling' ],
152 '... got the right list of override method modifiers');
153
154}