在Rails中,我可以在测试中使用test关键字,我发现这个关键字非常吸引人,比起Rspec的冗长,它是一个更好的选择。
示例:
class TestMyClass < ActionController::TestCase
test 'one equals one' do
assert 1 == 1
end
end目前,我正在创建一个gem,我想在我的测试中遵循同样的方法--使用test方法。我尝试从Minitest和UnitTest继承,后者似乎起作用了。然而,我的印象是Rails使用Minitest。那么Minitest真的提供了test指令吗?
这是可行的:
class TestMyClass < Test::Unit::TestCase
test 'one equals one' do
assert 1 == 1
end
end这给了我“错误的测试参数数量”:
class TestMyClass < Minitest:Test
test 'one equals one' do
assert 1 == 1
end
end发布于 2016-07-13 23:06:39
不,Minitest运行的是名称以'test_‘开头的普通方法。
来自ActionController::TestCase的方法test是由Rails提供的,作为'test_*‘方法的简单包装。它将这个转换为
test 'truish' do
assert true
end到这个
def test_truish
assert true
end它还检查是否定义了测试的主体,如果没有定义,它将显示一条错误消息。
https://stackoverflow.com/questions/38352823
复制相似问题