01 January, 2013

vim commands/functions to run cukes within vim

OK, I'm doing more rails work in vim, these days, so I'll be tossing more stupid vim tricks up here as I run into them.

The other day, I was moaning about cucumber and locations of step files, as it encourages (but doesn't depend upon) a file-naming convention. As such, step files can be hard to find. Anyway, as I'm kicking through a way to script a solution to that problem, I decided I wanted a way to run cukes from within vim.

I came up with two solutions:

  1. one to run the whole file that's in the currently open buffer
  2. one to run the scenario that starts on the line the cursor is on
To implement these, I'm using the very cool RunShellCommand function found here, which opens the results of the command in a scratch buffer in a new window.

I just added the following command definitions to my .vimrc:

command! Cuke call s:RunShellCommand('bundle exec cucumber ' .expand('%:p'))

command! CukeL call s:RunShellCommand('bundle exec cucumber ' .expand('%:p').':'.winline())  


I haven't mapped short commands with my <leader> yet as I'm not sure if I'll use this regularly, but it seemed helpful, so I thought I'd share. The drawback is that the execution time of cucumber is long, especially if it's a UI test, so it can take over your UI for a while, which is why I added CukeL, so I cold run just the current line. The cucumber overhead is still pretty high, so I may look into creating a modified RunShellCommand that forks the process, so you can continue working while you fire off the command.

No comments: