X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F200_examples%2F001_example.t;h=5984cc9b446e6c3907cedd2ca4129d7f530be996;hb=a28e50e44945358d15eb19e4688573741a319fe0;hp=3488cf03d1108c61dba4a04d74f18325de3917da;hpb=d443cad0cbcc03efe89556a96ff231822b59125d;p=gitmo%2FMoose.git diff --git a/t/200_examples/001_example.t b/t/200_examples/001_example.t index 3488cf0..5984cc9 100644 --- a/t/200_examples/001_example.t +++ b/t/200_examples/001_example.t @@ -3,10 +3,8 @@ use strict; use warnings; -use Test::More tests => 22; +use Test::More; use Test::Exception; -use Test::Output; - ## Roles @@ -21,16 +19,16 @@ use Test::Output; my $c = shift; my ($self, $field) = @_; return undef if $c->($self, $self->validation_value($field)); - return $self->error_message; + return $self->error_message; }; - + sub validation_value { my ($self, $field) = @_; return $field; } - + sub error_message { confess "Abstract method!" } - + package Constraint::OnLength; use Moose::Role; @@ -43,19 +41,17 @@ use Test::Output; override 'error_message' => sub { my $self = shift; return super() . ' ' . $self->units; - }; + }; } -## Classes +## Classes { package Constraint::AtLeast; use Moose; - ::stderr_is { - with 'Constraint' => { excludes => 'error_message' }; - } ""; + with 'Constraint'; sub validate { my ($self, $field) = @_; @@ -67,9 +63,7 @@ use Test::Output; package Constraint::NoMoreThan; use Moose; - ::stderr_is { - with 'Constraint' => { excludes => 'error_message' }; - } ''; + with 'Constraint'; sub validate { my ($self, $field) = @_; @@ -83,12 +77,12 @@ use Test::Output; extends 'Constraint::NoMoreThan'; with 'Constraint::OnLength'; - + package Constraint::LengthAtLeast; use Moose; - + extends 'Constraint::AtLeast'; - with 'Constraint::OnLength'; + with 'Constraint::OnLength'; } my $no_more_than_10 = Constraint::NoMoreThan->new(value => 10); @@ -117,8 +111,8 @@ ok($no_more_than_10_chars->does('Constraint'), '... Constraint::LengthNoMoreThan ok($no_more_than_10_chars->does('Constraint::OnLength'), '... Constraint::LengthNoMoreThan does Constraint::OnLength'); ok(!defined($no_more_than_10_chars->validate('foo')), '... validated correctly'); -is($no_more_than_10_chars->validate('foooooooooo'), - 'must be no more than 10 chars', +is($no_more_than_10_chars->validate('foooooooooo'), + 'must be no more than 10 chars', '... validation failed correctly'); my $at_least_10_chars = Constraint::LengthAtLeast->new(value => 10, units => 'chars'); @@ -131,3 +125,4 @@ ok($at_least_10_chars->does('Constraint::OnLength'), '... Constraint::LengthAtLe ok(!defined($at_least_10_chars->validate('barrrrrrrrr')), '... validated correctly'); is($at_least_10_chars->validate('bar'), 'must be at least 10 chars', '... validation failed correctly'); +done_testing;