Aion-Surf
view release on metacpan or search on metacpan
t/aion/surf.t view on Meta::CPAN
use common::sense; use open qw/:std :utf8/; use Test::More 0.98; sub _mkpath_ { my ($p) = @_; length($`) && !-e $`? mkdir($`, 0755) || die "mkdir $`: $!": () while $p =~ m!/!g; $p } BEGIN { use Scalar::Util qw//; use Carp qw//; $SIG{__DIE__} = sub { ...
#
# Aion::Surf - surfing by internet
#
# # VERSION
#
# 0.0.3
#
# # SYNOPSIS
#
subtest 'SYNOPSIS' => sub {
use Aion::Surf;
use common::sense;
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
$response
};
::is scalar do {get "http://example/ex"}, "get", 'get "http://example/ex" # => get';
::is scalar do {surf "http://example/ex"}, "get", 'surf "http://example/ex" # => get';
::is scalar do {head "http://example/ex"}, scalar do{1}, 'head "http://example/ex" # -> 1';
::is scalar do {head "http://example/not-found"}, scalar do{""}, 'head "http://example/not-found" # -> ""';
::is scalar do {surf HEAD => "http://example/ex"}, scalar do{1}, 'surf HEAD => "http://example/ex" # -> 1';
::is scalar do {surf HEAD => "http://example/not-found"}, scalar do{""}, 'surf HEAD => "http://example/not-found" # -> ""';
::is_deeply scalar do {[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/]}, scalar do {[qw/get 1 post put patch delete/]}, '[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put ...
::is_deeply scalar do {patch "http://example/json"}, scalar do {{a => 10}}, 'patch "http://example/json" # --> {a => 10}';
::is_deeply scalar do {[map patch, qw! http://example/ex http://example/json !]}, scalar do {["patch", {a => 10}]}, '[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]';
::is scalar do {get ["http://example/ex", headers => {Accept => "*/*"}]}, "get", 'get ["http://example/ex", headers => {Accept => "*/*"}] # => get';
::is scalar do {surf "http://example/ex", headers => [Accept => "*/*"]}, "get", 'surf "http://example/ex", headers => [Accept => "*/*"] # => get';
#
# # DESCRIPTION
#
# Aion::Surf contains a minimal set of functions for surfing the Internet. The purpose of the module is to make surfing as easy as possible, without specifying many additional settings.
#
# # SUBROUTINES
( run in 0.661 second using v1.01-cache-2.11-cpan-5b529ec07f3 )