Permalink
Browse files

Integrated spec-finder plugin with vim-ruby-conque

  • Loading branch information...
1 parent 3f70b50 commit ff1e84bf89cfd214303d9815f8688bc892cc648d @skwp committed May 30, 2012
Showing with 99 additions and 2 deletions.
  1. +22 −2 README.md
  2. +31 −0 doc/spec-finder.txt
  3. +40 −0 plugin/spec-finder.vim
  4. +6 −0 plugin/vim-ruby-conque.vim
View
@@ -1,7 +1,8 @@
-vim-ruby-conque.vim
+Ruby Conque & Fast-spec Aware RSpec Finder
============
* Colorized Ruby, Rake, RSpec, and Cucumber output in vim using ConqueTerm
+ * Spec Finder - use `Ctrl-s` to automatically find the related spec and open in a split, fast_spec aware!
* Sensible keybindings (feel free to change), all prefixed with 'rc':
```vim
@@ -12,6 +13,9 @@ nmap <silent> <Leader>rccc :call RunCucumberCurrentFileConque()<CR>
nmap <silent> <Leader>rccl :call RunCucumberCurrentLineConque()<CR>
nmap <silent> <Leader>rcRR :call RunRakeConque()<CR>
nmap <silent> <Leader>rcrl :call RunLastConqueCommand()<CR>
+
+nnoremap <silent> <C-s> :call RelatedSpecVOpen()<CR>
+nnoremap <silent> ,<C-s> :call RelatedSpecOpen()<CR>
```
* Requires: http://code.google.com/p/conque/
@@ -34,7 +38,7 @@ nmap <silent> <D-L> :call RunRspecCurrentLineConque()<CR>
nmap <silent> ,<D-R> :call RunLastConqueCommand()<CR>
```
-Usage
+Using the Spec Runner
-------------
Try some of the keybindings listed above.
@@ -45,6 +49,22 @@ Upon running a test your cursor will be in the Conque buffer, you can use these
p goes to the previous Failure message.
f goes to the Finished At section for an overview of the test.
+Using the Spec Finder
+--------------
+
+While inside a ruby file, invoke the shortcut (supplied as `Ctrl-s`), and
+the corresponding spec will be open. The assumptions are:
+
+ * Your specs live in spec/ or fast_spec/
+ * Your pwd (current dir) is the project root
+ * You use the same dir structure in your code and specs so that
+ code living at lib/foo/bar.rb has a spec at spec/lib/foo/bar_spec.rb
+
+For more information, please see doc/spec-finder.txt. There are included
+functions for opening the spec in the current window, and in a split, as
+well as just getting its full path.
+
+
Configuration
--------------
View
@@ -0,0 +1,31 @@
+*spec-finder.txt* Finds and opens the spec related to the file you're working on.
+
+Author: Yan Pritzker <http://yanpritzker.com/>
+
+USAGE *spec-finder*
+
+While inside a ruby file, invoke the shortcut (supplied as Ctrl-s), and
+the corresponding spec will be open. The assumptions are:
+
+ * Your specs live in spec/ or fast_spec/
+ * Your pwd (current dir) is the project root
+ * You use the same dir structure in your code and specs so that
+ code living at lib/foo/bar.rb has a spec at spec/lib/foo/bar_spec.rb
+
+This method handles files in fast_spec unlike the :A and :AV functions
+that ship with rails.vim
+
+FUNCTIONS *spec-finder-functions*
+
+RelatedSpec() - gives you the name of the related spec, can be integrated
+into other scripts, such as something that saves your file and runsj the
+related spec.
+RelatedSpecOpen() - Opens the related spec in current window
+RelatedSpecVOpen() - Opens the related spec in vertical split
+
+ABOUT *spec-finder-author*
+
+Find the project, and contribute at:
+https://github.com/skwp/vim-spec-finder
+
+Copyright (c) Yan Pritzker. Distributed under the same terms as Vim itself.
View
@@ -0,0 +1,40 @@
+" Find the related spec for any file you open.
+function! RelatedSpec()
+ let l:fullpath = expand("%:p")
+ let l:filepath = expand("%:h")
+ let l:fname = expand("%:t")
+ let l:filepath_without_app = substitute(l:filepath, "app/", "", "")
+
+ " Possible names for the spec/test for the file we're looking at
+ let l:test_names = [substitute(l:fname, ".rb$", "_spec.rb", ""), substitute(l:fname, ".rb$", "_test.rb", "")]
+
+ " Possible paths
+ let l:test_paths = ["spec", "fast_spec", "test"]
+
+ for test_name in l:test_names
+ for path in l:test_paths
+ let l:spec_path = path . "/" . l:filepath_without_app . "/" . test_name
+ let l:full_spec_path = substitute(l:fullpath, l:filepath . "/" . l:fname, l:spec_path, "")
+ if filereadable(l:spec_path)
+ return l:full_spec_path
+ end
+ endfor
+ endfor
+endfunction
+
+function! RelatedSpecOpen()
+ let l:spec_path = RelatedSpec()
+ if filereadable(l:spec_path)
+ execute ":e " . l:spec_path
+ endif
+endfunction
+
+function! RelatedSpecVOpen()
+ let l:spec_path = RelatedSpec()
+ if filereadable(l:spec_path)
+ execute ":botright vsp " . l:spec_path
+ endif
+endfunction
+
+nnoremap <silent> <C-s> :call RelatedSpecVOpen()<CR>
+nnoremap <silent> ,<C-s> :call RelatedSpecOpen()<CR>
@@ -72,6 +72,11 @@ function! RunLastConqueCommand()
endif
endfunction
+" Requires https://github.com/skwp/vim-spec-finder
+function! RunRspecRelated()
+ call RunSingleConque(g:ruby_conque_rspec_command . " " . RelatedSpec() . " --color")
+endfunction
+
" Get around Conques annoying trapping of input in some kind of strange
" inputless input mode. Also added q to close the buffer. n and p jump between
" errors in the output buffer.
@@ -94,3 +99,4 @@ nmap <silent> <Leader>rccl :call RunCucumberCurrentLineConque()<CR>
nmap <silent> <Leader>rccc :call RunCucumberCurrentFileConque()<CR>
nmap <silent> <Leader>rcRR :call RunRakeConque()<CR>
nmap <silent> <Leader>rcrl :call RunLastConqueCommand()<CR>
+nmap <silent> <Leader>rcrel :call RunRspecRelated()<CR>

0 comments on commit ff1e84b

Please sign in to comment.