initial import
[gitmo/MooseX-StrictConstructor.git] / t / basic.t
CommitLineData
32726d88 1use strict;
2use warnings;
3
4use Test::More tests => 4;
5
6
7{
8 package Standard;
9
10 use Moose;
11
12 has 'thing' => ( is => 'rw' );
13}
14
15{
16 package Stricter;
17
18 use MooseX::StrictConstructor;
19
20 has 'thing' => ( is => 'rw' );
21}
22
23{
24 package Tricky;
25
26 use MooseX::StrictConstructor;
27
28 has 'thing' => ( is => 'rw' );
29
30 sub BUILD
31 {
32 my $self = shift;
33 my $params = shift;
34
35 delete $params->{spy};
36 }
37}
38
39
40eval { Standard->new( thing => 1, bad => 99 ) };
41is( $@, '', 'standard Moose class ignores unknown params' );
42
43eval { Stricter->new( thing => 1, bad => 99 ) };
44like( $@, qr/unknown attribute.+: bad/, 'strict constructor blows up on unknown params' );
45
46eval { Tricky->new( thing => 1, spy => 99 ) };
47is( $@, '', 'can work around strict constructor by deleting params in BUILD()' );
48
49eval { Tricky->new( thing => 1, agent => 99 ) };
50like( $@, qr/unknown attribute.+: agent/, 'Tricky still blows up on unknown params other than spy' );