I want to write a SUnit test which uses a file with the Pharo 4.0 FileSystem. I want to write a file and then later read it.
Something like this
fname := 'TabularTestExport1.xlsx'.
(FileLocator temp / fname ) delete.
TabularXSLXExport workbook: myWorkbook fileName: (FileLocator temp / fname ).
temp directory What is the method to use for using a temporary file in a platform independant way. FileLocator temp
or FileLocator tempDirectory
is not implemented.
deleting an existing test file How do I ensure that a file is deleted? I.e. How do I avoid a walkback in case the file does not exist.
Alternatively everything could be done in the memory: 1. creation of test file, 2. exporting test file, 3. Importing test file back
For tests, unless you have a real big archive, is better to do things in memory. FileSystem provides you a way to do it, you just need to do:
fs := FileSystem memory.
It will give you a compatible API so you can make your tests. If you want a file and not a directory, you can do:
file := FileSystem memory / 'myFile'.
EDIT: I forget a couple of things:
FileLocator temp
is implemented and should work fine for you. Why you say is not implemented? Are you not finding it for some reason, maybe?myFileReference ensureDelete
will... well, ensure your file is deleted :)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With