Lessons in Spec'ing 6
Lesson: system calls in specs do stuff on your system. Be careful.
I was trying different things to understand why a spec was failing and, at one point, put a pending statement in a spec that generates a file and then deletes it. The statement that deletes the file is in an after(:each) block (which is guaranteed to run) and looks like this:
system(%Q|rm "#{dir}/#{filename}"|)
Imagine my horror when I saw this in the output:
rm: /: is a directory

That is so especially scary in a oh-god-it-could-happen-to-me kind of way…
Somebody even shipped it with File::Remove (perl): http://use.perl.org/~Alias/journal/34680
I came across this the other day, although not tried it yet: http://rubyforge.org/projects/mockfs/
I don’t like the way you have to modify your application code to use it, but it’s nice that one line of config stops real filesystem access.
Luckily you weren’t at the school of hard knocks that day ;-)
at least it wasn’t..
sudo rm -rdf /
;)
I dont understand why that does not work :(