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