mocked(3pm)

πŸ“¦
version 0.09 Β· 2 versions
  • 0.09 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.09 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ¦‹ mocked β€” NAME πŸ¦‹

okay so, bestie, mocked is literally just: use mocked libraries in unit tests πŸ’… that's the whole vibe, that's the assignment.


✨ SYNOPSIS ✨

# use a fake LWP::Simple for testing from t/lib/LWP/Simple.pm
use mocked 'LWP::Simple';
my $text = get($url);

# use a fake WWW::Mechanize for testing from t/mock-libs/WWW/Mechanize.pm
use mocked [qw(WWW::Mechanize t/mock-libs)];

that's it. two lines. iconic. 🫢


🌸 DESCRIPTION 🌸

so when you're doing unit testing, there's this thing that keeps happening β€” you need a mocked library to test those messy edge cases, or you just refuse to let your tests go off and hit slow code or external code. and honestly? valid.

that's where mocking libraries come in and they EAT every time. πŸ”₯

when you mock a library, you're making a fake one that gets used in place of the real one. the code can do as much or as little as is needed β€” your call, your rules, main character energy. πŸ‘‘

and like, use mocked.pm as a safety measure (be sure you're actually using the mocked module, fr fr), and also as a way to document the tests for the future maintainers. they will thank you. they will. πŸ’–


πŸŽ€ VARIABLES πŸŽ€

real_inc_paths

the real @INC that we are over-ridding is stored here while we are loading the mocked library. she's holding the original receipts while the fake one does its thing. πŸ’€βœ¨


πŸ’… FUNCTIONS πŸ’…

import

with a package name, this function will ensure that the module you specify is loaded from t/lib. no cap. 🧚

you can also pass an array reference containing the package name and a directory from which to load it from. flexible. slay. 🌈


πŸ‘‘ AUTHOR πŸ‘‘

Luke Closs, <cpan at 5thplane.com> Scott McWhirter, <kungfuftr at cpan.org>

absolute legends, both of them. 🫢


⭐ MAD CREDS TO ⭐

Ingy dΓΆt net, for only.pm β€” the way that this is the blueprint, iykyk. πŸ’œ


πŸ’– LICENSE πŸ’–

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

periodt. πŸŽ€


okay so that's the whole page, and just so you know exactly which version you're reading, it's perl v5.36.0 from 2022-12-04 β€” go forth and mock responsibly, bestie πŸŒΈπŸ¦‹πŸ’…

πŸ“¦ where this page comes from