/vim-minitest

Primary LanguageVim ScriptOtherNOASSERTION

Minitest.vim

This is a Minitest adaptation of Rspec.vim from thoughtbot.

NOTE: 2016-02-21: I think minitest-line makes this plugin obsolete.

The entire reason for this plugin that was rspec allowed single tests to be run by line number (e.g., cursor position, which Rspec.vim provides) while minitest required a method name.

Installation

Recommended installation with vundle:

Bundle 'spellman/vim-minitest'

Running all tests is achieved via running /test/test_helper.rb, which should require all tests. I used the following code in test_helper.rb from the CrashRuby blog. Note this assumes that vim's working directory is the project root.

require "minitest/autorun"
require "bundler/setup"

if __FILE__ == $0
  $LOAD_PATH.unshift "lib", "test"
  Dir.glob("./test/**/test_*.rb") { |f| require f }
end

As per Rspec.vim, if using zsh on OS X it may be necessary to run move /etc/zshenv to /etc/zshrc.

Example of key mappings

" Minitest.vim mappings
nmap <Leader>t <Plug>vim-minitest#RunCurrentTestFile
nmap <Leader>s <Plug>vim-minitest#RunNearestTest
nmap <Leader>l <Plug>vim-minitest#RunLastTest
nmap <Leader>a <Plug>vim-minitest#RunAllTests

Configuration

Overwrite g:minitest_command variable to execute a custom command.

Example:

let g:minitest_command = "!ruby -Itest {test}"