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