Software Rollbar Reported Error with RSpec

The logic inside my class sometimes uses Rollbar.silencedto ignore some exception (therefore they are not reported).

I am trying to write a test that ensures that rollbar does report an error.

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

Unfortunately, rollbar not used :error, :critical, :warningetc. when reporting unanswered errors.

I have seen report_exception_to_rollbarand call_with_rollbarinside rollbar source code , which are wrapped in Rollbar.scoped.

So, I tried to check it with:

expect(Rollbar).to receive(:scoped).with(any_args).and_call_original

but he also told me:

 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

How to ensure that an exception is caught using a roll and checked by rspec?

+4
1

, , Rollbar.log exception_reporter.rb. (Rollbar.error, Rollbar.warning .. Rollbar.log.)

:

expect(Rollbar).to receive(:log).with(any_args).and_call_original

+2

Source: https://habr.com/ru/post/1606993/


All Articles