Add another MOOSE_TEST_MD option, MooseX
[gitmo/Moose.git] / t / roles / runtime_roles_w_params.t
CommitLineData
3a79f0e9 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
b10dde3a 7use Test::Fatal;
3a79f0e9 8
7ff56534 9
3a79f0e9 10{
11 package Foo;
12 use Moose;
13 has 'bar' => (is => 'ro');
d03bd989 14
3a79f0e9 15 package Bar;
16 use Moose::Role;
d03bd989 17
18 has 'baz' => (is => 'ro', default => 'BAZ');
3a79f0e9 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
b10dde3a 29 is( exception {
3a79f0e9 30 Bar->meta->apply($foo)
b10dde3a 31 }, undef, '... this works' );
3a79f0e9 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
b10dde3a 46 is( exception {
3a79f0e9 47 Bar->meta->apply($foo, (rebless_params => { baz => 'FOO-BAZ' }))
b10dde3a 48 }, undef, '... this works' );
3a79f0e9 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
b10dde3a 63 is( exception {
3a79f0e9 64 Bar->meta->apply($foo, (rebless_params => { bar => 'FOO-BAR', baz => 'FOO-BAZ' }))
b10dde3a 65 }, undef, '... this works' );
3a79f0e9 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
a28e50e4 72done_testing;