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