Closed sfahlberg closed 7 years ago
I tried something to fix a maybe similar problem: https://github.com/dgmstuart/dotfiles/commit/3d1dd2348ba524602dc939d82216b674e474d806
I wanted to run RSpec through spring (i.e. through bin/rspec
) when it was available, but to fall back to a vanilla command when it wasn't (e.g. on a non-rails ruby project).
The problem I found was that although this approach works for running the whole suite, and files which load in the rails environment (e.g. using rails_helper
), it doesn't work so well for specs which were isolated (using only a spec_helper
and loading a minimum of dependencies), since running those with Spring actually slowed them down.
So I guess I do have the same need: to toggle how rspec runs, on the fly.
A simplistic solution might be something like this:
map <Leader>) :let g:rspec_command = "Dispatch bin/rspec {spec} --format=progress"<CR>
map <Leader>( :let g:rspec_command = "Dispatch bundle exec rspec {spec} --format=progress"<CR>
Or you could maybe go a step further and define a toggle function that switches between the two definitions - something like this:
let g:rspec_executable = "bundle exec rspec"
function! ToggleRSpecCommand()
if g:rspec_executable == "bundle exec rspec"
let g:rspec_executable = "bin/rspec"
else
let g:rspec_executable = "bundle exec rspec"
endif
echo "rspec_executable set to " . g:rspec_executable
let g:rspec_command = "Dispatch " . g:rspec_executable . " {spec} --format=progress"
endfunction
map <Leader>e :call ToggleRSpecCommand()<CR>
Another approach is to write a custom rspec
shell script (IMO it's easier to program in shell) that does checks to see which command should be ran based on things existing or not, then call that custom script as g:rspec_command
. I think there's enough of ideas here, so I'm going to close this issue.
awesome! Thanks! super helpful
hi there. I would like to be able to modify the
g:rspec_command
based on a shortcut I type. Sometimes, I want to use zeus, sometimes I don't. Sometimes I want to use dispatch sometimes I want to output tests outside of vim so I can run with a binding.pry.Is there any way to change the g:rspec command on the fly?