Ruby unittest error: "you should require" minitest / autorun "instead."

I have a very simple unit test, which I copied from http://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing .

require_relative "simple_number"
require "test/unit"

class TestSimpleNumber < Test::Unit::TestCase

    def test_simple
        assert_equal(4, SimpleNumber.new(2).add(2) )
        assert_equal(6, SimpleNumber.new(2).multiply(3) )
    end

end

Running this code causes an error:

Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
  /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:3:in `<top (required)>'
  tc_simple_number.rb:5:in `<main>'
MiniTest::Unit::TestCase is now Minitest::Test. From /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit/testcase.rb:8:in `<module:Unit>'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:670:in `<class:Runner>': undefined method `_run_suite' for class `Test::Unit::Runner' (NameError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:255:in `<module:Unit>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:9:in `<module:Test>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:8:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from tc_simple_number.rb:5:in `<main>'

What could be wrong?

+2
source share
1 answer

Test :: Unit :: TestCase is deprecated in favor of Minitest :: Test. If you want your example to work, you need to change a few things:

  • replace require "test/unit"withrequire "minitest/autorun"
  • replace Test::Unit::TestCase withwithMinitest::Test
+8
source

Source: https://habr.com/ru/post/1620405/


All Articles