Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Test::MockObject::Extends and FileHandle

by chromatic (Archbishop)
on Jan 23, 2010 at 18:54 UTC ( [id://819222]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Test::MockObject::Extends and FileHandle
in thread Test::MockObject::Extends and FileHandle

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.

  • Comment on Re^3: Test::MockObject::Extends and FileHandle

Replies are listed 'Best First'.
Re^4: Test::MockObject::Extends and FileHandle
by SilasTheMonk (Chaplain) on Jan 23, 2010 at 19:30 UTC

    > 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://819222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-20 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found