Herkum has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to write some testing code to mock Apache::Constants which is exporting some methods to the script. I know how to Mock a OO module, but not a module that is exporting just methods. This is the code I am mocking,
use Apache::Constants qw(OK DECLINED AUTH_REQUIRED); my $status = some_method(); return $status if ($status != OK);
I have tried this but this is not working so is probalbly just wrong.
$INC{Apache/Constants.pm} = 1; my $constants = Test::MockObject->new(); $constants->fake_module('Apache::Constants'); $constants->mock('OK', sub { return 1 } ); warn "OK is " . OK . "\n";
gives me "Undefined subroutine &Apache::Constants::OK called"
The reason I tried Test::MockObject is that the Apache::Constants is being used in the module that I am testing so I need to be able to export this mock object to that other module.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mocking Apache::Constants
by stvn (Monsignor) on May 25, 2006 at 20:18 UTC | |
by Herkum (Parson) on May 26, 2006 at 16:18 UTC | |
|
Re: Mocking Apache::Constants
by ForgotPasswordAgain (Vicar) on May 26, 2006 at 16:00 UTC |