Autotest and Vim integration 5

Posted by Aaron Patterson on May 18, 2009

Yay! I got vim and autotest integration working. When I run autotest, if there is an error, I can have Vim read the errors from autotest and jump me to the right place.

Here is a video of me using it:

Please note that I’m not copying and pasting anything. In vim, I hit a command and Vim automatically picks up errors from autotest and jumps me to the line where the error occurred.

You too can impress your friends with this trick! Here’s how:

  1. Make sure you have vim-ruby installed
  2. Use this as your .autotest file:
    require 'autotest/restart'
    
    Autotest.add_hook :initialize do |at|
      at.unit_diff = 'cat'
    end
    
    Autotest.add_hook :ran_command do |at|
      File.open('/tmp/autotest.txt', 'wb') { |f|
        f.write(at.results.join)
      }
    end
    
  3. Add this to your .vimrc:

    compiler rubyunit
    nmap <Leader>fd :cf /tmp/autotest.txt<cr> :compiler rubyunit<cr>
    [/sourcecode]

Now when you get an error in autotest, just type "\fd" in Vim to jump straight to your first error.

The contents of /tmp/autotest.txt will be used in your errorfile. In Vim do ":help quickfix" for more info on what you can do with your new found power.

Caveat: You don't get unit_diff. I'm working on that. Any help would be much appreciated (I suck at errorformat in Vim).

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Adam Anderson Mon, 18 May 2009 23:24:33 UTC

    I would’ve figured to get this working on rspec that you’d just need to change the compiler to rspec but no luck so far… Hopefully I’ll figure this out because this is clearly awesome. Thanks for the great post.

  2. Jinzhu Tue, 19 May 2009 18:40:38 UTC

    wow, Really awesome!

  3. Ryan Davis Wed, 20 May 2009 15:08:51 UTC

    Welcome to emacs in 2006… you’re catching up!

  4. Aaron Patterson Wed, 20 May 2009 18:13:04 UTC

    @Ryan We’re almost there!

  5. Mitko Wed, 17 Jun 2009 08:55:16 UTC

    Really nice.

    Altough doesn’t work correctly on linux.
    The thing is “compiler rubyunit” opens the file “/test/functional/usercontrollertest.rb”, not “/home/{user}/{pathtorailsapp}/test/functional/usercontroller_test.rb”, which is empty file.

Comments

Check Spelling
Activate Spell Check while Typing