Skip to content

Instantly share code, notes, and snippets.

@hovsater
Last active December 29, 2015 15:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hovsater/7688474 to your computer and use it in GitHub Desktop.
Save hovsater/7688474 to your computer and use it in GitHub Desktop.
User-defined command to setup key mappings for RSpec.
function RSpecCommands(bang)
if !a:bang
noremap <Leader>t :!bundle exec rspec %<CR>
noremap <Leader>T :!bundle exec rspec %:<C-R>=line('.')<CR><CR>
else
silent! nunmap <Leader>t
silent! nunmap <Leader>T
endif
endfunction
command -bang RSpec call RSpecCommands(<bang>0)

Usage

In Vim run :RSpec to activate the key mappings. <Leader>t can either run all tests in the current file or all tests in the project if no file is present. <Leader>T will run the test on the current line. Run :RSpec! to deactivate the key mappings.

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