Ovid has asked for the wisdom of the Perl Monks concerning the following question:
So I have some code I'm testing which relies on a class with a whole bunch of niggling, annoying little methods getting called hither and yon. For the purposes of my tests, however, I really only care about one accessor at the end of the test and what it returns (since some methods are called in void context). I don't care to go through the trouble of mocking all of the other methods. I'm looking for (and can't find) a test version of Class::BlackHole. I'm thinking something like this:
use Test::Automock; my $mock = Test::Automock->('Some::Difficult::Module'); $mock->add( fetch_my_slippers => sub { 1 } ); # adds this method can_ok $object, 'stuff'; ok $object->stuff, '... and calling it should succeed'; my @expected = ( fribble => [ $mock, $object ], woobie => [ $mock ], ); is_deeply $mock->methods_called, \@expected, "... with Some::Difficult::Methods doing their thing"; $mock->reset;
Test::Automock would simply use autoload to capture all method calls and their arguments. Methods by default would return a true value unless specifically overridden. I'd have to do tricks like overriding isa() and friends, but that seems like it would be a very lightweight method of handling mocked objects.
Is there something which does this? Did I miss anything?
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Automocked objects
by jasonk (Parson) on Apr 17, 2007 at 12:00 UTC | |
|
Re: Automocked objects (chains)
by tye (Sage) on Apr 17, 2007 at 16:01 UTC |