2012-03-03 60 views
0

背景:所以我有大約(Ruby on Rails的應用程序)我可以使用什麼RSpec的方式對這一要求

class A 
    def calculate_input_datetimes 
     # do stuff to calculate datetimes - then for each one identified 
     process_datetimes(my_datetime_start, my_datetime_end) 
    end 

    def process_datetimes(input_datetime_start, input_datetime_end) 
     # do stuff 
    end 
end 

所以:

  • 我想測試calculate_input_datetimes算法正在 和計算正確的日期時間傳遞給process_datetimes
  • 我知道我可以存根process_datetimes所以它的代碼不會被 參與測試的

問題:我怎樣才能設置但是RSpec的測試,所以我可以明確 測試正確datestimes已嘗試傳遞到 process_datetimes,所以對於一個給定的規範測試process_datetimes是 所謂三( 3)次,通過以下參數說:

  • 2012-03-03T00:00:00 + 00:00,2012-03-09T23:59:59 + 00:00
  • 2012-03- 10T00:00:00 + 00:00,2012-03-16T23:59:59 + 00:00
  • 2012-03-17T00:00:00 + 00:00,2012-03-23T23:59:59 + 00:00

感謝

回答

1

聽起來好像要should_receive和指定參數是什麼使用with預期,例如

a.should_receive(:process_datetimes).with(date1,date2) 
a.should_receive(:process_datetimes).with(date3,date4) 
a.calculate_input_datetimes 

有在docs更多的例子,例如,你可以使用.ordered如果這些調用的順序是非常重要的

相關問題