我试图测试两个类之间复杂的交互:
class Class1
def method1(obj2)
obj2.call1
obj2.call2
.... #calls that I don't care
obj2.call3(1)
end
end
我想写一个与此类似的rspec测试用例:
allow(mock_obj2).to receive_any_message!
expect(mock_obj2).to receive(:call3).with(1)
expect(mock_obj2).not_to receive(:call4)
换句话说,我希望我的测试用例只关注:call3和:call4,而忽略任何其他调用。
有可能吗?
答案 0 :(得分:2)
这应该有效:
mock_obj2 = double(:mock_obj2).as_null_object
expect(mock_obj2).to receive(:call3).with(1)
expect(mock_obj2).not_to receive(:call4)
Class1.new.method1(mock_obj2)