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