Skip to content
Michael Guterl edited this page Aug 16, 2016 · 13 revisions

Running individual tests

It's difficult to run individual tests with Minitest, because it doesn't accept line numbers (like RSpec), it only accepts regexes and test names. Test.vim, however, polyfills this limitation by parsing the file to determine which test is the closest to your cursor, and constructs a regex.

All of the Minitest syntaxes are supported:

  • Classic unit syntax

    class MathTest < Minitest::Test
      def test_addition
        assert_equal 2, 1 + 1
      end
    end
    :TestNearest
    => ruby -I test math_test.rb --name '/MathTest#test_addition/'
    
  • Rails' unit syntax

    class MathTest < ActiveSupport::TestCase
      test "addition" do
        assert_equal 2, 1 + 1
      end
    end
    :TestNearest
    => ruby -I test math_test.rb --name '/MathTest#test_addition/'
    
  • Classic spec syntax

    describe "Math" do
      it "adds numbers" do
        (1 + 1).must_equal 2
      end
    end
    :TestNearest
    => ruby -I test math_test.rb --name '/Math#test_\d+_adds numbers/'
    
  • Explicit spec syntax

    class MathTest < Minitest::Spec
      it "adds numbers" do
        (1 + 1).must_equal 2
      end
    end
    :TestNearest
    => ruby -I test math_test.rb --name '/MathTest#test_\d+_adds numbers/'
    

Detecting the executable

Test.vim's Minitest wrapper chooses the executable using the following logic:

  1. If you have a Rakefile with a Rake::TestTask defined, or you're using Rails, then
  2. if .zeus.sock is detected run zeus rake test,
  3. otherwise if bin/rake is present, run bin/rake,
  4. otherwise if Gemfile is present, run bundle exec rake,
  5. otherwise run rake.
  6. If Rakefile is not present, then
  7. if Gemfile is present, run bundle exec ruby -I test,
  8. otherwise run ruby -I test.

Whether or not you're using Rake for running your Minitest suite, Test.vim goes to great lengths to provide the same experience.

rake improvements

When using Rake, it's really difficult to pass test options. Luckily, test.vim has solved that problem for you:

:TestFile --seed 1234
=> rake test TEST="your_file_test.rb" TESTOPTS="--seed=1234"

ruby -I test improvements

When not using Rake, it's really difficult to run the whole test suite. Test.vim has got your back here as well:

:TestSuite
=> ruby -I test -e 'Dir["./test/**/*_test.rb"].each &method(:require)'

M runner

If you want test.vim to use M for running tests, you can set the executable:

let g:test#ruby#minitest#executable = 'm'