NAKAGAWA Masaki > Test-Mock-LWP-Conditional > Test::Mock::LWP::Conditional

Download:
Test-Mock-LWP-Conditional-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  

NAME ^

Test::Mock::LWP::Conditional - stubbing on LWP request

SYNOPSIS ^

    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;

DESCRIPTION ^

This module stubs out LWP::UserAgent's request.

METHODS ^

AUTHOR ^

NAKAGAWA Masaki <masaki@cpan.org>

LICENSE ^

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

SEE ALSO ^

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

syntax highlighting: