Lessons in Spec'ing
October 26th, 2007
Lesson: system calls in specs do stuff on your system. Be careful.
<p>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:</p>
system(%Q|rm "#{dir}/#{filename}"|)
Imagine my horror when I saw this in the output:
rm: /: is a directory


October 26th, 2007 at 9:30 am
That is so especially scary in a oh-god-it-could-happen-to-me kind of way…
October 26th, 2007 at 9:30 am
Somebody even shipped it with File::Remove (perl): http://use.perl.org/~Alias/journal/34680
October 26th, 2007 at 9:30 am
I came across this the other day, although not tried it yet: http://rubyforge.org/projects/mockfs/
October 26th, 2007 at 9:30 am
Luckily you weren’t at the school of hard knocks that day
October 26th, 2007 at 9:30 am
at least it wasn’t..
October 26th, 2007 at 9:30 am
I dont understand why that does not work