From 408eb5768ff65be867617e0e65d78d157f33a93d Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Fri, 18 Jul 2014 03:19:04 +1200 Subject: [PATCH] Add get method coverage --- Changes | 3 ++ misc/Changes.deps | 3 ++ misc/Changes.deps.all | 3 ++ t/get.t | 66 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 t/get.t diff --git a/Changes b/Changes index a0ca12d..d111cd1 100644 --- a/Changes +++ b/Changes @@ -3,11 +3,14 @@ Release history for HTTP-Tiny-Mech {{$NEXT}} [00 Major] - Recoded construction to work without Class::Tiny, as the logic is much more difficult since 1.000 + - Test Coverage increased to 100% + - Misc packaging cleanups [Dependencies::Stats] - Dependencies changed since 1.000000, see misc/*.deps* for details - develop: +3 -3 (suggests: +2 -1) - runtime: -1 + - test: +1 1.000000 2014-05-10T02:41:46Z [00 Minor] diff --git a/misc/Changes.deps b/misc/Changes.deps index e9283f9..6529acb 100644 --- a/misc/Changes.deps +++ b/misc/Changes.deps @@ -1,6 +1,9 @@ This file contains changes in REQUIRED dependencies for standard CPAN phases (configure/build/runtime/test) 1.000001 + [Added / test requires] + - HTTP::Response + [Removed / runtime requires] - Class::Tiny diff --git a/misc/Changes.deps.all b/misc/Changes.deps.all index 262cf75..3445311 100644 --- a/misc/Changes.deps.all +++ b/misc/Changes.deps.all @@ -10,6 +10,9 @@ This file contains ALL changes in dependencies in both REQUIRED / OPTIONAL depen - Dist::Zilla::App::Command::bakeini 0.001001 - Dist::Zilla::PluginBundle::Author::KENTNL 2.016004 + [Added / test requires] + - HTTP::Response + [Removed / develop requires] - Dist::Zilla::Plugin::Git::NextVersion::Sanitized - Dist::Zilla::Plugin::PkgVersion diff --git a/t/get.t b/t/get.t new file mode 100644 index 0000000..82ff379 --- /dev/null +++ b/t/get.t @@ -0,0 +1,66 @@ +use strict; +use warnings; + +use Test::More; + +# ABSTRACT: Test ->get with a dummy class + +use HTTP::Tiny::Mech; +use HTTP::Tiny 0.022; + +{ + + package FakeUA; + our $AUTOLOAD; + + sub AUTOLOAD { + my $program = $AUTOLOAD; + $program =~ s/.*:://; + + my ( $self, @args ) = @_; + push @{ $self->{calls} }, [ $program, @args ]; + require HTTP::Response; + return HTTP::Response->new(); + } + + sub new { + my ( $self, @args ) = @_; + bless { args => \@args, calls => [] }, $self; + } + +} + +my $instance = HTTP::Tiny::Mech->new( mechua => FakeUA->new(), ); +isa_ok( $instance, 'HTTP::Tiny' ); +isa_ok( $instance, 'HTTP::Tiny::Mech' ); +isa_ok( $instance->mechua, 'FakeUA' ); + +subtest "get url" => sub { + local $instance->mechua->{calls} = []; + my $result = $instance->get('http://www.example.org:80/'); + is( ref $result, 'HASH', "Got a hash back" ); + note explain $instance; +}; + +subtest "get url + opts" => sub { + local $instance->mechua->{calls} = []; + my $result = $instance->get( 'http://www.example.org:80/', { args => {} } ); + is( ref $result, 'HASH', "Got a hash back" ); + note explain $instance; +}; + +subtest "request url" => sub { + local $instance->mechua->{calls} = []; + my $result = $instance->request( 'HEAD', 'http://www.example.org:80/' ); + is( ref $result, 'HASH', "Got a hash back" ); + note explain $instance; +}; +subtest "request url + opts" => sub { + local $instance->mechua->{calls} = []; + my $result = $instance->request( 'POST', 'http://www.example.org:80/', { headers => {}, content => "CONTENT" } ); + is( ref $result, 'HASH', "Got a hash back" ); + note explain $instance; +}; + +done_testing; +