Testing deleting files

In unit or functional test, is there a way to check that a file has been
deleted?
It seems that running the test does not really execute deleting files,
which
is good because I don’t want it to actually delete the files. But can I
check that the deletion should have been performed in test environment?

thanks,

  • reynard

Correction, running the test actually deletes the file :frowning:
I think we want it to not delete the file but be able to check if the
deletion has been performed, right? maybe I’ll try creating mock object
for
the File class.
I’m sure someone else has encountered this need too. any suggestion?

thanks

  • reynard

On 15/08/06, Reynard H. [email protected] wrote:

Correction, running the test actually deletes the file :frowning:
I think we want it to not delete the file but be able to check if the deletion has been performed, right? maybe I’ll try creating mock object for the File class.
I’m sure someone else has encountered this need too. any suggestion?

You could use the Stubba component of Mocha
(http://mocha.rubyforge.org) to do something like the following…

def test_should_delete_file
File.expects(:delete).with(‘filename’).returns(1)
object = MyClass.new
object.method_which_deletes_file
File.verify
end

This test should pass as long as the expected call to the File.delete
method is made with the expected parameters. It will not actually
delete the file.

Make sense?

James.

Thanks James, that’s exactly what I need.

  • reynard

You could use the Stubba component of Mocha