Created
May 15, 2012 07:15
-
-
Save lkosak/2699716 to your computer and use it in GitHub Desktop.
Run them rails tests from vim!
This file contains 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
function! RunRailsTest() | |
let file = expand("%") | |
let basepath = getcwd() | |
let in_test_file = match(file, '\(.feature\|_spec.rb\|_test.rb\)$') != -1 | |
if !in_test_file | |
" Come up with a best guess search path | |
let search_fname = fnamemodify(file, ":s?^app/??:s?.rb$?_spec.rb?") | |
" Search for that shit | |
let result = globpath(basepath."/spec", "**/".search_fname) | |
if empty(result) | |
echo "Couldn't locate test file" | |
return | |
end | |
" Get first match (globpath returns a \n separated list) | |
let file = split(result, "\n")[0] | |
" Make it relative to the current dir (for display purposes) | |
let file = fnamemodify(file, ":.") | |
end | |
exec ":!clear && echo 'Running ".file."' && ruby " . file | |
endfunction | |
nmap <leader>r :call RunRailsTest()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment