Resolve 4 'failing' tests
[gitmo/Mouse.git] / t / 030_roles / 015_runtime_roles_and_attrs.t
CommitLineData
67199842 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 11;
7use Test::Exception;
8use Scalar::Util 'blessed';
9
10
11
12
13{
14 package Dog;
15 use Mouse::Role;
16
17 sub talk { 'woof' }
18
19 has fur => (
20 isa => "Str",
21 is => "rw",
22 default => "dirty",
23 );
24
25 package Foo;
26 use Mouse;
27
28 has 'dog' => (
29 is => 'rw',
30 does => 'Dog',
31 );
32}
33
34my $obj = Foo->new;
6cfa1e5e 35isa_ok($obj, 'Foo');
67199842 36
37ok(!$obj->can( 'talk' ), "... the role is not composed yet");
38ok(!$obj->can( 'fur' ), 'ditto');
39ok(!$obj->does('Dog'), '... we do not do any roles yet');
40
41dies_ok {
42 $obj->dog($obj)
43} '... and setting the accessor fails (not a Dog yet)';
44
45Dog->meta->apply($obj);
46
47ok($obj->does('Dog'), '... we now do the Bark role');
48ok($obj->can('talk'), "... the role is now composed at the object level");
49ok($obj->can('fur'), "it has fur");
50
51is($obj->talk, 'woof', '... got the right return value for the newly composed method');
52
53lives_ok {
54 $obj->dog($obj)
55} '... and setting the accessor is okay';
56
57is($obj->fur, "dirty", "role attr initialized");