Last active
April 27, 2018 01:19
-
-
Save arika/d151ea292e1c1d450ca46ad0688e33a8 to your computer and use it in GitHub Desktop.
https://github.com/janko-m/vim-test のtest-unit対応 .vim/autoload/test/ruby/testunit.vim (rails.vimとminitest.vimからのコピペ)
This file contains 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
let test#runners = {'Ruby': ['TestUnit']} |
This file contains 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
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