Skip to content

Instantly share code, notes, and snippets.

@codenamev
Created November 14, 2019 15:20
Show Gist options
  • Save codenamev/56cbc7c9e00307f0c0185088132fc987 to your computer and use it in GitHub Desktop.
Save codenamev/56cbc7c9e00307f0c0185088132fc987 to your computer and use it in GitHub Desktop.
Run specs from vim in another tmux pane.
map <silent> <Leader>rl :w<cr>:silent call RunCurrentLineInTest('!ts bundle exec rspec')<cr>:silent redraw!<cr>
map <silent> <Leader>rt :w<cr>:silent call RunCurrentTest('!ts bundle exec rspec')<cr>:silent redraw!<cr>
" Test runner helpers
function! RunCurrentTest(rspec_type)
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFile()
if match(expand('%'), '\.feature$') != -1
call SetTestRunner("!bin/cucumber")
exec g:my_test_runner g:my_test_file
elseif match(expand('%'), '_spec\.rb$') != -1
call SetTestRunner(a:rspec_type)
exec g:my_test_runner g:my_test_file
else
call SetTestRunner(a:rspec_type)
exec g:my_test_runner g:my_test_file
endif
else
exec g:my_test_runner g:my_test_file
endif
endfunction
function! SetTestRunner(runner)
let g:my_test_runner=a:runner
endfunction
function! RunCurrentLineInTest(rspec_type)
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFileWithLine()
end
exec a:rspec_type g:my_test_file . ":" . g:my_test_file_line
endfunction
function! SetTestFile()
let g:my_test_file=@%
endfunction
function! SetTestFileWithLine()
let g:my_test_file=@%
let g:my_test_file_line=line(".")
endfunction
#!/usr/bin/env bash
# Usage: ts bundle exec rspec
#
# Sends a command to a tmux pane
args=$@
tmux send-keys -t bottom-right "$args" C-m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment