运行 使用 Ruby 2.0 的单元测试和没有 Gemfile 的 minitest 5.5

Run unit test with Ruby 2.0 and minitest 5.5 without Gemfile

我正在通过阅读编程Ruby来学习Ruby,并且有这个示例代码:

require_relative 'count_frequency'
require_relative 'words_from_string'
require 'test/unit'

class TestWordsFromString < Test::Unit::TestCase
  def test_empty_string
    assert_equal([], words_from_string(''))
    assert_equal [], words_from_string('   ')
  end

  def test_single_word
    assert_equal ['cat'], words_from_string('cat')
    assert_equal ['cat'], words_from_string('   cat   ')
  end

  def test_many_words
    assert_equal ['the', 'cat', 'sat', 'on', 'the', 'cat'],         words_from_string('the cat sat on the mat')
  end

  def test_ignore_punctuation
    assert_equal ['the', "cat's", 'mat'], words_from_string("the cat's mat")
  end
end

当我尝试 运行 时,发生错误: MiniTest::Unit::TestCase is now Minitest::Test. 更详细的错误信息:

我正在使用 ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]minitest (5.5.0, 5.4.3, 5.3.5, 4.3.2)。我搜索了一下,发现从minitest5.0开始,MiniTest::Unit::TestCase变成了Minitest::Test。但我无能为力,因为它在 gem 的源文件中。有人建议在 Gemfile 中需要 minitest 4.**,但我只是 运行ning 一些脚本。我想不需要 Gemfile 。而且我当然不想卸载 minitest5.**。那么有没有办法 运行 这个脚本与 minitest5.5 和 ruby 2.0?

测试应该仍然是 运行。我有相同的设置,即使出现该错误,测试也会执行。

→ ruby --verbose etl_test.rb 
MiniTest::Unit::TestCase is now Minitest::Test. From etl_test.rb:4:in `<main>'
Run options: --seed 61653

# Running:

....

Finished in 0.001316s, 3039.5137 runs/s, 3039.5137 assertions/s.

4 runs, 4 assertions, 0 failures, 0 errors, 0 skips

classyhacker:~/dev/github/exercism/ruby/etl  
→ rbenv versions
  system
  1.9.3-p448
  2.0.0-p451
  2.1.0
  2.1.1
  2.1.2
* 2.1.3 (set by RBENV_VERSION environment variable)
  jruby-1.7.8

classyhacker:~/dev/github/exercism/ruby/etl  
→ gem list | grep minitest
minitest (5.5.1, 5.4.3, 4.7.5)

我的测试看起来像

require 'minitest/autorun'
require_relative 'etl'

class TransformTest < MiniTest::Unit::TestCase

  def test_transform_one_value
    old = { 1 => ['A'] }
    expected = { 'a' => 1 }

    assert_equal expected, ETL.transform(old)
  end

require minitest/autorun 也是 ruby​​doc 中建议的方式 http://ruby-doc.org/stdlib-2.0.0/libdoc/minitest/rdoc/MiniTest.html