測試中阻斷Time

方法中的一個產生當時時間的方法

current_time = Time.new;
time = current_time.strftime('%y.%m.%d %H:%M')

這個是將時間戳轉換爲字符串

寫測試的時候需要阻斷這個時間
阻斷這個產生時間的方法用stub方法
Time.stub(:new).and_return(Time.mktime(2013,8,24,11,22))
stub阻斷的方法,and_return將這個值賦給這個阻斷的方法的返回值,

mktime()函數將時間參數轉換爲時間戳

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章