Test::Mock::LWP::Conditional - stubbing on LWP request
use LWP::UserAgent; use HTTP::Response; use Test::More use Test::Mock::LWP::Conditional; my $uri = 'http://example.com/'; # global Test::Mock::LWP::Conditional->stub_request($uri => HTTP::Response->new(503)); is LWP::UserAgent->new->get($uri)->code => 503; # lexical my $ua = LWP::UserAgent->new; $ua->stub_request($uri => sub { HTTP::Response->new(500) }); is $ua->get($uri)->code => 500; is LWP::UserAgent->new->get($uri)->code => 503; # reset Test::Mock::LWP::Conditional->reset_all; is $ua->get($uri)->code => 200; is LWP::UserAgent->new->get($uri)->code => 200;
This module stubs out LWP::UserAgent's request.
stub_request($uri, $res)
Sets stub response for requesed URI.
reset_all
Clear all stub requests.
NAKAGAWA Masaki <masaki@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Test::Mock::LWP, Test::Mock::LWP::Dispatch, Test::MockHTTP, Test::LWP::MockSocket::http
LWP::UserAgent
https://github.com/bblimke/webmock, https://github.com/chrisk/fakeweb
To install Test::Mock::LWP::Conditional, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Mock::LWP::Conditional
CPAN shell
perl -MCPAN -e shell install Test::Mock::LWP::Conditional
For more information on module installation, please visit the detailed CPAN module installation guide.