diff --git a/README.md b/README.md index fa41df4..a575a97 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Add your preferred key mappings to your `.vimrc` file. ```vim " RSpec.vim mappings map t :call RunCurrentSpecFile() -map s :call RunNearestSpec() +map e :call RunExamples() " runs examples under cursor or in visual selection map l :call RunLastSpec() map a :call RunAllSpecs() ``` diff --git a/plugin/rspec.vim b/plugin/rspec.vim index 34f7372..bcb5571 100644 --- a/plugin/rspec.vim +++ b/plugin/rspec.vim @@ -21,14 +21,21 @@ function! RunCurrentSpecFile() endif endfunction +" Preserved for backwards compatibility function! RunNearestSpec() + call RunExamples() +endfunction + +function! RunExamples() range if s:InSpecFile() + let line_arg = ":" . join(range(a:firstline, a:lastline), ":") + let s:last_spec_file = s:CurrentFilePath() - let s:last_spec_file_with_line = s:last_spec_file . ":" . line(".") - let s:last_spec = s:last_spec_file_with_line - call s:RunSpecs(s:last_spec_file_with_line) - elseif exists("s:last_spec_file_with_line") - call s:RunSpecs(s:last_spec_file_with_line) + let s:last_spec_examples = s:last_spec_file . line_arg + let s:last_spec = s:last_spec_examples + call s:RunSpecs(s:last_spec_examples) + elseif exists("s:last_spec_examples") + call s:RunSpecs(s:last_spec_examples) endif endfunction