├── .gitignore ├── README.mdown ├── doc └── turbux.txt └── plugin └── turbux.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /README.mdown: -------------------------------------------------------------------------------- 1 | Turbux is designed to speed up your TDD cycle by using a single key 2 | mapping to run the most relevant test based on the current file in vim. 3 | It uses tmux's scriptability to send commands to a chosen pane in your 4 | tmux session. 5 | 6 | For more information, see the documentation. 7 | 8 | 9 | Dependencies 10 | ------------ 11 | 12 | This plugin depends on [vim-dispatch][7], [tslime.vim][1], [vim-tmux-runner][8], or [vimux][2], 13 | whichever is available, and becomes really awesome when used with 14 | [rails.vim][3]. It also makes the assumption that you're using tmux. 15 | 16 | **Note:** Due to a bug in the original tslime.vim plugin, please use 17 | [my fork][4]. 18 | 19 | 20 | Installation 21 | ------------ 22 | 23 | Use [pathogen][5] or [vundle][6]. 24 | 25 | [1]: https://github.com/jgdavey/tslime.vim 26 | [2]: https://github.com/benmills/vimux 27 | [3]: https://github.com/tpope/vim-rails 28 | [4]: https://github.com/jgdavey/tslime.vim 29 | [5]: https://github.com/tpope/vim-pathogen 30 | [6]: https://github.com/gmarik/vundle 31 | [7]: https://github.com/tpope/vim-dispatch 32 | [8]: https://github.com/christoomey/vim-tmux-runner 33 | -------------------------------------------------------------------------------- /doc/turbux.txt: -------------------------------------------------------------------------------- 1 | *turbux.txt* Turbo Ruby tests with tmux 2 | 3 | Author: Joshua Davey 4 | License: Same terms as Vim itself (see |license|) 5 | 6 | This plugin is only available if 'compatible' is not set. 7 | 8 | This plugin can optionally be used with tslime.vim or vimux, whichever 9 | is available, from within a tmux session. 10 | 11 | It also depends optionally on rails.vim. 12 | 13 | INTRODUCTION *turbux* 14 | 15 | Turbux is designed to speed up your TDD cycle by using a single key 16 | mapping to run the most relevant test based on the current file in vim. 17 | With either tslime or vimux, it uses tmux's scriptability to send 18 | commands to a chosen pane in your tmux session. 19 | 20 | The default mapping for invoking the plugin is t. In a spec 21 | file, this will run "rspec ". In a test-unit file, this will 22 | run "ruby -Itest ". In a cucumber feature file, this will run 23 | "cucumber ". 24 | 25 | If rails.vim is present, some additional niceties are provided. When 26 | rails.vim can find an alternate file for the current one, and that file 27 | is a spec or test, it will run the alternate file rather than the one 28 | you are in. For example, given the following two files: 29 | > 30 | app/models/foo.rb 31 | spec/models/foo_bar.rb 32 | < 33 | When the current file and is "foo.rb" and you invoke the plugin, the 34 | following command will be sent the configured tmux pane: 35 | > 36 | rspec spec/models/foo_bar.rb 37 | < 38 | Note: this plugin does not work well with |autochdir|. The working 39 | directories for the target pane and vim should match. 40 | 41 | 42 | REPEATING *turbux-repeating* 43 | 44 | If you invoke the plugin (by default, with t), and neither the 45 | current file nor the alternate is a test, spec or feature, turbux will 46 | simply send the most recent command instead. This can be quite helpful 47 | in situations where you are editing a related file, or in the case of 48 | cucumber, step definitions or a view. 49 | 50 | The |turbux| and |turbux-focused| invocations each store their own 51 | command, so you can use the focused one elsewhere in a test suite while 52 | still setting the normal one, or vice-versa. 53 | 54 | 55 | FOCUSED *turbux-focused* 56 | 57 | Turbux also comes with bindings to run focused tests. This is 58 | accomplished by appending the current line number to the test command. 59 | In cucumber, this runs the scenario under the cursor. In rspec, this 60 | runs only the example or group under the cursor. 61 | 62 | The default mapping for focused test output is T. 63 | 64 | 65 | CONFIGURATION *turbux-config* 66 | 67 | Turbux attempts to intelligently determine the most appropriate test 68 | runner based on loaded plugins. You can manually set the test runner 69 | with the following setting: 70 | > 71 | let g:turbux_runner = 'vim' " default: vimux OR tslime OR vim 72 | > 73 | Use the following in your vimrc to set a common command prefix for prepending 74 | all commands: 75 | > 76 | let g:turbux_command_prefix = 'bundle exec' " default: (empty) 77 | < 78 | You can also choose your own commands for each test framework. A command use 79 | case is to use 'spec' instead of 'rspec' for older versions of RSpec. 80 | > 81 | let g:turbux_command_rspec = 'spec' " default: rspec 82 | let g:turbux_command_test_unit = 'ruby' " default: ruby -Itest 83 | let g:turbux_command_cucumber = 'cucumber' " default: cucumber -rfeatures 84 | let g:turbux_command_turnip = 'rspec' " default: rspec -rturnip 85 | let g:turbux_command_teaspoon = 'teaspoon' " default: teaspoon 86 | < 87 | You can implement a custom test runner. The following is one such example: 88 | > 89 | let g:turbux_custom_runner = 'TurbuxCustomRunner' " default: (unset) 90 | function! TurbuxCustomRunner(command) 91 | call VimuxRunCommand("shrink") 92 | call VimuxClearRunnerHistory() 93 | return VimuxRunCommand(a:command) 94 | endfunction 95 | < 96 | MAPPING *turbux-mappings* 97 | 98 | SendTestToTmux Normal invocation 99 | SendFocusedTestToTmux Focused test (appends line number or named 100 | test) 101 | 102 | And the following are available unless "g:no_turbux_mappings" is set: 103 | 104 | t Normal invocation 105 | T Focused test 106 | 107 | To use custom mappings, you can put something like the following in your 108 | vimrc: 109 | > 110 | let g:no_turbux_mappings = 1 111 | map rt SendTestToTmux 112 | map rT SendFocusedTestToTmux 113 | < 114 | 115 | vim:tw=78:et:ft=help:norl: 116 | -------------------------------------------------------------------------------- /plugin/turbux.vim: -------------------------------------------------------------------------------- 1 | " turbux.vim - Turbo Ruby tests with tmux 2 | " Author: Joshua Davey 3 | " Version: 1.0 4 | 5 | " Install this file to plugin/turbux.vim. 6 | " Relies on the following plugins: 7 | " - tslime.vim or vimux 8 | " - rails.vim 9 | 10 | if exists('g:loaded_turbux') || &cp || v:version < 700 11 | finish 12 | endif 13 | let g:loaded_turbux = 1 14 | 15 | " Default Settings {{{1 16 | function! s:turbux_command_setting(name, default_value) 17 | let name = 'g:turbux_command_'.a:name 18 | if !exists(name) 19 | exec ':let '.name.'= "'.a:default_value.'"' 20 | endif 21 | endfunction 22 | 23 | call s:turbux_command_setting("teaspoon", "teaspoon") 24 | call s:turbux_command_setting("rspec", "rspec") 25 | call s:turbux_command_setting("test_unit", "ruby -Itest") 26 | call s:turbux_command_setting("turnip", "rspec -rturnip") 27 | call s:turbux_command_setting("cucumber", "cucumber") 28 | call s:turbux_command_setting("prefix", "") 29 | call s:turbux_command_setting("elixir_test", "mix test") 30 | call s:turbux_command_setting("elixir_spec", "mix espec") 31 | " }}}1 32 | 33 | " Utility {{{1 34 | " 35 | function! s:has_rails_vim() 36 | return exists('g:autoloaded_rails') && !empty(rails#buffer()) && !empty(rails#app()) 37 | endfunction 38 | 39 | function! s:filereadable(filename) 40 | let f = a:filename 41 | if s:has_rails_vim() 42 | let f = rails#app().path(f) 43 | endif 44 | return filereadable(f) 45 | endfunction 46 | 47 | function! s:first_readable_file(files) abort 48 | let files = type(a:files) == type([]) ? copy(a:files) : split(a:files,"\n") 49 | for file in files 50 | if s:filereadable(file) 51 | return file 52 | endif 53 | endfor 54 | return '' 55 | endfunction 56 | 57 | function! s:add(array, string) 58 | if type(a:string) == type("") && !empty(a:string) 59 | call add(a:array, a:string) 60 | endif 61 | endfunction 62 | 63 | " helper methods to find and parse test names in quotes 64 | function! s:gsub(str,pat,rep) 65 | return substitute(a:str,'\v\C'.a:pat,a:rep,'g') 66 | endfunction 67 | 68 | function! s:shellescape(str) 69 | return s:gsub(s:gsub(s:gsub(a:str, '"', '\\"'), "'", "\\\\'"), '!', '\\!') 70 | endfunction 71 | " }}}1 72 | 73 | " Test running {{{1 74 | function! s:prefix_for_test(file) 75 | if a:file =~# '_spec.rb$' 76 | return g:turbux_command_rspec 77 | elseif a:file =~# '_spec.\(coffee\|js\)$' 78 | return g:turbux_command_teaspoon 79 | elseif a:file =~# '\(\ SendTestToTmux :w \| call SendTestToTmux(expand('%')) 300 | nnoremap SendFocusedTestToTmux :w \| call SendFocusedTestToTmux(expand('%'), line('.')) 301 | 302 | if !exists("g:no_turbux_mappings") 303 | nmap t SendTestToTmux 304 | nmap T SendFocusedTestToTmux 305 | endif 306 | "}}}1 307 | 308 | 309 | " vim:set ft=vim ts=4 sw=2 sts=2: 310 | --------------------------------------------------------------------------------