Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I did not like the idea of putting files for these tests on a user's filesystem.

Think of it this way; it's difficult to anticipate all of the ways user filesystems might differ from your expectations. One might be encrypted. Another might be case-insensitive. A third might be on a slow network mount.

By testing as much of that system as possible—by not mocking things—your tests are richer and better represent the conditions you want to validate.

Using File::Temp avoids at least two difficult problems. First, it reduces your need to clean up after yourself by handling it for you. Hopefully that eases your mind about writing to user filesystems. Second, it makes your tests less serial; you can run them in parallel because there's very little chance multiple tests or multiple runs will collide because they all depend on the state of one specific file with a hard-coded name and path.

If you wrap your temporary file generation in a function, it could be even cleaner. The third time you write to a temporary file, I'd do that; you'll reduce duplication and further reduce coupling on the generated name of the temporary file.


In reply to Re^3: Can Test::MockObject mock a file? by chromatic
in thread Can Test::MockObject mock a file? by Lady_Aleena

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2021-10-25 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?