Skip to content

Instantly share code, notes, and snippets.

@jmbeck
Created December 20, 2013 17:10
Show Gist options
  • Save jmbeck/8058045 to your computer and use it in GitHub Desktop.
Save jmbeck/8058045 to your computer and use it in GitHub Desktop.
Running tests from inside vim
let mapleader = " "
" rspec mappings
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
function! RunCurrentSpecFile()
if InSpecFile()
let l:command = "zeus test " . @%
call SetLastSpecCommand(l:command)
call RunSpecs(l:command)
endif
endfunction
function! RunNearestSpec()
if InSpecFile()
let l:command = "zeus test " . @%. ":" . line(".")
call SetLastSpecCommand(l:command)
call RunSpecs(l:command)
endif
endfunction
function! RunLastSpec()
if exists("t:last_spec_command")
call RunSpecs(t:last_spec_command)
endif
endfunction
function! InSpecFile()
return match(expand("%"), "_spec.rb$") != -1
endfunction
function! SetLastSpecCommand(command)
let t:last_spec_command = a:command
endfunction
function! RunSpecs(command)
execute ":w\|!clear && echo " . a:command . " && echo && " . a:command
endfunction
Steps
-----
1) Add the above lines to your ~/.vimrc
2) Add the zeus line to your thredUP3/Procfile
3) Add zeus.json to your thredUP3/ directory (for faster startup)
4) Restart foreman
5) Run tests from vim!
i. Spacebar + s runs the test your cursor is on
ii. Spacebar + t runs the entire file
redis: redis-server --port 6379
web: unicorn_rails -c config/unicorn.conf
test_web: unicorn_rails -c config/unicorn_test.conf --env=test
zeus: zeus start
{
"command": "ruby -rubygems -r./custom_plan -eZeus.go",
"plan": {
"boot": {
"default_bundle": {
"development_environment": {
"prerake": {"rake": []},
"console": ["c"],
"generate": ["g"]
},
"test_environment": {
"test_helper": {"test": ["rspec"]}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment