x0nt1g
Last Updated: February 25, 2016
·
857
· maxidr

Run your Rails tests from vim to spin

After seeing the blog post of Vladimir Saric titled Streamlining vim with RSpec and Cucumber I add some changes to run rspec test in spin. You need to add the following in ~/.vimrc file:

" Functions to run spin from VIM

function! RailsScriptIfExists(name)
  " Bundle exec
  if isdirectory(".bundle") || (exists("b:rails_root") && isdirectory(b:rails_root . "/.bundle"))
    return "bundle exec " . a:name
  " System Binary
  else
    return a:name
  end
endfunction

function! RunSpinPush(args)
  let spec = RailsScriptIfExists("spin push")
  let cmd = spec . " " . a:args . " " . @%
  execute ":silent ! echo " . cmd . " && " . cmd . " &>/dev/null &" | redraw!
endfunction

map <Leader>s :call RunSpinPush("")<CR>

Now you can use CTRL + s (or the key as you configure as Leader) in the rspec file (in vim) and show the test result in the terminal you're running spin serve.