ruby-on-rails – 如何期望在Rails中使用某些参数将消息发送到任
发布时间:2020-12-16 21:07:43 所属栏目:百科 来源:网络整理
导读:退款时,我们需要停用附有该订单的连续出版物.在规范中,订单有两个连续出版物,我必须要求对API进行两次调用,以便停用序列号. 我试过了: expect_any_instance_of(Gateway).to receive(:deactivate_dongle).once.with(serial_number: '67890')expect_any_insta
退款时,我们需要停用附有该订单的连续出版物.在规范中,订单有两个连续出版物,我必须要求对API进行两次调用,以便停用序列号.
我试过了: expect_any_instance_of(Gateway).to receive(:deactivate_dongle).once.with(serial_number: '67890') expect_any_instance_of(Gateway).to receive(:deactivate_dongle).once.with(serial_number: '12345') 这给了我: The message 'deactivate_dongle' was received by #<Gateway:70179265658480 @connection=#<Faraday::Connection:0x007fa7c4667b28>> but has already been received by #<Gateway:0x007fa7c6858160> 同样的: expect_any_instance_of(Gateway).to receive(:deactivate_dongle).with(serial_number: '12345') expect_any_instance_of(Gateway).to receive(:deactivate_dongle).with(serial_number: '67890') 我怎样才能做到这一点? 解决方法
如果你可以改变你的实现来对已知的Gateway实例做出预期(为了避免expect_any_instance_of),你可以使用rspec的
ordered 方法来添加接收消息的约束.
我担心在你的情况下你应该尝试添加一个规范,其中只涉及其中一个系列,所以你可以正确地期望它.例如 expect_any_instance_of(Gateway).to receive(:deactivate_dongle).once.with(serial_number: '67890') 然后有一个带有n个连续出版物的规范,并且只需要将deactivate_dongle调用n次. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |