Astro-SpaceTrack
view release on metacpan or search on metacpan
inc/My/Module/Test.pm view on Meta::CPAN
}
sub throws_exception { ## no critic (RequireArgUnpacking)
my ( $obj, $method, @args ) = @_;
my $name = pop @args;
my $exception = pop @args;
REGEXP_REF eq ref $exception
or $exception = qr{\A$exception};
$rslt = eval { $obj->$method( @args ) }
and do {
@_ = ( "$name throw no exception. Status: " .
$rslt->status_line() );
goto &fail;
};
@_ = ( $@, $exception, $name );
goto &like;
}
1;
__END__
=head1 NAME
My::Module::Test - Test routines for Astro::SpaceTrack
=head1 SYNOPSIS
use Astro::SpaceTrack;
use lib qw{ inc };
use My::Module::Test;
my $st = Astro::SpaceTrack->new();
is_success $st, fubar => 42,
'fubar( 42 ) succeeds';
my $resp = most_recent_http_response;
is $resp->content(), 'XLII',
q<fubar( 42 ) returned 'XLII'>;
=head1 DESCRIPTION
This Perl module contains testing routines for Astro::SpaceTrack. Some
of them actually perform tests, others perform whatever miscellany of
functions seemed appropriate.
Everything in this module is B<private> to the C<Astro::SpaceTrack>
package. The author reserves the right to change or revoke anything here
without notice.
=head1 SUBROUTINES
This package exports the following subroutines, all by default.
=head2 is_error
is_error $st, fubar => 42,
404,
'Make sure $st->fubar( 42 ) returns a 404';
This subroutine executes the given method and tests its result code for
numeric equality to the given code. The method is assumed to return an
HTTP::Response object. The arguments are:
- The method's invocant
- The method's name
- Zero or more arguments
- The expected HTTP status code
- The test name
=head2 is_error_or_skip
is_error $st, fubar => 42,
404,
'Make sure $st->fubar( 42 ) returns a 404';
This subroutine is like C<is_error(), but if the returned status is 500,
the test is skipped.
=head2 is_not_success
is_not_success $st, fubar => 42,
'Make sure $st->fubar( 42 ) fails';
This subroutine executes the given method and tests its result for
failure. The method is assumed to return an HTTP::Response object. The
arguments are:
- The method's invocant
- The method's name
- Zero or more arguments
- The test name
=head2 is_success
is_success $st, fubar => 42,
'Make sure $st->fubar( 42 ) succeeds';
This subroutine executes the given method and tests its result for
success. The method is assumed to return an HTTP::Response object. The
arguments are:
- The method's invocant
- The method's name
- Zero or more arguments
- The test name
=head2 is_success_or_skop
is_success_or_skip $st, fubar => 42,
'Make sure $st->fubar( 42 ) succeeds', 3;
This subroutine is like C<is_success>, but if a problem occurs the
number of tests given by the last argument is skipped. The skip argument
assumes that the current test is B<not> skipped. If a 500 error is
encountered, the current test B<is> skipped, and the number of tests
skipped is the skip argument plus 1.
=head2 last_modified
This subroutine returns the value of the C<Last-Modified> header from
the most recent HTTP::Respose object, as a Perl time. If there is no
HTTP::Response, or if it did not contain that header, C<undef> is
returned.
=head2 most_recent_http_response
my $resp = most_recent_http_response;
$resp->is_success()
or diag $resp->status_line();
This subroutine returns the HTTP::Response object from the most-recent
test that actually generated one.
=head2 not_defined
( run in 0.867 second using v1.01-cache-2.11-cpan-39bf76dae61 )