perl-Test-MockPackages-1.01-alt1.noarch.rpm


Advertisement

Description

perl-Test-MockPackages - Mock external dependencies in tests

Property Value
Distribution ALT Linux Sisyphus
Repository Autoimports noarch
Package name perl-Test-MockPackages
Package version 1.01
Package release alt1
Package architecture noarch
Package type rpm
Installed size 31.68 KB
Download size 31.68 KB
Official Mirror ftp.altlinux.org
Test::MockPackages is a package for mocking other packages as well as ensuring those packages are being used correctly.
Say we have a Weather class that can return the current degrees in Fahrenheit. In order to do this it uses another class, Weather::Fetcher which
makes an external call. When we want to write a unit test for Weather, we want to mock the functionality of Weather::Fetcher.
Here is the sample code for our Weather class:
package Weather;
use Moose;
use Weather::Fetcher;
sub degrees_f {
my ( $self, $zip_code ) = @_;
my $data = eval { Weather::Fetcher::fetch_weather( $zip_code ) };
if ( !$data ) {
return;
}
return $data->{temp_f} . "-OF";
}
And here's how we may choose to test this class. In the `success' subtest, we use the mock() helper subroutine, and in the `failure' method we use the OOP approach. Both provide identical functionality.
use Test::More;
use Test::MockPackages qw(mock);
subtest 'degrees_f' => sub {
subtest 'success' => sub {
my $m = mock({
'Weather::Fetcher' => {
fetch_weather => [
expects => [ '14202' ],
returns => [ { temp_f => 80 } ],
],
},
});
isa_ok( my $weather = Weather->new, 'Weather' );
is( $weather->degrees_f( 14202 ), '80-OF', 'correct temperature returned' );
};
subtest 'failure' => sub {
my $m = Test::MockPackages->new();
$m->pkg( 'Weather::Fetcher' )
->mock( 'fetch_weather' )
->expects( '14202' )
->returns();
my $weather = Weather->new;
is( $weather->degrees_f( 14202 ), undef, 'no temperature returned' );
};
};
done_testing();
When we run our tests, you can see that Test::MockPackages validates the following for us: 1. the subroutine is called with the correct arguments, 2. the subroutine was called the correct number of times. Lastly, Test::MockPackages allows us to have this mocked subr...

Alternatives

Package Version Architecture Repository
perl-Test-MockPackages - - -

Requires

Name Value
/usr/share/perl5 -
perl(Const/Fast.pm) -
perl(English.pm) -
perl(Lingua/EN/Inflect.pm) -
perl(List/Util.pm) -
perl(Scalar/Util.pm) -
perl(Storable.pm) -
perl(Sub/Metadata.pm) -
perl(Test/Builder/Module.pm) -
perl(Test/Deep.pm) -
perl(Test/More.pm) -
perl(parent.pm) -
perl(utf8.pm) -
perl-base >= 1:5.10.0
rpmlib(PayloadIsLzma) -

Provides

Name Value
perl(Test/MockPackages.pm) = 1.010
perl(Test/MockPackages/Mock.pm) = 1.0
perl(Test/MockPackages/Package.pm) = 1.0
perl(Test/MockPackages/Returns.pm) = 1.0
perl-Test-MockPackages = 1.01-alt1

Download

Type URL
Binary Package perl-Test-MockPackages-1.01-alt1.noarch.rpm
Source Package perl-Test-MockPackages-1.01-alt1.src.rpm

Install Howto

  1. Add the following line to /etc/apt/sources.list:
    
    rpm [Sisyphus] http://ftp.altlinux.org/pub/distributions/ALTLinux/autoimports/Sisyphus noarch autoimports
    rpm [Sisyphus] http://ftp.altlinux.org/pub/distributions/ALTLinux/autoimports/Sisyphus noarch autoimports
    
  2. Update the package index:
    # sudo apt-get update
  3. Install perl-Test-MockPackages rpm package:
    # sudo apt-get install perl-Test-MockPackages

Files

Path
/usr/share/doc/perl-Test-MockPackages-1.01/Changes
/usr/share/doc/perl-Test-MockPackages-1.01/README
/usr/share/doc/perl-Test-MockPackages-1.01/ignore.txt
/usr/share/perl5/Test/MockPackages.pm
/usr/share/perl5/Test/MockPackages/Mock.pm
/usr/share/perl5/Test/MockPackages/Package.pm
/usr/share/perl5/Test/MockPackages/Returns.pm

See Also

Package Description
perl-Test-MockRandom-1.01-alt2_5.noarch.rpm Override randoms with non-random behavior
perl-Test-MockSleep-0.02-alt1.noarch.rpm Pretend to sleep!
perl-Test-MockTime-DateCalc-6-alt1.noarch.rpm Fake date/time for Date::Calc functions
perl-Test-MockTime-HiRes-0.08-alt1.noarch.rpm Replaces actual time with simulated high resolution time
perl-Test-Mockify-2.4-alt1.noarch.rpm minimal mocking framework for perl
perl-Test-Modern-0.013-alt1.noarch.rpm precision testing for modern perl
perl-Test-Module-CheckDep-Version-0.03-alt1.noarch.rpm Unusable distribution to test Module::CheckDep::Version
perl-Test-Module-Runnable-0.3.0-alt1.noarch.rpm Base class for runnable unit tests using Moose introspection
perl-Test-Module-Used-0.2.6-alt1_11.noarch.rpm Test required module is really used and vice versa between lib/t and META.yml
perl-Test-ModuleReady-0.0.6-alt1.noarch.rpm Simple module for checking that a module is ready for submission
perl-Test-ModuleVersion-0.17-alt1.noarch.rpm Module version test generator
perl-Test-Mojo-More-0.061-alt1.noarch.rpm Test::Mojo and more
perl-Test-Mojo-Most-0.08-alt1.noarch.rpm Combine various L<Test::Mojo> modules into one, a bit like L<Test::Most> but for Mojo
perl-Test-Mojo-Pg-0.33-alt1.noarch.rpm Tear down and bring up databases with Mojo::Pg
perl-Test-Mojo-Plack-0.10-alt1.noarch.rpm Test Plack-compatible applications with Test:Mojo
Advertisement
Advertisement