Permalink
Browse files

Initial release

  • Loading branch information...
0 parents commit 4b521750cdffb9f92dc06dffc940d4e213548ac3 @jgdavey committed Jan 9, 2012
Showing with 192 additions and 0 deletions.
  1. +19 −0 README.mdown
  2. +70 −0 doc/turbux.txt
  3. +103 −0 plugin/turbux.vim
@@ -0,0 +1,19 @@
+Turbux is designed to speed up your TDD cycle by using a single key
+mapping to run the most relevant test based on the current file in vim.
+It uses tmux's scriptability to send commands to a chosen pane in your
+tmux session, by way of tslime.vim.
+
+For more information, see the documentation.
+
+
+Dependencies
+------------
+
+This plugin depends on tslime.vim, and becomes really awesome when used
+with rails.vim. It also makes the assumption that you're using tmux.
+
+
+Installation
+------------
+
+Use tpope's pathogen.
@@ -0,0 +1,70 @@
+*turbux.txt* Turbo Ruby tests with tmux
+
+Author: Joshua Davey <http://joshuadavey.com/>
+License: Same terms as Vim itself (see |license|)
+
+This plugin is only available if 'compatible' is not set.
+
+This plugin depends on tslime.vim, and optionally rails.vim. As with
+tslime.vim, it is only useful within a tmux session.
+
+INTRODUCTION *turbux*
+
+Turbux is designed to speed up your TDD cycle by using a single key
+mapping to run the most relevant test based on the current file in vim.
+It uses tmux's scriptability to send commands to a chosen pane in your
+tmux session, by way of tslime.vim.
+
+The default mapping for invoking the plugin is <leader>t. In a spec
+file, this will run "rspec <filename>". In a test-unit file, this will
+run "ruby -Itest <filename>". In a cucumber feature file, this will run
+"cucumber <filename>".
+
+If rails.vim is present, some additional niceties are provided. When
+rails.vim can find an alternate file for the current one, and that file
+is a spec or test, it will run the alternate file rather than the one
+you are in. For example, given the following two files:
+>
+ app/models/foo.rb
+ spec/models/foo_bar.rb
+<
+When the current file and is "foo.rb" and you invoke the plugin, the
+following command will be sent the configured tmux pane:
+>
+ rspec spec/models/foo_bar.rb
+<
+
+REPEATING *turbux-repeating*
+
+If you invoke the plugin (by default, with <leader>t), and neither the
+current file nor the alternate is a test, spec or feature, turbux will
+simply send the most recent command instead. This can be quite helpful
+in situations where you are editing a related file, or in the case of
+cucumber, step definitions or a view.
+
+The |turbux| and |turbux-focused| invocations each store their own
+command, so you can use the focused one elsewhere in a test suite while
+still setting the normal one, or vice-versa.
+
+
+FOCUSED *turbux-focused*
+
+Turbux also comes with bindings to run focused tests. This is
+accomplished by appending the current line number to the test command.
+In cucumber, this runs the scenario under the cursor. In rspec, this
+runs only the example or group under the cursor.
+
+The default mapping for focused test output is <leader>T.
+
+
+MAPPING *turbux-mappings*
+
+<Plug>SendTestToTmux Normal invocation
+<Plug>SendFocusedTestToTmux Focused test (appends line number)
+
+And the following are available unless "g:no_turbux_mappings" is set:
+
+<leader>t Normal invocation
+<leader>T Focused test (appends line number)
+
+ vim:tw=78:et:ft=help:norl:
@@ -0,0 +1,103 @@
+" turbux.vim - Turbo Ruby tests with tmux
+" Author: Joshua Davey <http://joshuadavey.com/>
+" Version: 1.0
+
+" Install this file to plugin/turbux.vim.
+" Relies on the following plugins:
+" - tslime.vim
+" - rails.vim
+
+if exists('g:loaded_turbux') || &cp || v:version < 700
+ finish
+endif
+let g:loaded_turbux = 1
+
+function! s:first_readable_file(files) abort
+ let files = type(a:files) == type([]) ? copy(a:files) : split(a:files,"\n")
+ for file in files
+ if filereadable(rails#app().path(file))
+ return file
+ endif
+ endfor
+ return ''
+endfunction
+
+function! s:prefix_for_test(file)
+ if a:file =~# '_spec.rb$'
+ return "rspec "
+ elseif a:file =~# '_test.rb$'
+ return "ruby -Itest "
+ elseif a:file =~# '.feature$'
+ return "cucumber "
+ endif
+ return ''
+endfunction
+
+function! s:alternate_for_file(file)
+ let related_file = ""
+ if exists('g:autoloaded_rails')
+ let alt = s:first_readable_file(rails#buffer().related())
+ if alt =~# '.rb$'
+ let related_file = alt
+ endif
+ endif
+ return related_file
+endfunction
+
+function! s:command_for_file(file)
+ let executable=""
+ let alternate_file = s:alternate_for_file(a:file)
+ if s:prefix_for_test(a:file) != ''
+ let executable = s:prefix_for_test(a:file) . a:file
+ elseif alternate_file != ''
+ let executable = s:prefix_for_test(alternate_file) . alternate_file
+ endif
+ return executable
+endfunction
+
+function! s:send_test(executable)
+ let executable = a:executable
+ if executable == ''
+ if exists("g:tmux_last_command") && g:tmux_last_command != ''
+ let executable = g:tmux_last_command
+ else
+ let executable = 'echo "Warning: No command has been run yet"'
+ endif
+ endif
+ return Send_to_Tmux(" ".executable."\n")
+endfunction
+
+" Public functions
+function! SendTestToTmux(file) abort
+ let executable = s:command_for_file(a:file)
+ if executable != ''
+ let g:tmux_last_command = executable
+ endif
+ return s:send_test(executable)
+endfunction
+
+function! SendFocusedTestToTmux(file, line) abort
+ let focus = ":".a:line
+
+ if s:prefix_for_test(a:file) != ''
+ let executable = s:command_for_file(a:file).focus
+ let g:tmux_last_focused_command = executable
+ elseif exists("g:tmux_last_focused_command") && g:tmux_last_focused_command != ''
+ let executable = g:tmux_last_focused_command
+ else
+ let executable = ''
+ endif
+
+ return s:send_test(executable)
+endfunction
+
+" Mappings
+nnoremap <silent> <Plug>SendTestToTmux :<C-U>w \| call SendTestToTmux(expand('%'))<CR>
+nnoremap <silent> <Plug>SendFocusedTestToTmux :<C-U>w \| call SendFocusedTestToTmux(expand('%'), line('.'))<CR>
+
+if !exists("g:no_turbux_mappings")
+ nmap <leader>t <Plug>SendTestToTmux
+ nmap <leader>T <Plug>SendFocusedTestToTmux
+endif
+
+" vim:set ft=vim ff=unix ts=4 sw=2 sts=2:

0 comments on commit 4b52175

Please sign in to comment.