Sha256: f3690c163fe2046259936699981c3ad30d702d60ab1505918eb22aa990c864e1

Contents?: true

Size: 1.73 KB

Versions: 23

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHC::Rollbar do
  before(:each) do
    LHC.config.interceptors = [LHC::Rollbar]
  end

  context 'Rollbar is undefined' do
    before(:each) do
      Object.send(:remove_const, 'Rollbar') if Object.const_defined?('Rollbar')
    end
    it 'does not report' do
      stub_request(:get, 'http://local.ch').to_return(status: 400)
      expect(-> { LHC.get('http://local.ch') })
        .to raise_error LHC::BadRequest
    end
  end

  context 'Rollbar is defined' do
    before(:each) do
      class Rollbar; end
      ::Rollbar.stub(:warning)
    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(:warning)
        .with(
          'Status: 400 URL: http://local.ch',
          response: hash_including(body: anything, code: anything, headers: anything, time: anything, timeout?: anything),
          request: hash_including(url: anything, method: anything, headers: anything, params: 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(:warning)
          .with(
            'Status: 400 URL: http://local.ch',
            hash_including(
              response: anything,
              request: anything,
              additional: 'data'
            )
          )
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
lhc-14.0.0 spec/interceptors/rollbar/main_spec.rb
lhc-13.2.0 spec/interceptors/rollbar/main_spec.rb
lhc-13.1.0 spec/interceptors/rollbar/main_spec.rb
lhc-13.0.0 spec/interceptors/rollbar/main_spec.rb
lhc-12.3.0 spec/interceptors/rollbar/main_spec.rb
lhc-12.2.1 spec/interceptors/rollbar/main_spec.rb
lhc-12.2.0 spec/interceptors/rollbar/main_spec.rb
lhc-12.1.3 spec/interceptors/rollbar/main_spec.rb
lhc-12.1.2 spec/interceptors/rollbar/main_spec.rb
lhc-12.1.1 spec/interceptors/rollbar/main_spec.rb
lhc-12.1.0 spec/interceptors/rollbar/main_spec.rb
lhc-12.0.3 spec/interceptors/rollbar/main_spec.rb
lhc-12.0.2 spec/interceptors/rollbar/main_spec.rb
lhc-12.0.1 spec/interceptors/rollbar/main_spec.rb
lhc-12.0.0 spec/interceptors/rollbar/main_spec.rb
lhc-11.2.0 spec/interceptors/rollbar/main_spec.rb
lhc-11.1.1 spec/interceptors/rollbar/main_spec.rb
lhc-11.1.0 spec/interceptors/rollbar/main_spec.rb
lhc-11.0.2 spec/interceptors/rollbar/main_spec.rb
lhc-11.0.1 spec/interceptors/rollbar/main_spec.rb