如何使Ruby Mocha模拟仅检查一个参数

问题描述 投票:0回答:1

我想模拟此功能:

def self.set_segment_info(segment_info, history_record)
  history_record.segment_info = segment_info
end

在我的测试中,我想要一个仅能确认我以期望值调用set_segment_info的模拟程序。我不在乎我为history_record传递的内容。

我将如何做?我尝试过

SegmentHistoryRecord.expects(:set_segment_info).with(:segment_info => expected_segment_info, :history_record => anything)

但是那不起作用。

ruby unit-testing mocking automated-tests mocha
1个回答
0
投票
SegmentHistoryRecord.expects(:set_segment_info).with() do |param1, param2|
  # change below to your verification for :segment_info
  # and leave param2 doing nothing, the expectation will ignore param2
  param1 == expected_segment_info
end
© www.soinside.com 2019 - 2024. All rights reserved.