All Projects → gabebw → vim-spec-runner

gabebw / vim-spec-runner

Licence: other
🏃 An efficient and intelligent spec runner for RSpec and JS unit tests

Programming Languages

ruby
36898 projects - #4 most used programming language
Vim Script
2826 projects

Vim-spec-runner Build Status

An efficient and intelligent spec runner for Vim.

vim-spec-runner automatically detects the test type. It can run tests using any external command dispatcher (like vim-dispatch). It should Just Work (TM) for most of the workflows and configurations you use each day.

It can run RSpec files or JavaScript files (with Teaspoon).

Benefits

  • Has commands to run a single test case, run a whole spec file, or re-run the last spec command
  • If you're editing a non-spec file and you run vim-spec-runner, it automatically falls back to running the most recent spec
  • Simple to use with any external command dispatcher, including Tmux ones like vim-tmux-runner or tslime
  • Automatically detects and uses preloaders (zeus and spring)
  • Saves the current file before running specs

Installation

With vundle:

Plugin 'gabebw/vim-spec-runner'

Usage

Commands

There are three commands in the public API:

  • :RunCurrentSpecFile runs the entire current spec file, or if not in a spec file, re-runs the most recent command
  • :RunFocusedSpec runs the current line in a spec, or if not in a spec file, re-runs the most recent command
  • :RunMostRecentSpec re-runs the most recent command

All three commands use the g:spec_runner_dispatcher variable, which is explained in the "Configuration" section.

Custom mappings

To create your own custom mappings, we've defined mapping placeholders (<Plug> maps) for each of the commands to make mapping easy.

" Use <Leader>t to run the current spec file.
map <Leader>t <Plug>RunCurrentSpecFile

" Use <Leader>u to run the current line in a spec.
map <Leader>u <Plug>RunFocusedSpec

" Use <Leader>v to explicitly run the most recent spec.
map <Leader>v <Plug>RunMostRecentSpec

You must use map when you define your mappings. Note that for Magical Vim Reasons, even though you're typing map, it's a normal-mode mapping.

Configuration

The g:spec_runner_dispatcher variable is used by all three public commands to run specs. By default, it echoes the command and then runs it:

" Default mapping. Echo the commmand then run it:
let g:spec_runner_dispatcher = '!echo "{command}" && {command}'

{command} is a placeholder and will be replaced with the actual command to run.

You can configure this plugin to run the spec command with your dispatcher of choice:

" Using vim-tmux-runner:
let g:spec_runner_dispatcher = 'call VtrSendCommand("{command}")'

" Using tslime.vim:
let g:spec_runner_dispatcher = 'call Send_to_Tmux("clear\n{command}\n")'

" Using vim-dispatch
let g:spec_runner_dispatcher = 'Dispatch {command}'

By default, the plugin will :write the spec file before running it. To disable that:

let g:disable_write_on_spec_run = 1

This plugin will try to automatically determine your preloader (spring or zeus). Sometimes you need to override it, which you can do by setting g:spec_runner_preloader:

let g:spec_runner_preloader = './bin/spring'
" Or disable preloading entirely:
let g:spec_runner_preloader = ''

Running the plugin's tests

bundle exec rake

If you get errors on OSX about Vimrunner, try installing MacVim then re-running the specs:

$ brew install macvim
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].