Skip to content
Browse files

Alternate between lib files and their tests/specs.

Tries to find a unit test for a lib file first, then tries to find a
spec for it. For a unit test, tries to find a model first, then a lib
file. Added lib and spec-lib file types.
  • Loading branch information...
1 parent c82f452 commit 018ede6cb5da83524e52f7146c274965191a3d4c @mwilden mwilden committed with Sep 25, 2008
Showing with 10 additions and 2 deletions.
  1. +10 −2 autoload/rails.vim
View
12 autoload/rails.vim
@@ -523,6 +523,10 @@ function! RailsFileType()
let r = "test-functional"
elseif f =~ '\<test/integration/.*_test\.rb$'
let r = "test-integration"
+ elseif f =~ '\<spec/lib/.*_spec\.rb$'
+ let r = 'spec-lib'
+ elseif f =~ '\<lib/.*\.rb$'
+ let r = 'lib'
elseif f =~ '\<spec/\w*s/.*_spec\.rb$'
let r = s:sub(f,'.*<spec/(\w*)s/.*','spec-\1')
elseif f =~ '\<\%(test\|spec\)/fixtures\>'
@@ -2560,7 +2564,7 @@ function! s:AlternateFile()
"return s:sub(file,'app/controllers/','test/functional/')
return s:sub(file,'<app/controllers/','test/functional/')."\n".s:sub(s:sub(file,'_test\.rb$','_spec.rb'),'app/controllers/','spec/controllers/')
elseif t =~ '^test-unit\>'
- return s:sub(file,'test/unit/','app/models/')
+ return s:sub(file,'test/unit/','app/models/')."\n".s:sub(file,'test/unit/','lib/')
elseif t =~ '^test-functional\>'
if file =~ '_api\.rb'
return s:sub(file,'test/functional/','app/apis/')
@@ -2569,7 +2573,11 @@ function! s:AlternateFile()
else
return s:sub(file,'test/functional/','')
endif
- elseif t =~ '^spec\>'
+ elseif t == 'spec-lib'
+ return s:sub(file,'<spec/','')
+ elseif t == 'lib'
+ return s:sub(f, '<lib/(.*)\.rb$', 'test/unit/\1_test\.rb')."\n".s:sub(f, '<lib/(.*)\.rb$', 'spec/lib/\1_spec\.rb')
+ elseif t == 'spec'
return s:sub(file,'<spec/','app/')
elseif file =~ '\<vendor/.*/lib/'
return s:sub(file,'<vendor/.{-}/\zslib/','test/')

0 comments on commit 018ede6

Please sign in to comment.
Something went wrong with that request. Please try again.