561fff370aa5616a798d62e749c8f9c94b784a63
[gitmo/MooseX-MetaDescription.git] / t / 003_inheriting_meta_desc.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More no_plan => 1;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('MooseX::MetaDescription');
11 }
12
13 {
14     package Foo;
15     use Moose;
16     
17     has 'baz' => (
18         traits      => [ 'MooseX::MetaDescription::Meta::Trait' ],
19         is          => 'ro',
20         isa         => 'Str',   
21         default     => sub { 'Foo::baz' },
22         description => {
23             bar   => 'Foo::baz::bar',
24             gorch => 'Foo::baz::gorch',
25         }
26     );    
27     
28     package Bar;
29     use Moose;
30     
31     extends 'Foo';
32 }
33
34 # check the meta-desc
35
36 my $baz_attr = Foo->meta->find_attribute_by_name('baz');
37 isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description');
38 is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
39
40 {
41     my $baz_attr = Bar->meta->find_attribute_by_name('baz');
42     can_ok($baz_attr, 'description');    
43     isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description');
44     is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
45     
46     my ($baz_attr_2) = Bar->meta->compute_all_applicable_attributes;
47     is($baz_attr, $baz_attr_2, '... got the same attribute');
48 }
49
50 # check the actual descs
51
52 foreach my $foo ('Foo', Foo->new, 'Bar', Bar->new) {
53
54     is_deeply(
55         $foo->meta->find_attribute_by_name('baz')->description,
56         {
57             bar   => 'Foo::baz::bar',
58             gorch => 'Foo::baz::gorch',
59         },
60         '... got the right class description'
61     );
62 }