chromatic wrote: > On Thursday 05 October 2006 12:25, Christopher H. Laco wrote: > >> I'm having a idiot moment... >> >> I'm trying to mock out some config reading tests for reading from >> MP1/MP2 even though I don't have either installed. so I thought >> "Test::MockObjext is the answer!". >> >> The following code goes boom with a 'Can't locate object method request >> >> via package "Apache"': >>> use strict; >>> use warnings; >>> use Test::MockObject; >>> >>> my $mock = Test::MockObject->new; >>> $mock->fake_module('Apache'); >>> $mock->set_series(undef, $mockrequest); >>> >>> warn Apache->request; >> If I change the fake_module call to >> Test::MockObject->fake_module('Apache'), the code gets happt, but it >> appears I can then install subs into that Apache using any of the set_ >> helpers. >> >> Or am I just missing something? >> >> The pod mentions that fake_module is a class and object method, but >> doesn't really extol the virtues on when to use one over the other. > >> Someone cluestick me please. > > Test::MockObject primarily returns you an object on which you can mock and > call mocked methods. fake_module() lets you install new methods into the > mocked class by passing name and subref pairs, but that's really not the > point of the module. > > -- c > >
I won't pretend not be be confused at the moment then, because I have other tests that do: T::MO->new->fake_module('Foo'), and classes that 'use Foo' and do 'Foo->new' just work with the mocked verson. At least, I thought they did, and they don't throw the same error. So, all of that aside, what is everyone else using in this type of scenario of mocking classes used by all rather than passing mocked object around? Test::MockModule/MockClass looks like it will do. -=Chris
signature.asc
Description: OpenPGP digital signature