> If I comment out the fake_new line I can see that there is no faking at all.

Sure there is; pass an object to the T::MO::E constructor. The object you get back is your mock object. Any methods you add to that object are mock objects for that specific method. Thus you need to use that object (the T::MO::E instance), not a new object.

Okay the scenario I have is that module X uses module FileHandle, in such a way that a single function X::f creates a FileHandle and writes to it all within one function. So I want one test script where FileHandle::open always fails, and one test script where FileHandle::open behaves normally but FileHandle::print always misbehaves. As far as I know I managed to get this working in the style I described above. How is one supposed to do that. If you are interested, you can see what I actually did in the latest version of Test::Regression.

Maybe what I really need to do is write a Test::FileHandle module. As far as I can see all FileHandle does is import various functions. So presumably Test::FileHandle would import mocked functions into the FileHandle name space. I am not sure I fully understand how one would go about this. Would be nice if this worked for glob style classes in general and even better if the print syntax worked naturally.


In reply to Re^4: Test::MockObject::Extends and FileHandle by SilasTheMonk
in thread Test::MockObject::Extends and FileHandle by SilasTheMonk

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.