Pithikos
Pithikos

Reputation: 20300

Does minitest provide a "test" directive?

In Rails I can use the test keyword for my tests which I find very attractive and a bettter choice to Rspec's verbosity.

Example:

class TestMyClass < ActionController::TestCase
  test 'one equals one' do
    assert 1 == 1
  end
end

At the moment I am creating a gem and I want to follow the same way for my tests - by using the test method. I tried inheriting from Minitest and UnitTest and the latter seems to work. However I was under the impression that Rails uses Minitest. So does Minitest actually provide a test directive?

This works:

class TestMyClass < Test::Unit::TestCase
  test 'one equals one' do
    assert 1 == 1
  end
end

This gives me "wrong number of arguments for test":

class TestMyClass < Minitest:Test
  test 'one equals one' do
    assert 1 == 1
  end
end

Upvotes: 1

Views: 51

Answers (1)

kolomeetz
kolomeetz

Reputation: 21

No, Minitest runs ordinary methods with names started from 'test_'.

Method test from ActionController::TestCase is provided by Rails and works as a simple wrap for 'test_*' methods. It converts this

test 'truish' do
  assert true
end

to this

def test_truish
  assert true
end

Also it checks if the body of the test was defined, if it wasn't, it will show an error message.

Upvotes: 2

Related Questions