Skip to content

Instantly share code, notes, and snippets.

@hjdivad
Created July 8, 2014 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hjdivad/1a45219b5a9cf1034ef4 to your computer and use it in GitHub Desktop.
Save hjdivad/1a45219b5a9cf1034ef4 to your computer and use it in GitHub Desktop.
" for filetype rspec

if !exists("*s:RunSpec")
  function s:RunSpec()
    let command="tmux send-keys -t bottom-left zeus " . "' '" . "rspec\ " . "' '" . expand("%") . ":" . line(".") . "$'\n'"
    let g:last_spec_command=command

    echo system(command)
  endfunction
endif

nmap <buffer> T :call <SID>RunSpec()<CR>
" for filetype vim

if !exists("*s:RerunLastSpec")
  function s:RerunLastSpec()
    if exists("g:last_spec_command")
      echo system(g:last_spec_command)
    endif
  endfunction
endif

nmap <buffer> T :call <SID>RerunLastSpec()<CR>

This assumes that your rspec files have a type of something like 'ruby.rspec'. An easy way to do this is as follows

augroup ExtraTypes
  autocmd!
  autocmd BufNewFile,BufRead *_spec.rb set ft+=.rspec
augroup end

With all this set up, T in an rspec file will run the test on that line, and in a ruby file will re-run the last test.

Note that it assumes a couple things:

  1. that the test command is zeus
  2. that you're in tmux and you want to run tests in the bottom-left pane.

It's easy enough to change the command to suit your environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment