Test::Resub is a lexically scoped subroutine replacement for testing.
SYNOPSIS
#!/usr/bin/perl
use Test::More tests => 4;
use Test::Resub qw(resub);
{
package Somewhere;
sub show {
my ($class, $message) = @_;
return "$class, $message";
}
}
# sanity
is( Somewhere->show('beyond the sea'), 'Somewhere, beyond the sea' );
# scoped replacement of subroutine with argument capturing
{
my $rs = resub 'Somewhere::show', sub { 'hi' }, capture => 1;
is( Somewhere->show('over the rainbow'), 'hi' );
is_deeply( $rs->method_args, [['over the rainbow']] );
}
# scope ends, resub goes away, original code returns
is( Somewhere->show('waiting for me'), 'Somewhere, waiting for me' );
This module allows you to temporarily replace a subroutine/method with arbitrary code. Later, you can tell how many times was it called and with what arguments each time. You can also specify that the subroutine/method must get called, must not get called, or may be optionally called.
Product's homepage
Requirements:
· Perl