NAME

Test::Mock::Guard - Simple mock test library using RAII.

SYNOPSIS

use Test::More;
use Test::Mock::Guard qw(mock_guard);

package Some::Class;

sub new { bless {} => shift }
sub foo { "foo" }
sub bar { 1; }

package main;

{
    my $guard = mock_guard( 'Some::Class', +{ foo => sub { "bar" }, bar => 10 } );
    my $obj = Some::Class->new;
    is( $obj->foo, "bar" );
    is( $obj->bar, 10 );
}

my $obj = Some::Class->new;
is( $obj->foo, "foo" );
is( $obj->bar, 1 );

done_testing;

DESCRIPTION

Test::Mock::Guard is mock test library using RAII.

EXPORT FUNCTION

mock_guard( %class_defs )

%class_defs are following format.

key

Specify class name as mock

value

Hash reference. It's key as method name, It's value is code reference or value. If the value is code reference, then call code reference and return the result. If the value is value, then return the value directly.

METHODS

new( %class_defs )

See "mock_guard" definition.

DESTROY

Internal use only.

AUTHOR

Toru Yamaguchi <zigorou@cpan.org>

SEE ALSO

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.