Skip to content

Instantly share code, notes, and snippets.

@lkosak
Created May 9, 2014 00:13
Show Gist options
  • Save lkosak/8142ee47dc626928a718 to your computer and use it in GitHub Desktop.
Save lkosak/8142ee47dc626928a718 to your computer and use it in GitHub Desktop.
vim rspec functions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>r :call RunTestFile("")<cr>
"map <leader>r :call RunTestFile("", "--tag wip")<cr>
map <leader>t :call RunTestFile(line("."))<cr>
function! ZeusRunning()
return findfile(".zeus.sock", getcwd()) == ".zeus.sock"
endfunction
function! RunTestFile(line, ...)
let filename = expand("%")
if ZeusRunning()
let command = "zeus rspec"
else
let command = "bundle exec rspec"
end
let run = ""
if match(filename, '\.feature$') != -1
let run = ":!cucumber " . filename
elseif match(filename, '_spec\.js$') != -1
let run = ":!make test"
elseif match(filename, '_spec\.rb$') != -1
if a:line
let filename = filename . ":" . a:line
endif
if a:0 > 0
let run = ":!" . command . " " . a:1 . " " . filename
else
let run = ":!" . command . " " . filename
endif
end
if empty(run)
echo "Not in a test file"
else
exec run
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment