Adam Zerner
Adam Zerner

Reputation: 19178

How can you have nested tests with Minitest?

For example, in Jasmine, you can do this:

describe('Person', function () {
  describe('movement methods', function () {
    it('#run', function () {

    });
    it('#jump', function () {

    });
  });
});

With Minitest, it seems that you can't have a "movement methods" category. You'd have to just do:

class PersonTest
  def test_run
  end

  def test_jump
  end
end

Is there a way to nest in Minitest?

Upvotes: 6

Views: 3442

Answers (1)

jdgray
jdgray

Reputation: 1983

Yes you can. You can do something like this (not the prettiest):

class Person < ActiveSupport::TestCase
  class MovementMethods < ActiveSupport::TestCase
    test "#run" do
      # something
    end

    test "#jump" do
      # something
    end
  end
end

Also consider using minitest/spec and you can write your tests cases more comparable to the Jasmine snippet:

require 'minitest/spec'

describe Person do
  describe 'movement methods' do
    it '#run' do
      # something
    end

    it '#jump' do
      # something
    end
  end
end

Upvotes: 7

Related Questions