--- /home/doudou/system/gems/gems/vim-ruby-2006.07.11/ftplugin/ruby.vim	2006-10-15 14:07:27.000000000 +0200
+++ ruby.vim	2006-11-29 20:03:31.000000000 +0100
@@ -123,4 +123,99 @@ unlet s:cpo_save
 " differs on Windows.  Email gsinclair@soyabean.com.au if you need help.
 "
 
+command! -buffer -nargs=* Test :call s:Test(<f-args>)
+command! -buffer -nargs=0 RubyTestCurrentWord :call s:Test(expand('%:p'), expand('<cword>'))
+command! -buffer -nargs=0 RubyTestCurrentFile :call s:Test(expand('%:p'))
+command! -buffer -nargs=0 RubyTestRepeat      :call call("s:Test", g:ruby_last_test)
+map gTw :compiler rubyunit \| RubyTestCurrentWord<CR>
+map gTf :compiler rubyunit \| RubyTestCurrentFile<CR>
+map gt  :compiler rubyunit \| RubyTestRepeat<CR>
+command! -buffer -nargs=* RakeTest :call s:RakeTest()
+
+if exists("s:loaded_functions")
+  finish
+endif
+let s:loaded_functions=1
+
+function s:FindTestName(dir, base, prefix, ext)
+    let test = a:base
+    if isdirectory(a:dir . test)
+      return test
+    endif
+
+    if test !~ '\' . a:ext . '$'
+      let test = test . a:ext
+    endif
+    if filereadable(a:dir . test)
+      return test
+    endif
+
+    let test = a:prefix . test
+    if filereadable(a:dir . test)
+      return test
+    endif
+
+    throw "no such test " . a:base
+endfunction
+  
+" Find the directory containing 'test_file'. test_file
+" can be either a file (test_kind == 'file') or a directory
+" (test_kind == 'dir')
+function s:FindDir(test_file, test_kind)
+    let test_with = {'dir': 'isdirectory', 'file': 'filereadable'}
+    let test_function = test_with[a:test_kind]
+
+    let curdir = expand("%:p:h")
+    let basedir = curdir
+    while curdir != "/" && !call(test_function, [curdir . "/" . a:test_file])
+	let curdir = fnamemodify(curdir, ':h')
+    endwhile
+
+    if curdir == '/'
+        echoerr "cannot find the " . a:test_kind . " " . a:test_file . " from " . basedir
+    elseif curdir !~ '/$'
+        return curdir . '/'
+    else
+        return curdir
+    endif
+endfunction
+
+function s:Test(...)
+  let g:ruby_last_test = copy(a:000)
+
+  compiler! rubyunit
+  try
+    if a:0 > 0
+      if a:1[0] != '/'
+	let topsrcdir=s:FindDir('test', 'dir')
+	let testdir=topsrcdir . '/test/'
+	let testfile = testdir . s:FindTestName(testdir, a:1, 'test_', '.rb')
+      else
+	let testfile = a:1
+      endif
+
+      if a:0 == 1
+	execute "make " . testfile
+      else
+	execute "make " . testfile . " -n " . a:2
+      endif
+    else
+      let topsrcdir=s:FindDir('test', 'dir')
+      let testdir=topsrcdir . '/test/'
+      execute "make " . testdir
+    endif
+  catch 
+    echoerr v:exception
+  endtry
+endfunction
+
+function s:TestCurrentWord()
+endfunction
+
+function s:RakeTest()
+  compiler rubyunit
+  set makeprg=rake
+  execute "make test"
+endfunction
+
 " vim: nowrap sw=2 sts=2 ts=8 ff=unix:
