require 'rails_helper' describe LHC::Rollbar do before(:each) do LHC.config.interceptors = [LHC::Rollbar] end it 'does not report if Rollbar is not defined' do stub_request(:get, 'http://local.ch').to_return(status: 400) expect(-> { LHC.get('http://local.ch') }) .to raise_error LHC::BadRequest end context 'Rollbar is defined' do before(:each) do class Rollbar; end allow(::Rollbar).to receive(:error) end it 'does report errors to rollbar' do stub_request(:get, 'http://local.ch').to_return(status: 400) expect(-> { LHC.get('http://local.ch') }) .to raise_error LHC::BadRequest expect(::Rollbar).to have_received(:error) .with(LHC::BadRequest, hash_including(response: anything, request: anything)) end context 'additional params' do it 'does report errors to rollbar with additional data' do stub_request(:get, 'http://local.ch') .to_return(status: 400) expect(-> { LHC.get('http://local.ch', rollbar: { additional: 'data' }) }) .to raise_error LHC::BadRequest expect(::Rollbar).to have_received(:error) .with( LHC::BadRequest, hash_including( response: anything, request: anything, additional: 'data' ) ) end end end end