no_plan does not take a param
[gitmo/MooseX-MetaDescription.git] / t / 002_custom_description.t
CommitLineData
91297cb4 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
d68e679f 6use Test::More 'no_plan';
91297cb4 7use Test::Exception;
8
9BEGIN {
10 use_ok('MooseX::MetaDescription');
11}
12
13{
14 package Foo::Description;
15 use Moose;
16
17 extends 'MooseX::MetaDescription::Description';
18
19 has 'bar' => (is => 'ro', isa => 'Str');
20 has 'baz' => (is => 'ro', isa => 'Str');
21 has 'gorch' => (is => 'ro', isa => 'Str');
22
23 package Foo::MetaDescription::Trait;
24 use Moose::Role;
25
26 with 'MooseX::MetaDescription::Meta::Trait';
27
28 has '+metadescription_classname' => (
29 default => 'Foo::Description'
30 );
31
32 package Foo::MetaDescription::Attribute;
33 use Moose;
34
35 extends 'MooseX::MetaDescription::Meta::Attribute';
36 with 'Foo::MetaDescription::Trait';
37
38 has '+metadescription_classname' => (
39 default => 'Foo::Description'
40 );
41}
42
43{
44 package Foo;
45 use Moose;
46
47 has 'bar' => (
48 metaclass => 'Foo::MetaDescription::Attribute',
49 is => 'ro',
50 isa => 'Str',
51 default => sub { 'Foo::bar' },
52 description => {
53 baz => 'Foo::bar::baz',
54 gorch => 'Foo::bar::gorch',
55 }
56 );
57
58 has 'baz' => (
59 traits => [ 'Foo::MetaDescription::Trait' ],
60 is => 'ro',
61 isa => 'Str',
62 default => sub { 'Foo::baz' },
63 description => {
64 bar => 'Foo::baz::bar',
65 gorch => 'Foo::baz::gorch',
66 }
67 );
68}
69
70# check the meta-desc
71
72my $bar_attr = Foo->meta->get_attribute('bar');
73isa_ok($bar_attr->metadescription, 'MooseX::MetaDescription::Description');
74isa_ok($bar_attr->metadescription, 'Foo::Description');
75is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref');
76
77my $baz_attr = Foo->meta->get_attribute('baz');
78isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description');
79isa_ok($baz_attr->metadescription, 'Foo::Description');
80is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref');
81
82# check the actual descs
83
84foreach my $foo ('Foo', Foo->new) {
85
86 is_deeply(
87 $foo->meta->get_attribute('bar')->description,
88 {
89 baz => 'Foo::bar::baz',
90 gorch => 'Foo::bar::gorch',
91 },
92 '... got the right class description'
93 );
94
95 my $bar_meta_desc = $foo->meta->get_attribute('bar')->metadescription;
96 is($bar_meta_desc->baz, 'Foo::bar::baz', '... we have methods');
97 is($bar_meta_desc->gorch, 'Foo::bar::gorch', '... we have methods');
98
99 is_deeply(
100 $foo->meta->get_attribute('baz')->description,
101 {
102 bar => 'Foo::baz::bar',
103 gorch => 'Foo::baz::gorch',
104 },
105 '... got the right class description'
106 );
107
108 my $baz_meta_desc = $foo->meta->get_attribute('baz')->metadescription;
109 is($baz_meta_desc->bar, 'Foo::baz::bar', '... we have methods');
110 is($baz_meta_desc->gorch, 'Foo::baz::gorch', '... we have methods');
111}
112