Convert all tests to done_testing.
[gitmo/Moose.git] / t / 020_attributes / 020_trigger_and_coerce.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9
10 {
11
12     package Fake::DateTime;
13     use Moose;
14
15     has 'string_repr' => ( is => 'ro' );
16
17     package Mortgage;
18     use Moose;
19     use Moose::Util::TypeConstraints;
20
21     coerce 'Fake::DateTime' => from 'Str' =>
22         via { Fake::DateTime->new( string_repr => $_ ) };
23
24     has 'closing_date' => (
25         is      => 'rw',
26         isa     => 'Fake::DateTime',
27         coerce  => 1,
28         trigger => sub {
29             my ( $self, $val ) = @_;
30             ::pass('... trigger is being called');
31             ::isa_ok( $self->closing_date, 'Fake::DateTime' );
32             ::isa_ok( $val,                'Fake::DateTime' );
33         }
34     );
35 }
36
37 {
38     my $mtg = Mortgage->new( closing_date => 'yesterday' );
39     isa_ok( $mtg, 'Mortgage' );
40
41     # check that coercion worked
42     isa_ok( $mtg->closing_date, 'Fake::DateTime' );
43 }
44
45 Mortgage->meta->make_immutable;
46 ok( Mortgage->meta->is_immutable, '... Mortgage is now immutable' );
47
48 {
49     my $mtg = Mortgage->new( closing_date => 'yesterday' );
50     isa_ok( $mtg, 'Mortgage' );
51
52     # check that coercion worked
53     isa_ok( $mtg->closing_date, 'Fake::DateTime' );
54 }
55
56 done_testing;