-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated spec-finder plugin with vim-ruby-conque
- Loading branch information
Showing
4 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters