所以我在我的應用程式中有一個重試規則。我想用rspec來測驗一下。
當我呼叫服務而不傳遞帳戶ID時,它應該給我false,而當傳遞帳戶ID時,它應該給我true。
我正在嘗試這樣的代碼
options = {
email: '[email protected]'/span>
}
expect_any_instance_of(PaymentService::CreatePayment).to receive(:call)
.with(options)
.and_return(false)
options[:account_id] = 12345。
expect_any_instance_of(PaymentService::CreatePayment).to receive(:call)
.with(options)
.and_return(true)
但是這對我來說不起作用。
uj5u.com熱心網友回復:
嘗試重新寫成:
invalid_options = {
email: '[email protected]'/span>
}
expect_any_instance_of(PaymentService::CreatePayment).to receive(:call)
.with(invalid_options)
.and_return(false)
valid_options = {
電子郵件: '[email protected]'。
account_id: 12345,
}
expect_any_instance_of(PaymentService::CreatePayment).to receive(:call)
.with(valid_options)
.and_return(true)
uj5u.com熱心網友回復:
所以我想出了一個方法來做這件事。
expect_any_instance_of(PaymentService::CreatePayment).to receive(:call). twice do |_, _, options|
options[:account_id].present? ? true : false ?
結束。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/313830.html
標籤:
上一篇:bundleupdate--conservativedevise不更新,只更新"devise"寶石。
下一篇:如何用CSS隱藏按鈕文本?
