diff --git a/plugin/vttr.vim b/plugin/vttr.vim index dd841e9..373132a 100644 --- a/plugin/vttr.vim +++ b/plugin/vttr.vim @@ -25,6 +25,7 @@ function! SetFilePaths() let fullfilename = expand('%:p') let matches = matchlist(fullfilename, '\(.*\)\/\(spec.*\)') if len(matches) < 3 + let accompanyingSpecPath = findAccompanyingSpec() return 0 endif let s:project_root_path = matches[1] @@ -32,6 +33,18 @@ function! SetFilePaths() return 1 endfunction +function! FindAccompanyingSpec(fullfilename) + let a:fullfilename = 'app/models/user.rb' + let filename_matches = matchlist(a:fullfilename, '.*\/\(.*\).rb') + if len(filename_matches) < 2 + let accompanyingSpecPath = findAccompanyingSpec() + return 0 + endif + let filename = filename_matches[1] + let newfilename = substitute(fullfilename, '\/\([a-z]*.rb\)', '/' . filename . '_spec.rb', 'g') + echo substitute(newfilename, 'app\/', 'spec/', 'g') +endfunction + function! ClearScreenIfNeeded() if g:clear_screen_before_test_run call system("tmux send-keys -t .+ 'clear' Enter")