Ruby 在块期望之后调用原始实现

Ruby 在块期望之后调用原始实现,ruby,rspec,Ruby,Rspec,是否有可能从块匹配器调用原始实现 expect(object).to receive(:method) do |argument| expect(argument).to eql expected_value somehow_call_original_implementation_of_the_method end 当我使用和_call_original时,它会忽略块内参数的期望值,只需检查方法是否收到: expect(object).to receive(:method) do

是否有可能从块匹配器调用原始实现

expect(object).to receive(:method) do |argument|
  expect(argument).to eql expected_value

  somehow_call_original_implementation_of_the_method
end
当我使用
和_call_original
时,它会忽略块内参数的期望值,只需检查方法是否收到:

expect(object).to receive(:method) do |argument|
  expect(argument).to eql expected_value
end.and_call_original

为什么要用块调用
expect\u receive
?我认为这是为
allow_to_receive
保留的,其中块被用作方法的实现

在你的情况下,我想你可以把它改成这样:

expect(argument).to eql(expected_argument_value)
expect(object).to receive(:method).and_return(expected_value)
object.method