make the test style match the rest of the (modern) Moose tests
[gitmo/Moose.git] / t / 070_attribute_helpers / 011_counter_with_defaults.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 13;
7 use Test::Moose;
8
9 BEGIN {
10     use_ok('Moose::AttributeHelpers');
11 }
12
13 {
14     package MyHomePage;
15     use Moose;
16
17     has 'counter' => ( traits => ['Counter'] );
18 }
19
20 my $page = MyHomePage->new();
21 isa_ok( $page, 'MyHomePage' );
22
23 can_ok( $page, $_ ) for qw[
24     dec_counter
25     inc_counter
26     reset_counter
27 ];
28
29 is( $page->counter, 0, '... got the default value' );
30
31 $page->inc_counter;
32 is( $page->counter, 1, '... got the incremented value' );
33
34 $page->inc_counter;
35 is( $page->counter, 2, '... got the incremented value (again)' );
36
37 $page->dec_counter;
38 is( $page->counter, 1, '... got the decremented value' );
39
40 $page->reset_counter;
41 is( $page->counter, 0, '... got the original value' );
42
43 # check the meta ..
44
45 my $counter = $page->meta->get_attribute('counter');
46 does_ok( $counter, 'Moose::AttributeHelpers::Trait::Counter' );
47
48 is( $counter->type_constraint->name, 'Num',
49     '... got the expected default type constraint' );
50
51 is_deeply(
52     $counter->handles,
53     {
54         'inc_counter'   => 'inc',
55         'dec_counter'   => 'dec',
56         'reset_counter' => 'reset',
57         'set_counter'   => 'set',
58     },
59     '... got the right default handles methods'
60 );
61