in reply to Mocking Classes and Test::Class
Tricky. A couple ideas (untested):
1. Delete $INC{$filename} (where $filename is the conversion of a bare module name to a filename) and then re-require the module to re-load it. (You may need to silence redefine warnings.) See require for details.
2. Require the real module and mock an empty subclass instead. (Though you might wind up with un-mocked behavior if you call a non-mocked, inherited method.
sub setup : Test(setup) { my ($self) = @_; my $mockClass = Test::MockClass->new('Mock::DateTime'); $mockClass->addMethod('now', sub {'XXXX'}); require DateTime; @Mock::DateTime::ISA = qw( DateTime ); } sub test : Test { my ($self) = @_; ok(Mock::DateTime->now); diag(Mock::DateTime->now); }
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|