Sha256: d2376cbd0d2d2e874f7ae08db35c329e2a2071b9a36ae6c68c3cac63414e5dfd

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'

describe Rollbar::LoggerProxy do
  let(:logger) { double(:logger) }
  let(:message) { 'the-message' }

  subject { described_class.new(logger) }

  before do
    allow(Rollbar.configuration).to receive(:enabled).and_return(true)
    allow(Rollbar.configuration).to receive(:logger_level).and_return(:debug)
  end

  shared_examples 'delegate to logger' do
    it 'logs with correct level' do
      expect(logger).to receive(level).with(message)

      subject.send(level, message)
    end
  end

  %w(info error warn debug).each do |level|
    describe "#{level}" do
      it_should_behave_like 'delegate to logger' do
        let(:level) { level }
      end
    end
  end

  describe '#log' do
    context 'if Rollbar is disabled' do
      before do
        expect(Rollbar.configuration).to receive(:enabled).and_return(false)
      end

      it 'doesnt call the logger' do
        expect(logger).to_not receive(:error)

        subject.log('error', 'foo')
      end
    end

    context 'if the logger fails' do
      it 'doesnt raise' do
        allow(logger).to receive(:info).and_raise(StandardError.new)

        expect { subject.log('info', message) }.not_to raise_error
      end
    end

    context 'if logger_level is :info' do
      before do
        allow(Rollbar.configuration).to receive(:logger_level).and_return(:info)
      end

      it 'doesnt call the logger (debug)' do
        expect(logger).to_not receive(:debug)

        subject.log('debug', 'foo')
      end

      it 'calls the logger (error)' do
        expect(logger).to receive(:error)

        subject.log('error', 'foo')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rollbar-2.18.2 spec/rollbar/logger_proxy_spec.rb
rollbar-2.18.0 spec/rollbar/logger_proxy_spec.rb
rollbar-2.17.0 spec/rollbar/logger_proxy_spec.rb