Skip to content

Commit

Permalink
Better tests for validate_attribute and attribute_options_ok
Browse files Browse the repository at this point in the history
  • Loading branch information
rsrchboy committed Oct 5, 2012
1 parent ac0332c commit cea582d
Showing 1 changed file with 98 additions and 51 deletions.
149 changes: 98 additions & 51 deletions t/validate_attribute.t
@@ -1,8 +1,10 @@
use strict;
use warnings;

use Test::Builder::Tester;
use Test::More;
use Test::Moose::More;
use TAP::SimpleOutput 'counters';

{ package TestRole; use Moose::Role; use namespace::autoclean; }
{
Expand All @@ -21,59 +23,104 @@ use Test::Moose::More;

}

validate_attribute TestClass => foo => (
-does => [ 'TestRole' ],
-isa => [ 'Moose::Meta::Attribute' ],
traits => [ 'TestRole' ],
isa => 'Int',
does => 'Bar',
handles => { },
reader => 'foo',
builder => '_build_foo',
default => undef,
init_arg => 'foo',
lazy => 1,
);
# initial tests, covering the most straight-forward cases (IMHO)

attribute_options_ok TestClass => foo => (
traits => [ 'TestRole' ],
isa => 'Int',
does => 'Bar',
handles => { },
reader => 'foo',
builder => '_build_foo',
default => undef,
init_arg => 'foo',
lazy => 1,
);
note 'validate attribute validation';
{
my ($_ok, $_nok, $_skip) = counters();
test_out $_ok->('TestClass has an attribute named foo');
test_out $_ok->('Moose::Meta::Class::__ANON__::SERIAL::1 does TestRole');
test_out $_ok->('foo has a builder');
test_out $_ok->('foo option builder correct');
test_out $_ok->('foo does not have a default');
test_out $_ok->('foo option default correct');
test_out $_ok->('foo has a reader');
test_out $_ok->('foo option reader correct');
test_out $_skip->("cannot test 'isa' options yet");
test_out $_skip->("cannot test 'does' options yet");
test_out $_skip->("cannot test 'handles' options yet");
test_out $_skip->("cannot test 'traits' options yet");
test_out $_ok->('foo has a init_arg');
test_out $_ok->('foo option init_arg correct');
test_out $_ok->('foo is lazy');
validate_attribute TestClass => foo => (
-does => [ 'TestRole' ],
-isa => [ 'Moose::Meta::Attribute' ],
traits => [ 'TestRole' ],
isa => 'Int',
does => 'Bar',
handles => { },
reader => 'foo',
builder => '_build_foo',
default => undef,
init_arg => 'foo',
lazy => 1,
);
test_test 'validate_attribute works correctly';
}


subtest 'a standalone run of validate_attribute' => sub {

validate_attribute TestClass => foo => (
-does => [ 'TestRole' ],
-isa => [ 'Moose::Meta::Attribute' ],
traits => [ 'TestRole' ],
isa => 'Int',
does => 'Bar',
handles => { },
reader => 'foo',
builder => '_build_foo',
default => undef,
init_arg => 'foo',
lazy => 1,
);
};

note 'attribute_options_ok validation';
{
my ($_ok, $_nok, $_skip) = counters();
test_out $_ok->('TestClass has an attribute named foo');
test_out $_ok->('foo has a builder');
test_out $_ok->('foo option builder correct');
test_out $_ok->('foo does not have a default');
test_out $_ok->('foo option default correct');
test_out $_ok->('foo has a reader');
test_out $_ok->('foo option reader correct');
test_out $_skip->("cannot test 'isa' options yet");
test_out $_skip->("cannot test 'does' options yet");
test_out $_skip->("cannot test 'handles' options yet");
test_out $_skip->("cannot test 'traits' options yet");
test_out $_ok->('foo has a init_arg');
test_out $_ok->('foo option init_arg correct');
test_out $_ok->('foo is lazy');
attribute_options_ok TestClass => foo => (
traits => [ 'TestRole' ],
isa => 'Int',
does => 'Bar',
handles => { },
reader => 'foo',
builder => '_build_foo',
default => undef,
init_arg => 'foo',
lazy => 1,
);
test_test 'attribute_options_ok works as expected';
}

attribute_options_ok TestClass => foo => (
traits => [ 'TestRole' ],
isa => 'Int',
does => 'Bar',
handles => { },
reader => 'foo',
builder => '_build_foo',
default => undef,
init_arg => 'foo',
lazy => 1,
);
subtest 'a standalone run of attribute_options_ok' => sub {

# XXX "third" form, maybe
#validate_attribute TestClass => foo => (
#isa => [ 'Moose::Meta::Attribute' ],
#does => [ 'TestRole' ],
#options => {
#traits => [ 'TestRole' ],
#isa => 'Int',
#does => 'Bar',
#handles => { },
#reader => 'foo',
#builder => '_build_foo',
#default => undef,
#init_arg => 'foo',
#lazy => 1,
#},
#);
attribute_options_ok TestClass => foo => (
traits => [ 'TestRole' ],
isa => 'Int',
does => 'Bar',
handles => { },
reader => 'foo',
builder => '_build_foo',
default => undef,
init_arg => 'foo',
lazy => 1,
);
};

done_testing;

0 comments on commit cea582d

Please sign in to comment.