2010-06-12 40 views
0

我是Ruby測試的新品,Google沒有幫助。Ruby測試:在測試用例中打印

使用測試/股,我怎麼能打印實例變量,就像

test "thing to happen" do 
    do_stuff 
    assert_equal "foo", @variable 
    p @varible 
end 
+3

該代碼應該輸出@variable到控制檯,除非斷言失敗。你的問題到底是什麼? – flitzwald 2010-06-12 06:39:34

+0

是測試用例還是被測對象中的實例變量? – BaroqueBobcat 2010-06-12 07:24:56

回答

1

紅寶石asserts可以輸出信息到測試運行控制檯:

test "thing to happen" do 
    do_stuff 
    assert_equal "foo", @variable, "@variable is #{@variable} when: things to happen" 
    p @varible 
end