Convert all tests to done_testing.
[gitmo/Moose.git] / t / 200_examples / 005_example_w_TestDeep.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 =pod
9
10 This tests how well Moose type constraints
11 play with Test::Deep.
12
13 Its not as pretty as Declare::Constraints::Simple,
14 but it is not completely horrid either.
15
16 =cut
17
18 BEGIN {
19     eval "use Test::Deep;";
20     plan skip_all => "Test::Deep is required for this test" if $@;
21 }
22
23 use Test::Exception;
24
25 {
26     package Foo;
27     use Moose;
28     use Moose::Util::TypeConstraints;
29
30     use Test::Deep qw[
31         eq_deeply array_each subhashof ignore
32     ];
33
34     # define your own type ...
35     type 'ArrayOfHashOfBarsAndRandomNumbers'
36         => where {
37             eq_deeply($_,
38                 array_each(
39                     subhashof({
40                         bar           => Test::Deep::isa('Bar'),
41                         random_number => ignore()
42                     })
43                 )
44             )
45         };
46
47     has 'bar' => (
48         is  => 'rw',
49         isa => 'ArrayOfHashOfBarsAndRandomNumbers',
50     );
51
52     package Bar;
53     use Moose;
54 }
55
56 my $array_of_hashes = [
57     { bar => Bar->new, random_number => 10 },
58     { bar => Bar->new },
59 ];
60
61 my $foo;
62 lives_ok {
63     $foo = Foo->new('bar' => $array_of_hashes);
64 } '... construction succeeded';
65 isa_ok($foo, 'Foo');
66
67 is_deeply($foo->bar, $array_of_hashes, '... got our value correctly');
68
69 dies_ok {
70     $foo->bar({});
71 } '... validation failed correctly';
72
73 dies_ok {
74     $foo->bar([{ foo => 3 }]);
75 } '... validation failed correctly';
76
77 done_testing;