【发布时间】:2015-07-12 06:23:01
【问题描述】:
我是通过阅读 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.**,但我只是在运行一些脚本。我想不需要 Gemfile。而且我当然不想卸载 minitest5.**。那么有没有办法可以用 minitest5.5 和 ruby 2.0 运行这个脚本?
【问题讨论】:
标签: ruby unit-testing minitest