Skip to content

Instantly share code, notes, and snippets.

@arika arika/.vimrc
Last active Apr 27, 2018

Embed
What would you like to do?
https://github.com/janko-m/vim-test のtest-unit対応 .vim/autoload/test/ruby/testunit.vim (rails.vimとminitest.vimからのコピペ)
let test#runners = {'Ruby': ['TestUnit']}
if !exists('g:test#ruby#testunit#file_pattern')
let g:test#ruby#testunit#file_pattern = '\v_test\.rb$'
endif
function! test#ruby#testunit#test_file(file) abort
if empty(s:testunit_version()) || s:testunit_version()[0] < 3
return 0
end
return a:file =~# g:test#ruby#testunit#file_pattern
endfunction
function! test#ruby#testunit#build_position(type, position) abort
if a:type ==# 'nearest'
return [a:position['file'], '--location='.a:position['line']]
elseif a:type ==# 'file'
return [a:position['file']]
else
return []
endif
endfunction
function! test#ruby#testunit#build_args(args) abort
return test#ruby#minitest#build_args(a:args)
endfunction
function! test#ruby#testunit#executable() abort
if filereadable('Rakefile') && system('cat Rakefile') =~# 'Rake::TestTask' ||
\ (exists('b:rails_root') || filereadable('./bin/rails'))
if !empty(glob('.zeus.sock'))
return 'zeus rake test'
elseif filereadable('./bin/rake') && get(g:, 'test#ruby#use_binstubs', 1)
return './bin/rake test'
elseif filereadable('Gemfile') && get(g:, 'test#ruby#bundle_exec', 1)
return 'bundle exec rake test'
else
return 'rake test'
endif
else
if filereadable('Gemfile') && get(g:, 'test#ruby#bundle_exec', 1)
return 'bundle exec ruby -I test'
else
return 'ruby -I test'
endif
endif
endfunction
function! s:testunit_version() abort
if filereadable('Gemfile.lock')
for line in readfile('Gemfile.lock')
let version_string = matchstr(line, '\v^ *test-unit \(\zs\d+\.\d+\..+\ze\)')
if version_string
break
endif
endfor
if version_string
let rails_version = matchlist(version_string, '\v(\d+)\.(\d+)\.(\d+)%(\.(\d+))?')[1:-1]
call filter(rails_version, '!empty(v:val)')
call map(rails_version, 'str2nr(v:val)')
return rails_version
end
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.