2011-07-30 33 views
1

我在'artists_helpers'類中有這樣的代碼。如何使用rspec rails將參數傳遞到函數?

def round_to(x) 
    (self * 10**x).round.to_f/10**x 
end 

同樣,在artist_helper_spec.rb中,我有這樣的代碼。

describe ArtistsHelper do 
    it "should return a two digits after decimal" do 
    mock=12.234 
    mock.round_to(2).should == 12.23 
    end 
end 

如何編寫腳本使該功能可以測試。

問題是,在運行rspec測試時,我沒有在助手中獲得':self'變量的值。

是否有其他有用的鏈接?

+0

我不明白的價值:rspec的運行測試時,在輔助變數, '自我'。 – Gagan

回答

1

ArtistHelper.round_to(2)。應該== 12.23

相關問題