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

6 Responses to “Lessons in Spec'ing”

  1. rubyruy Says:

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

  2. krotty.korobka.net Says:

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

  3. Ashley Moran Says:

    I came across this the other day, although not tried it yet: http://rubyforge.org/projects/mockfs/

    <p>I don&#8217;t like the way you have to modify your application code to use it, but it&#8217;s nice that one line of config stops real filesystem access.</p>
    
  4. James Hill Says:

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

  5. Lance Carlson Says:

    at least it wasn’t..

    <p>sudo rm -rdf /</p>
    
    
    <p>;)</p>
    
  6. Bob Says:

    I dont understand why that does not work :(