我正在Rails中使用Rspec测试一个ruby类
class VolumeAnalysis该类有一个调用活动记录的方法。
returned_volumes此方法从活动记录中抓取一组项,并返回如下内容:
[
<struct volumeAnalysis::Entry date="2019-12-03", volume=0.3864511633501078e4, predicted=0.143488366498922e3>,
<struct volumeAnalysis::Entry date="2019-12-04", volume=0.3699056933789016e4, predicted=0.165454699712062e3>,
....
....
....
.... ]我希望测试的类中的其他方法取决于这个方法,如何模拟这个方法返回值?
发布于 2019-12-03 22:04:48
试着做这样的事情:
allow(volume_analysis).to receive(:returned_volumes) { and_then_create_your_entry_structs_here }
def and_then_create_your_entry_structs_here
[VolumeAnalysis::Entry.new(DateTime.current, 0.123, 0.123)]
# this is quick and dirty - you'll have to create the Entry objects properly
endhttps://stackoverflow.com/questions/59165024
复制相似问题