Revert autogenerated tests. Tests should not changed radically.
[gitmo/Mouse.git] / t / 030_roles / 016_runtime_roles_and_nonmoose.t
CommitLineData
67199842 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6475f69d 6use Test::More;
67199842 7use Test::Exception;
8use Scalar::Util 'blessed';
9
10
67199842 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
34my $bar = Bar->new;
6cfa1e5e 35isa_ok($bar, 'Bar');
67199842 36
37my $foo = Foo->new;
6cfa1e5e 38isa_ok($foo, 'Foo');
67199842 39
40ok(!$bar->can( 'talk' ), "... the role is not composed yet");
41
42dies_ok {
43 $foo->dog($bar)
44} '... and setting the accessor fails (not a Dog yet)';
45
46Dog->meta->apply($bar);
47
48ok($bar->can('talk'), "... the role is now composed at the object level");
49
50is($bar->talk, 'woof', '... got the right return value for the newly composed method');
51
52lives_ok {
53 $foo->dog($bar)
54} '... and setting the accessor is okay';
55
6475f69d 56done_testing;