Browse files

...and also check 'requires => ?' attribute options

  • Loading branch information...
1 parent 3140ba4 commit 7b31771dc2d658ff2f7c9ebcc62c891468df9f44 @RsrchBoy committed Oct 28, 2012
Showing with 19 additions and 6 deletions.
  1. +9 −0 lib/Test/Moose/More.pm
  2. +10 −6 t/validate_attribute.t
View
9 lib/Test/Moose/More.pm
@@ -414,6 +414,7 @@ expect:
default => undef,
init_arg => 'foo',
lazy => 1,
+ required => undef,
);
@@ -504,6 +505,14 @@ sub _attribute_options_ok {
is($att->$property, $value, "$thing_name option $property correct")
};
+ if (my $is_required = delete $opts{required}) {
+
+ $is_required
+ ? ok($att->is_required, "$thing_name is required")
+ : ok(!$att->is_required, "$thing_name is not required")
+ ;
+ }
+
$check->($_) for grep { any(@check_opts) eq $_ } sort keys %opts;
do { $tb->skip("cannot test '$_' options yet", 1); delete $opts{$_} }
View
16 t/validate_attribute.t
@@ -20,12 +20,13 @@ use TAP::SimpleOutput 'counters';
use namespace::autoclean;
has foo => (
- traits => [ 'TestRole' ],
- is => 'ro',
- isa => 'Int',
- builder => '_build_foo',
- lazy => 1,
- thinger => 'foo',
+ traits => [ 'TestRole' ],
+ required => 1,
+ is => 'ro',
+ isa => 'Int',
+ builder => '_build_foo',
+ lazy => 1,
+ thinger => 'foo',
);
}
@@ -39,6 +40,7 @@ note 'validate attribute validation';
test_out $_ok->(q{Moose::Meta::Class::__ANON__::SERIAL::1 is a Moose class});
test_out $_ok->('The object isa Moose::Meta::Attribute');
test_out $_ok->('Moose::Meta::Class::__ANON__::SERIAL::1 does TestRole');
+ test_out $_ok->('foo is required');
test_out $_ok->('foo has a builder');
test_out $_ok->('foo option builder correct');
test_out $_ok->('foo does not have a default');
@@ -68,6 +70,7 @@ note 'validate attribute validation';
default => undef,
init_arg => 'foo',
lazy => 1,
+ required => 1,
thinger => 'foo',
binger => 'bar',
);
@@ -89,6 +92,7 @@ subtest 'a standalone run of validate_attribute' => sub {
builder => '_build_foo',
default => undef,
init_arg => 'foo',
+ required => 1,
lazy => 1,
thinger => 'foo',
);

0 comments on commit 7b31771

Please sign in to comment.