Created
January 29, 2016 22:32
-
-
Save davidpdrsn/0569291c4a4a5a900c9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function! s:path_to_current_file() | |
| return expand("%") | |
| endfunction | |
| function! s:splitv(file_name) | |
| execute "vsplit " . a:file_name | |
| endfunction | |
| function! s:splith(file_name) | |
| execute "split " . a:file_name | |
| endfunction | |
| function! s:spec_file_path(filename) | |
| if match(a:filename, "_spec") != -1 | |
| if match(a:filename, "lib") != -1 | |
| let folder_name = substitute(a:filename, "spec/lib", "lib", "") | |
| return substitute(folder_name, "_spec.rb", ".rb", "") | |
| else | |
| let folder_name = substitute(a:filename, "spec/", "app/", "") | |
| return substitute(folder_name, "_spec.rb", ".rb", "") | |
| endif | |
| else | |
| let folder_name = substitute(a:filename, "app", "spec", "") | |
| let folder_name = substitute(folder_name, "lib", "spec/lib", "") | |
| return substitute(folder_name, ".rb", "_spec.rb", "") | |
| endif | |
| endfunction | |
| function! rails_test#run_spec() | |
| let path = s:spec_file_path(s:path_to_current_file()) | |
| execute "Dispatch rspec " . path | |
| endfunction | |
| function! rails_test#vsplit_spec() | |
| let path = s:spec_file_path(s:path_to_current_file()) | |
| call s:splitv(path) | |
| endfunction | |
| function! rails_test#hsplit_spec() | |
| let path = s:spec_file_path(s:path_to_current_file()) | |
| call s:splith(path) | |
| endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment