thoughtbot / vim-rspec

Run Rspec specs from Vim
https://robots.thoughtbot.com
MIT License
656 stars 108 forks source link

Pass along flag to rspec #115

Closed jsborjesson closed 7 years ago

jsborjesson commented 8 years ago

Hello! I use this plugin probably a thousand times per day, and I often find myself thinking "I would like to run the last selected specs, but with --format=documentation. Is this possible somehow? Being able to pass the rspec flags to RunLastSpec() as an argument would be great, but maybe there is an easier way to do this.

Any pointers are appreciated!

jondavidjohn commented 7 years ago

Using a custom command would likely do the trick.

jsborjesson commented 7 years ago

Is it possible to do this on a per-run basis? I want the normal output most of the time, but a special binding to do it again more verbosely. Perhaps I can write a function that sets the custom command, then runs it, then changes it back...

jsborjesson commented 7 years ago

Was actually very easy to do it this way - don't know why I didn't think of it before:

" .vim/after/ftplugin/ruby.vim
let g:rspec_command = 'call VtrSendCommand("bundle exec rspec {spec}")'
nnoremap <buffer> <Leader>a :call RunAllSpecs()<CR>
nnoremap <buffer> <Leader>l :call RunLastSpec()<CR>
nnoremap <buffer> <Leader>L :call RunLastSpecWithDocumentation()<CR>
nnoremap <buffer> <Leader>s :call RunNearestSpec()<CR>
nnoremap <buffer> <Leader>t :call RunCurrentSpecFile()<CR>

function! RunLastSpecWithDocumentation()
    let l:old_rspec_command = g:rspec_command
    let g:rspec_command = 'call VtrSendCommand("bundle exec rspec {spec} --format=documentation")'

    call RunLastSpec()

    let g:rspec_command = l:old_rspec_command
endfunction