Skip to content

Instantly share code, notes, and snippets.

@lucasdavila
Forked from robsonmarques/.vimrc
Created July 9, 2013 17:34
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 lucasdavila/5959408 to your computer and use it in GitHub Desktop.
Save lucasdavila/5959408 to your computer and use it in GitHub Desktop.
" RSpec
map <Leader>r :call RunTest()<CR>
map <Leader>R :call RunNearestTest()<CR>
function! RunTest()
call RunTestFile(FindTestFile())
endfunction
function! RunNearestTest()
call RunTestFile(FindTestFile() . ':' . line('.'))
endfunction
function! FindTestFile()
let current_file = expand("%")
let spec_file = current_file
if match(current_file, '_spec.rb$') == -1
let spec_file = substitute(spec_file, '^app/', '', '')
let spec_file = substitute(spec_file, '.rb$', '_spec.rb', '')
let spec_file = 'spec/' . spec_file
endif
return spec_file
endfunction
function! RunTestFile(filename)
write
if filereadable('bin/rspec')
exec ":!bin/rspec --format documentation " . a:filename
else
exec ":!bundle exec rspec --format documentation " . a:filename
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment