我正在从rspec中拓展业务,进入MiniTest和shoulda。我不知道该怎么用测试方法.
class TestKata < MiniTest::Test
context 'Kata#n00bify' do
should 'replace "to" and "too" with the number 2, even if
they are only part of a word (E.g. today = 2day)' do
assert_equal '2', Kata.n00bify('too')
assert_equal '2', Kata.n00bify('too')
assert_equal '2day', Kata.n00bify('today')
end
should 'replace "for" and "fore" with the number 4' do
assert_equal '4', Kata.n00bify('for')
assert_equal '4', Kata.n00bify('fore')
end
# ...
end
end以下是测试结果:
失败: TestKata#test_:Kata#n00bify应该用数字4. /./test_n00b.rb:31 Minitest::断言:预期:"4“实际:零失败: TestKata#test_:Kata#n00bify应该将"to”和“of”替换为数字4。/./test_n00b.rb:31 Minitest::Expected:“4”实际:零失败:TestKata#test_:Kata#n00bify应该用数字2替换“to”和"too“,即使它们只是单词的一部分(例如今天=2天)。/./test_n00b.rb:25 Minitest::断言:预期:"2“实际:零
我不明白的是--测试方法在哪里?注意测试结果中它的TestKata#test_<nothing>:。在我看来很丑。希望它的阅读只是与肩的上下文。ie:
失败: Kata#n00bify应该..。
我遗漏了什么?感谢你的帮助!
发布于 2015-11-20 08:58:31
Shoulda为使用should块定义测试方法提供了另一种语法。Minitest要求测试方法名从字符串"test_"开始,因此Shoulda使用该约定为每个块动态定义方法。当您编写类似于should "foo"的东西时,您将得到一个名为test_: TestClassName#foo的测试方法。
至于输出,有大量的宝石实现交替格式设置。你可以试着看看最小的记者,这是其中最全面和最好的维护。
https://stackoverflow.com/questions/33815630
复制相似问题