On Wed, Jun 18, 2008 at 06:53:30AM -0400, David Golden wrote:
> My "standard" approach is to have a test setup routine that (a)
> creates a temp directory and (b) mocks File::HomeDir to make sure that
> all it's methods return the temp directory. The only real "trick" is
> making sure that $INC{File/Homedir.pm} gets set before anything might
> possibly load File::HomeDir.
>
> I should probably just wrap it up into a Test::MockHomeDir module.
I wouldn't bother, cos there's so much stuff out there that will look
directly at ~ or $ENV{HOME}, or read /etc/passwd by hand, or ...
FWIW, instead of mocking File::HomeDir, my approach would be to wrap all
uses of it in a tiny function:
sub _gethomedir { return File::HomeDir->my_home(); }
and then when testing my module that uses it, do this in the test suite:
use File::Temp;
my $fakehome = File::Temp->newdir();
*Module::_gethomedir = sub { return $fakehome };
--
David Cantrell | Enforcer, South London Linguistic Massive
engineer: n. one who, regardless of how much effort he puts in
to a job, will never satisfy either the suits or the scientists