Test::MockObject::Extra - A little bit Extra on top of Test::MockObject
# Create a mock my $mock = Test::MockObject::Extra->new(); # Fake out a module $mock->fake_module( 'Some::Module', som_sub => sub { ... }, ); # Do some testing.... ... # Remove the fake module $mock->unfake_module;
This module adds a bit of extra functionality I needed in Test::MockObject. It could probably be rolled into Test::MockObject if the author wants it.
Test::MockObject::Extra inherits from Test::MockObject. It overrides fake_module() and adds a new method unfake_module(). These are described below.
fake_module(module name), [ subname =
Works in the same way as Test::MockObject, except it emits a warning if called as a class method. This is because (in order for unfake_module() to work) it needs to record what subs have been faked, so they can be restored later.
unfake_module()
If you've called fake_module() (or fake_new()), you may need to 'unfake' it later, so the real class can load. This is especially true if you have a whole lot of tests running in one process (such as under Test::Class::Load).
Note, that after calling unfake_module(), you'll need to load the real version of the module in some way (this could probably be added as an option to this method at a later date). If you're loading the modules you're testing with use_ok(), you should be OK.
Also note it's possible to call fake_module() as a class method. If you do this, unfake_module() will die if you call it, since it needs to hold onto some state data in order to unfake the module.
Sam Crawley (Mutant) - mutant dot nz at gmail dot com
You may distribute this code under the same terms as Perl itself.
To install Test::MockObject::Extra, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::MockObject::Extra
CPAN shell
perl -MCPAN -e shell install Test::MockObject::Extra
For more information on module installation, please visit the detailed CPAN module installation guide.