Skip to content

Instantly share code, notes, and snippets.

@ayumu83s
Created February 19, 2014 04:40
Show Gist options
  • Save ayumu83s/9086150 to your computer and use it in GitHub Desktop.
Save ayumu83s/9086150 to your computer and use it in GitHub Desktop.
Test::Stubを使ってみる
use warnings;
use utf8;
use Test::More;
use Test::Stub;
subtest 'Test::Stub' => sub {
my $agent = LWP::UserAgent->new();
stub($agent)->get(
my ($self, $path) = @_;
if ($path =~ /google\.co\.jp\z/) {
HTTP::Response->new(200,"OK");
} else {
HTTP::Response->new(500,"Internal Server Error");
}
);
is($agent->get("http://www.google.co.jp")->code, 200);
is($agent->get("http://www.yahoo.co.jp")->code, 500);
};
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment