Many more fixes. That's probably all of them!
[gitmo/Moose.git] / t / 020_attributes / 006_attribute_required.t
CommitLineData
bbd2fe69 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
ab859145 6use Test::More tests => 16;
bbd2fe69 7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose');
11}
12
13{
14 package Foo;
bbd2fe69 15 use Moose;
16
17 has 'bar' => (is => 'ro', required => 1);
18 has 'baz' => (is => 'rw', default => 100, required => 1);
bbd2fe69 19 has 'boo' => (is => 'rw', lazy => 1, default => 50, required => 1);
20}
21
22{
23 my $foo = Foo->new(bar => 10, baz => 20, boo => 100);
24 isa_ok($foo, 'Foo');
25
26 is($foo->bar, 10, '... got the right bar');
27 is($foo->baz, 20, '... got the right baz');
28 is($foo->boo, 100, '... got the right boo');
29}
30
31{
32 my $foo = Foo->new(bar => 10, boo => 5);
33 isa_ok($foo, 'Foo');
34
35 is($foo->bar, 10, '... got the right bar');
36 is($foo->baz, 100, '... got the right baz');
37 is($foo->boo, 5, '... got the right boo');
38}
39
40{
41 my $foo = Foo->new(bar => 10);
42 isa_ok($foo, 'Foo');
43
44 is($foo->bar, 10, '... got the right bar');
45 is($foo->baz, 100, '... got the right baz');
46 is($foo->boo, 50, '... got the right boo');
47}
48
49throws_ok {
ab859145 50 Foo->new(bar => 10, baz => undef);
51} qr/^Attribute \(baz\) is required and cannot be undef/, '... must supply all the required attribute';
52
53throws_ok {
54 Foo->new(bar => 10, boo => undef);
55} qr/^Attribute \(boo\) is required and cannot be undef/, '... must supply all the required attribute';
56
57throws_ok {
bbd2fe69 58 Foo->new;
59} qr/^Attribute \(bar\) is required/, '... must supply all the required attribute';
60