【发布时间】:2015-11-19 22:36:20
【问题描述】:
我正在从 rspec 分支出来,进入 MiniTest 和 shoulda。我无法弄清楚测试方法如何与 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
以下是测试结果:
Failure: TestKata#test_: Kata#n00bify should replace "for" and "fore" with the number 4. [/.../test_n00b.rb:31] Minitest::Assertion: Expected: "4" Actual: nil Failure: TestKata#test_: Kata#n00bify should replace "to" and "too" with the number 2, even if they are only part of a word (E.g. today = 2day). [/.../test_n00b.rb:25] Minitest::Assertion: Expected: "2" Actual: nil
我不明白的是——测试方法在哪里?请注意测试结果中的TestKata#test_<nothing>:。在我看来很难看。很想用应该的上下文来阅读它。即:
Failure: Kata#n00bify should ...
我错过了什么?感谢您的帮助!
【问题讨论】: