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