Skip to content

Instantly share code, notes, and snippets.

@jparker
Created February 12, 2013 19:35
Show Gist options
  • Save jparker/4772677 to your computer and use it in GitHub Desktop.
Save jparker/4772677 to your computer and use it in GitHub Desktop.
Mappings and a function for running RSpec within Vim.
noremap <Leader>rs :call RunSpec('spec', '-fp')<CR>
noremap <Leader>rd :call RunSpec(expand('%:h'), '-fd')<CR>
noremap <Leader>rf :call RunSpec(expand('%'), '-fd')<CR>
noremap <Leader>rl :call RunSpec(expand('%'), '-fd -l ' . line('.'))<CR>
function! RunSpec(spec_path, spec_opts)
let speccish = match(@%, '_spec.rb$') != -1
if speccish
exec '!bundle exec rspec ' . a:spec_opts . ' ' . a:spec_path
else
echo '<< WARNING >> RunSpec() can only be called from inside spec files!'
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment