我知道如何指定对象不应该收到特定的消息:
expect(File).to_not receive(:delete)
我如何指定它根本不应该收到任何消息?就像是
expect(File).to_not receive_any_message
我知道如何指定对象不应该收到特定的消息:
expect(File).to_not receive(:delete)
我如何指定它根本不应该收到任何消息?就像是
expect(File).to_not receive_any_message
听起来你只想用一个没有预期的双重替换有问题的对象(所以任何方法调用都会导致错误)。在你的确切情况下,你可以做到
stub_const("File", double())
我不确定用例是什么。但以下是我能想出的唯一直接答案:
methods_list = File.public_methods # using 'public_methods' for clarity
methods_list.each do |method_name|
expect(File).to_not receive(method_name)
end
如果你想要涵盖所有方法(即不仅仅是 public
那些):
# readers, let me know if there is a single method to
# fetch all public, protected, and private methods
methods_list = File.public_methods +
File.protected_methods +
File.private_methods