-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.vim
51 lines (43 loc) · 1.35 KB
/
testing.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function Test_file()
let currentFile = expand('%')
if currentFile =~ "spec/.*.rb"
call RspecTest(currentFile)
elseif currentFile =~ ".*.py"
call PythonTest(currentFile)
else
let errorMessage = "Can't run tests for this file.."
lua require("notify")(errorMessage, "error")
endif
endfunction
function Test_line()
let current_file = expand('%')
" let file_name = split(current_file, "\\.")[0]
if current_file !~ "spec/.*.rb"
lua require("notify")("Can't run test for this line..", "error")
return
endif
if exists('$TMUX')
call system('tmux split -h "bundle exec rspec ' . current_file . ':' . line('.') . ' --format documentation; read"')
else
exe "! bundle exec rspec " . current_file . ":" . line(".")
endif
endfunction
function RspecTest(fileName)
if exists('$TMUX')
call system('tmux split -h "bundle exec rspec ' . a:fileName . ' --format documentation; read"')
else
exe "! bundle exec rspec " . a:fileName
endif
endfunction
function PythonTest(fileName)
let absoluteCommand = printf("pytest %s; read", expand("%"))
if exists('$TMUX')
let command = printf("tmux split -h '%s'", absoluteCommand)
call system(command)
else
call system(printf("! %s", absoluteCommand))
endif
endfunction
function RepoAbsolutePath()
return system("git rev-parse --show-toplevel | tr -d '\\n'")
endfunction