-
-
Save lucasdavila/5959408 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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