Permalink
Browse files

Added test functions for vim

  • Loading branch information...
1 parent 522476f commit ddf1dfb91723862d41e5a3a3f6a62e43b77db794 Teo Ljungberg committed Jan 6, 2013
Showing with 72 additions and 13 deletions.
  1. +1 −1 .gitignore
  2. +51 −0 home/.vim/test_functions.vim
  3. +20 −12 home/.vimrc
View
@@ -1 +1 @@
-home/.vim/bundle/*
+home/.vim/bundle
@@ -0,0 +1,51 @@
+function! RunCurrentTest()
+ let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
+ if in_test_file
+ call SetTestFile()
+
+ if match(expand('%'), '\.feature$') != -1
+ call SetTestRunner("!cucumber")
+ exec g:bjo_test_runner g:bjo_test_file
+ elseif match(expand('%'), '_spec\.rb$') != -1
+ call SetTestRunner("!rspec")
+ exec g:bjo_test_runner g:bjo_test_file
+ else
+ call SetTestRunner("!ruby -Itest")
+ exec g:bjo_test_runner g:bjo_test_file
+ endif
+ else
+ exec g:bjo_test_runner g:bjo_test_file
+ endif
+endfunction
+
+function! SetTestRunner(runner)
+ let g:bjo_test_runner=a:runner
+endfunction
+
+function! RunCurrentLineInTest()
+ let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
+ if in_test_file
+ call SetTestFileWithLine()
+ end
+
+ exec "!rspec" g:bjo_test_file . ":" . g:bjo_test_file_line
+endfunction
+
+function! SetTestFile()
+ let g:bjo_test_file=@%
+endfunction
+
+function! SetTestFileWithLine()
+ let g:bjo_test_file=@%
+ let g:bjo_test_file_line=line(".")
+endfunction
+
+function! CorrectTestRunner()
+ if match(expand('%'), '\.feature$') != -1
+ return "cucumber"
+ elseif match(expand('%'), '_spec\.rb$') != -1
+ return "rspec"
+ else
+ return "ruby"
+ endif
+endfunction
View
@@ -22,6 +22,7 @@ Bundle 'tpope/vim-rails'
Bundle 'tpope/vim-git'
Bundle 'tpope/vim-markdown'
Bundle 'tpope/vim-commentary'
+Bundle 'tpope/vim-sleuth'
Bundle 'mattn/gist-vim'
Bundle 'mattn/webapi-vim'
Bundle 'scrooloose/nerdtree'
@@ -42,28 +43,30 @@ set nowritebackup " no backups
set nobackup
set noswapfile
-set shiftwidth=2 " intendation
-set tabstop=2
-set softtabstop=2
set expandtab
set autoindent
set smartindent
set wrap
set linebreak
-autocmd FileType html setlocal expandtab shiftwidth=4 softtabstop=4
-autocmd FileType javascript setlocal expandtab shiftwidth=4 softtabstop=4
-autocmd FileType css setlocal expandtab shiftwidth=4 softtabstop=4
+highlight ExtraWhitespace ctermbg=red guibg=red
+match ExtraWhitespace /\s\+$/
set incsearch " search
set hlsearch
set ignorecase
set smartcase
set gdefault
-nnoremap n nzzzv
-nnoremap N Nzzzv
+noremap n nzzzv
+noremap N Nzzzv
+noremap * *<c-o>
+
+" for running tests inside vim
+source ~/.vim/test_functions.vim
+noremap <leader>tl :call RunCurrentLineInTest()<cr>
+noremap <leader>tt :call RunCurrentTest()<cr>
" NERDTree
-noremap <leader>n :NERDTreeToggle<cr>
+noremap <silent> <leader>n :NERDTreeToggle<cr>
let NERDTreeChDirMode = 1
let NERDTreeMinimalUI = 1
let NERDTreeWinPos = 'right'
@@ -96,11 +99,16 @@ call togglebg#map("<F5>")
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gc :Gcommit -v<CR>
+" Rails
+noremap <leader>m :Rmodel
+noremap <leader>c :Rcontroller
+noremap <leader>v :Rview
+
"LEADER bindings
noremap <leader>s :%s//<left>
noremap <leader>ev :vsplit ~/.vimrc<cr>
-noremap <LEADER><space> :nohls<cr>
-noremap <leader>v V`]
+noremap <silent> <leader><space> :nohls<cr>call clearmatches()<cr>
+noremap <leader>V V`]
" sudo to write
cmap w!! w !sudo tee % >/dev/null<cr>
@@ -126,7 +134,7 @@ map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
-
+
" emacs movement in insert/command mode
inoremap <c-a> <esc>I
inoremap <c-e> <esc>A

0 comments on commit ddf1dfb

Please sign in to comment.