Currently my vimrc has the following key mappings:
map <leader>m :w\|!clear && rspec --drb %<cr>
map <leader>k :w\|!clear && rspec --drb %:<C-r>=line('.')<CR><cr>
map <leader>c :w\|:!clear && cucumber --drb -r ./features %<cr>
map <leader>x :w\|!clear && cucumber --drb -r ./features %:<C-r>=line('.')<CR><cr>
However I want to consolidate them into (two) functions that have the same keymap for line vs file, I've tried the following but Vim complains about missing parentheses:
function! TestCurrentLine()
let spec = '*_spec\.rb'
if !(expand("%") =~ spec)
:!clear && cucumber --drb -r ./features %:<C-r>=line('.')<CR>
else
:!clear && rspec --drb %:<C-r>=line('.')<CR>
end
endfunction
function! TestCurrentFile()
let spec = '*_spec\.rb'
if !(expand("%") =~ spec)
:!clear && cucumber --drb -r ./features %
else
:!clear && rspec --drb %
end
endfunction
map <leader>m :w\|call TestCurrentFile<cr>
map <leader>k :w\|call TestCurrentLine<cr>
Any ideas?