【发布时间】:2015-09-11 16:52:48
【问题描述】:
我班级中的逻辑有时使用Rollbar.silenced 来忽略某些异常(因此它们不会被报告)。
我正在尝试编写一个测试来确保滚动条实际报告错误。
it 'does not mute rollbar' do
expect(Rollbar).not_to receive(:silenced)
expect(Rollbar).to receive(:error).with(any_args).and_call_original
expect { query }.to raise_error(unknown_exception)
end
很遗憾rollbar在:error、:critical、:warning等方法中报告未获救的错误时不使用。
我在滚动条sourcecode 中看到report_exception_to_rollbar 和call_with_rollbar,它们用Rollbar.scoped 包裹。
所以我尝试使用以下方法对其进行测试:
expect(Rollbar).to receive(:scoped).with(any_args).and_call_original
但它也告诉我:
Failure/Error: expect(Rollbar).to receive(:scoped).with(any_args).and_call_original
(Rollbar).scoped(*(any args))
expected: 1 time with any arguments
received: 0 times with any arguments
如何确保异常被rollbar捕获并用rspec测试?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 rspec rollbar