Lessons in Spec'ing 6

Posted by David Fri, 26 Oct 2007 13:30:14 GMT

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
Comments

Leave a response

  1. Avatar
    rubyruy Fri, 26 Oct 2007 14:40:16 GMT

    That is so especially scary in a oh-god-it-could-happen-to-me kind of way…

  2. Avatar
    krotty.korobka.net Fri, 26 Oct 2007 16:48:17 GMT

    Somebody even shipped it with File::Remove (perl): http://use.perl.org/~Alias/journal/34680

  3. Avatar
    Ashley Moran Fri, 26 Oct 2007 17:19:21 GMT

    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.

  4. Avatar
    James Hill Sat, 27 Oct 2007 17:03:07 GMT

    Luckily you weren’t at the school of hard knocks that day ;-)

  5. Avatar
    Lance Carlson Tue, 30 Oct 2007 16:27:12 GMT

    at least it wasn’t..

    sudo rm -rdf /

    ;)

  6. Avatar
    Bob Tue, 30 Oct 2007 21:18:08 GMT

    I dont understand why that does not work :(

Comments