The code below is syntactically correct but does not do what you may think at first glance:
It is an excerpt from a spec file and it is supposed to mean:
- silently delete this database file even if it does not exist
- create the database management class (and the underlying file)
Here’s what I should have written:
Notice the nil at the end of the rescue clause ?
Would you have guessed that in the first case, the last line of the block is executed only if an exception is raised by File.delete ? From a statement modifier, I expected a “one-line” parsing logic.
In this particular case, this had the nasty effect of making my test pass and fail every other time it was running since the last line creates the file mentioned in the delete call. Although I do not like the rescue nil trick in general, I thought it was quite handy in the context of this spec code, I paid for my carelessness…