Sam Crawley > Test-MockObject-Extra > Test::MockObject::Extra

Download:
Test-MockObject-Extra-0.001.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Test::MockObject::Extra - A little bit Extra on top of Test::MockObject

SYNOPSIS ^

    # 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;

DESCRIPTION ^

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.

METHODS ^

fake_module(module name), [ subname = coderef, ... ]

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.

AUTHOR ^

Sam Crawley (Mutant) - mutant dot nz at gmail dot com

LICENSE ^

You may distribute this code under the same terms as Perl itself.

syntax highlighting: