tokuhirom's Blog

Test::Stub - yet another stubbing library for Perl5

https://metacpan.org/module/Test::Stub
https://github.com/tokuhirom/Test-Stub/

I seen a Test::Double module. It's cool. But it have too much dependencies for me.
I need more simpler version of it.

Test::Stub doesn't have any dependencies.

Interface of these two modules are mostly same.

    use Test::Stub;

    my $agent = LWP::UserAgent->new();
    stub($agent)->get(HTTP::Response->new(200, "OK"));
    is($agent->get('http://www.aiseikai.or.jp/')->code, 200);

Enjoy!

【One more thing】
If you don't want to use DSL-ish interface, use straightforward function instead.

    use Test::Stub qw/make_stub/;

    my $agent = LWP::UserAgent->new();
    make_stub($agent, 'get', HTTP::Response->new(200, "OK"));
    is($agent->get('http://www.aiseikai.or.jp/')->code, 200);