2016-08-21 31 views
0

時候當我使用的失敗ActiveSupport::TestCase測試顯示BigDecimal的數量爲人類可讀顯示的消息是這樣的:如何使用的ActiveSupport :: TestCase的

2) Failure: 
ArrayTest#test_example [/Users/ironsand/dev/my_project/test/core_ext/array_test.rb:6]: 
--- expected 
+++ actual 
@@ -1 +1 @@ 
-#<BigDecimal:7fb947c749a0,'0.94E0',9(18)> 
+#<BigDecimal:7fb947c7f5a8,'0.95E0',9(45)> 

我想說明,而不是<BigDecimal:7fb947c749a0,'0.94E0',9(18)>0.94。 在rails cosole或pry中,我使用的是awesome_print

有沒有辦法激活awesome_print作爲測試結果? 我不堅持使用awesome_print,如果有另一種方式來顯示數字更具可讀性,我會很高興地使用它。

回答

0

你可以添加一條消息,斷言語句

message = "Expected #{expected_number.to_f} but actual number is #{actual_number.to_f}" 
assert_equal expected_number, actual_number, message 

而且,你沒問這個,但如果你想比較兩個小數,你可能想使用assert_in_delta地看到,這些數字很接近而非確切。

相關問題