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