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.


In reply to Automocked objects by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.