|
1 | 1 | " Get file path
|
2 | 2 | let s:plugin_path = expand("<sfile>:p:h:h")
|
3 | 3 |
|
| 4 | +" Set Ruby/RSpec |
| 5 | +function! s:SetRubyCommand() |
| 6 | + if !exists("g:rspec_command") |
| 7 | + let s:cmd = "rspec {spec}" |
| 8 | + call s:GUIRunning() |
| 9 | + else |
| 10 | + let g:spec_command = g:rspec_command |
| 11 | + endif |
| 12 | +endfunction |
| 13 | + |
| 14 | +" Set Javascript |
| 15 | +function! s:SetJavascriptCommand() |
| 16 | + if !exists("g:mocha_js_command") |
| 17 | + let s:cmd = "mocha {spec}" |
| 18 | + call s:GUIRunning() |
| 19 | + else |
| 20 | + let g:spec_command = g:mocha_js_command |
| 21 | + endif |
| 22 | +endfunction |
| 23 | + |
| 24 | +" Set Coffeescript |
| 25 | +function! s:SetCoffeescriptCommand() |
| 26 | + if !exists("g:mocha_coffee_command") |
| 27 | + let s:cmd = "mocha --compilers coffee:coffee-script {spec}" |
| 28 | + call s:GUIRunning() |
| 29 | + else |
| 30 | + let g:spec_command = g:mocha_coffee_command |
| 31 | + endif |
| 32 | +endfunction |
| 33 | + |
| 34 | +" Initial Spec Command |
| 35 | +function! s:SetInitialSpecCommand() |
| 36 | + let l:spec = s:plugin_path . "/bin/major_filetype" |
| 37 | + let l:filetype = system(l:spec) |
| 38 | + if l:filetype =~ 'rb' |
| 39 | + call s:SetRubyCommand() |
| 40 | + elseif l:filetype =~ 'js' |
| 41 | + call s:SetJavascriptCommand() |
| 42 | + elseif l:filetype =~ 'coffee' |
| 43 | + call s:SetCoffeescriptCommand() |
| 44 | + else |
| 45 | + let g:spec_command = "" |
| 46 | + endif |
| 47 | +endfunction |
| 48 | + |
4 | 49 | " Determine which command based on filetype
|
5 | 50 | function! s:GetCorrectCommand()
|
6 | 51 | " Set default {rspec} command (ruby/rails)
|
7 | 52 | if &filetype ==? 'ruby'
|
8 |
| - if !exists("g:rspec_command") |
9 |
| - let s:cmd = "rspec {spec}" |
10 |
| - call s:GUIRunning() |
11 |
| - else |
12 |
| - let g:spec_command = g:rspec_command |
13 |
| - endif |
| 53 | + call s:SetRubyCommand() |
14 | 54 | " Set default {mocha} command (javascript)
|
15 | 55 | elseif &filetype ==? 'javascript'
|
16 |
| - if !exists("g:mocha_js_command") |
17 |
| - let s:cmd = "mocha {spec}" |
18 |
| - call s:GUIRunning() |
19 |
| - else |
20 |
| - let g:spec_command = g:mocha_js_command |
21 |
| - endif |
| 56 | + call s:SetJavascriptCommand() |
22 | 57 | " Set default {mocha} command (coffeescript)
|
23 | 58 | elseif &filetype ==? 'coffee'
|
24 |
| - if !exists("g:mocha_coffee_command") |
25 |
| - let s:cmd = "mocha --compilers coffee:coffee-script {spec}" |
26 |
| - call s:GUIRunning() |
27 |
| - else |
28 |
| - let g:spec_command = g:mocha_coffee_command |
29 |
| - endif |
| 59 | + call s:SetCoffeescriptCommand() |
30 | 60 | " Fallthrough default
|
31 | 61 | else
|
32 |
| - let g:spec_command = "" |
| 62 | + call s:SetInitialSpecCommand() |
33 | 63 | endif
|
34 | 64 | endfunction
|
35 | 65 |
|
@@ -71,8 +101,10 @@ endfunction
|
71 | 101 | function! RunAllSpecs()
|
72 | 102 | if isdirectory('spec')
|
73 | 103 | let l:spec = "spec"
|
74 |
| - else |
| 104 | + elseif isdirectory('test') |
75 | 105 | let l:spec = "test"
|
| 106 | + else |
| 107 | + let l:spec = "" |
76 | 108 | endif
|
77 | 109 | call SetLastSpecCommand(l:spec)
|
78 | 110 | call RunSpecs(l:spec)
|
|
0 commit comments