上下文:
我有一项工作,捕捉这些配置的一些错误
class CheckBankStatusJob < BaseJob
discard_on(ConnectionErrors::Error) do
Logger.new(STDOUT).warn("Connection Error!")
end
retry_on(
BankError::NoResponseData,
StandardError,
wait: 5.seconds,
)
end
ConnectionErrors
继承自StandardError
BankError::NoResponseData
继承自StandardError
我想在rspec 中测试discard_on
事件
it "logs down when RemoteErrors::Error" do
allow_any_instance_of(described_class).to receive(:perform).and_raise(ConnectionErrors::Error)
expect_any_instance_of(Logger).to receive(:warn).with("Connection Error!")
described_class.perform_now
end
它从不进入discard_on
块而是进入retry_on
块。
错误
Failure/Error:
expected: 1 time with arguments: xxx
received: 0 times
retry_on
是否首先执行?还是因为ConnectionErrors
继承自StandardError
?
提前感谢
我认为您需要替换"执行";用";perform_now";引发ConnectionErrors:Error
allow_any_instance_of(described_class).to receive(:perform_now).and_raise(ConnectionErrors::Error)