background image
<< Isolate The Untestable Part | Forcing Failure >>
<< Isolate The Untestable Part | Forcing Failure >>
Replace The Untestable Part
Then, Replace The Untestable Part
{
my @snooze_args = ();
my $snooze_called = 0;
local *Power::Manager::snooze = sub {
$snooze_called++;
@snooze_args = @_; # trap the arguments
return 0; # simulate successful system call
};
should_i_sleep($Min_Power - 1);
is( $snooze_called, 1, 'snooze called once' );
is( @snooze_args, 0, ' called properly' );
}
Check that it was called.
Check that it got the right arguments
By changing the return value to non-zero we can simulate a
failure.
Very, very powerful technique.