如何测试外部休息呼叫两次?
我正在编写RSPEC测试用例。我想测试用正确的有效载荷两次调用外部端点。但是我似乎找不到解决问题的方法。
client = RealExternalAPI.new
expect_any_instance_of(HTTP::Client).to(
receive(:post).and_return(fake_api_response(status: 200))
)
expect_any_instance_of(HTTP::Client).to(
receive(:post).and_return(fake_api_response(status: 200))
)
client.post_call(payload: 1)
client.post_call(payload: 2)
这是一个错误消息:
The message 'post' was received by #<HTTP::Client:2282816320 @default_options=#<HTTP::Options:0x0000000110220f40>, @connection=, @state=clean> but has already been received by #<HTTP::Client:0x0000000110223ee8>
I am writing RSpec test cases. I would like to test that an external endpoint has been called twice with the correct payload. But I can't seem to find a solution to my problem.
client = RealExternalAPI.new
expect_any_instance_of(HTTP::Client).to(
receive(:post).and_return(fake_api_response(status: 200))
)
expect_any_instance_of(HTTP::Client).to(
receive(:post).and_return(fake_api_response(status: 200))
)
client.post_call(payload: 1)
client.post_call(payload: 2)
Here is an error message:
The message 'post' was received by #<HTTP::Client:2282816320 @default_options=#<HTTP::Options:0x0000000110220f40>, @connection=, @state=clean> but has already been received by #<HTTP::Client:0x0000000110223ee8>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用RSPEC消息期望接收计数验证呼叫计数的助手
You can use RSpec Message expectations Receive counts helper to verify the call count