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