I sometimes find that testing validation methods is annoying. They might look
something like this hideously contrived example:
sub _validate {
my $self =shift;
if ( $self->is_broken ) { throw_some_exception "we're broken" }
if ( $self->username ) { throw_another_exception "we gots a bucket, er,
user" }
if ( $self->is_inflatable ) { throw_up "a.k.a., 'unswallowing'" }
}
And then, in my tests, I'll have something like:
my $some_class = Test::MockModule->new($class);
$some_class->mock( is_broken => 1 );
# is_broken tests
$some_class->unmock('is_broken');
$some_class->mock( username => 'twinkletoes');
# twinkletoes tests
$some_class->unmock('is_broken');
$some_class->mock( is_inflatable => 1 );
# inflatable tests
$some_class->unmock('is_inflatable');
It would be nice to do something like:
$some_class->sequential_mock(
is_broken => 1,
username => 'twinkletoes',
is_inflatable => 1
);
# is_broken tests
# twinkletoes tests
# inflatable tests
That does pull the tests a bit further away from the mocking, which could
confuse some, but it would be much nicer to write!
The code for this shouldn't be too hard, but I'm wondering if anyone thinks
this is a stupid idea, or if something like this belongs directly in
Test::MockModule?
Cheers,
Ovid
--
Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/