我最近嘗試磨礪我的rails技能使用這個工具:是否有針對ruby koans的補充指南/答案?
http://github.com/edgecase/ruby_koans
,但我有一些經過測試的麻煩。另外,我不確定自己是否正確地做了一些事情,因爲目標只是爲了通過測試,有很多方法可以通過測試,我可能正在做一些不符合標準的事情。
有沒有辦法確認我是否正確地做事?
一個具體的例子:
在about_nil,
def test_nil_is_an_object
assert_equal __, nil.is_a?(Object), "Unlike NULL in other languages"
end
所以它告訴我,以檢查是否該第二子句是等於一個對象(所以我可以說零是一個對象)或僅把assert_equal true, nil.is_a?(Object)
,因爲聲明是真實的?
和下一個測試:
def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
# What happens when you call a method that doesn't exist. The
# following begin/rescue/end code block captures the exception and
# make some assertions about it.
begin
nil.some_method_nil_doesnt_know_about
rescue Exception => ex
# What exception has been caught?
assert_equal __, ex.class
# What message was attached to the exception?
# (HINT: replace __ with part of the error message.)
assert_match(/__/, ex.message)
end
end
即時猜測我應該把在assert_match有關assert_equal「無方法錯誤」的字符串,但什麼?
有趣,不知道該koans,總得試一試。也許尋求幫助,或尋求你認爲不正確的事情的建議,但更具體的,會讓你更好的回答 – Chubas 2010-08-25 06:16:16