Redid conversion to Test::Fatal
[gitmo/Moose.git] / t / 030_roles / 018_runtime_roles_w_params.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Fatal;
8
9
10 {
11     package Foo;
12     use Moose;
13     has 'bar' => (is => 'ro');
14
15     package Bar;
16     use Moose::Role;
17
18     has 'baz' => (is => 'ro', default => 'BAZ');
19 }
20
21 # normal ...
22 {
23     my $foo = Foo->new(bar => 'BAR');
24     isa_ok($foo, 'Foo');
25
26     is($foo->bar, 'BAR', '... got the expect value');
27     ok(!$foo->can('baz'), '... no baz method though');
28
29     is( exception {
30         Bar->meta->apply($foo)
31     }, undef, '... this works' );
32
33     is($foo->bar, 'BAR', '... got the expect value');
34     ok($foo->can('baz'), '... we have baz method now');
35     is($foo->baz, 'BAZ', '... got the expect value');
36 }
37
38 # with extra params ...
39 {
40     my $foo = Foo->new(bar => 'BAR');
41     isa_ok($foo, 'Foo');
42
43     is($foo->bar, 'BAR', '... got the expect value');
44     ok(!$foo->can('baz'), '... no baz method though');
45
46     is( exception {
47         Bar->meta->apply($foo, (rebless_params => { baz => 'FOO-BAZ' }))
48     }, undef, '... this works' );
49
50     is($foo->bar, 'BAR', '... got the expect value');
51     ok($foo->can('baz'), '... we have baz method now');
52     is($foo->baz, 'FOO-BAZ', '... got the expect value');
53 }
54
55 # with extra params ...
56 {
57     my $foo = Foo->new(bar => 'BAR');
58     isa_ok($foo, 'Foo');
59
60     is($foo->bar, 'BAR', '... got the expect value');
61     ok(!$foo->can('baz'), '... no baz method though');
62
63     is( exception {
64         Bar->meta->apply($foo, (rebless_params => { bar => 'FOO-BAR', baz => 'FOO-BAZ' }))
65     }, undef, '... this works' );
66
67     is($foo->bar, 'FOO-BAR', '... got the expect value');
68     ok($foo->can('baz'), '... we have baz method now');
69     is($foo->baz, 'FOO-BAZ', '... got the expect value');
70 }
71
72 done_testing;