[rspec-users] Mocking expectations on I/O operations

Ash Moran
2011-09-15T10:08:35Z

On 15 Sep 2011, at 10:05, Rob Aldred wrote:

> Thanks Justin,
> That isnt working... its erroring with:
>
> The method `delete` was not stubbed or was already unstubbed

Hi Rob

For reasons I could go into, when I''m coding myself I don''t
usually stub  out file system access or other third party systems. Rather, I
write an adapter that behaves in the way I expect and test it using the real
file system, then test the rest of the system against a mock. That avoids this
category of problem.

What you''re doing here appears to be mixing both real (from
mini_magick) and stubbed (your own library''s) calls to filesystem code,
and I think it''s the asymmetry that''s biting you.

I could explain the above in more detail*, but in lieu of that, here''s
another angle: can you run the code in a subdirectory per image and nuke that
after? That way you only have one point to hit for the cleanup.

HTH

Ash

* As a quick example, you might have a TempFileCleaner object in place of
IconGenerator#cleanup, seeded with all the potential temp filenames, or some
algorithm to figure them out

--