Skip to content
Browse files

running specs while on vim

  • Loading branch information...
1 parent d76a7dc commit ae99fea549d53472a482df7082f64e52f825ed25 @arthurgeek committed
Showing with 42 additions and 0 deletions.
  1. +42 −0 vimrc
View
42 vimrc
@@ -196,3 +196,45 @@ endfunction
" mapping for function above
map <leader>bw :call Wipeout()<CR>
+
+" functions ro run tests under rails project
+function! RunTests(filename)
+ " Write the file and run tests for the given filename
+ :w
+ :silent !echo;echo;echo;echo;echo
+ exec ":!bundle exec rspec " . a:filename
+endfunction
+
+function! SetTestFile()
+ " Set the spec file that tests will be run for.
+ let t:grb_test_file=@%
+endfunction
+
+function! RunTestFile(...)
+ if a:0
+ let command_suffix = a:1
+ else
+ let command_suffix = ""
+ endif
+
+ " Run the tests for the previously-marked file.
+ let in_spec_file = match(expand("%"), '_spec.rb$') != -1
+ if in_spec_file
+ call SetTestFile()
+ elseif !exists("t:grb_test_file")
+ return
+ end
+ call RunTests(t:grb_test_file . command_suffix . " --format=spec")
+endfunction
+
+function! RunNearestTest()
+ let spec_line_number = line('.')
+ call RunTestFile(":" . spec_line_number)
+endfunction
+
+" Run this file
+map <leader>r :call RunTestFile()<cr>
+" Run only the example under the cursor
+map <leader>R :call RunNearestTest()<cr>
+" Run all test files
+map <leader>a :call RunTests('spec')<cr>

0 comments on commit ae99fea

Please sign in to comment.
Something went wrong with that request. Please try again.