I've got a method as follows:
if response.fetch('ok')
response.fetch(response_key) { [] }
elsif response.fetch('error') == 'token_revoked'
ErrorReporter.increment('access_revoked', source: { account_id: account_id }, sporadic: true)
fail(RemoteService::AccessRevoked, 'Our access to your account was revoked, please re-authorize.')
else
ErrorReporter.increment(
'bad_request',
source: {
account_id: account_id
error: response.fetch('error')
},
sporadic: true
)
fail(RemoteService::InvalidRequest, 'Something went wrong communicating with the remote service, please try again')
end
And I'm trying to test the scenario when the request returns with the token_revoked
error. I'd like to ensure the test specifies that in this scenario, that we report the error to our ErrorReporting service.
So, my spec looks like this:
it 'records the failure with our error reporting service' do
expect(ErrorReporter).to receive(:increment).with(
'bad_request',
source: {
account_id: 1
},
sporadic: true
)
available_channels.fetch
end
However, this spec always fails, because after the call is made to the ErrorReporter, the code immediately calls fail
which makes my spec fail. Does anyone have any idea how I can verify that the call to my error reporter is made while handling the inevitable exception that I know the code is now going to throw?