Sha256: 0e44223007e25553a3cce249276810523c64f44108c05f1c3512856a4c1102d6

Contents?: true

Size: 1.51 KB

Versions: 6

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

RSpec.describe Loga::Sidekiq do
  describe '.configure_logging' do
    context 'when sidekiq is defined' do
      it 'gets invoked on Loga.configure' do
        allow(described_class).to receive(:configure_logging)

        Loga.reset

        Loga.configure(
          service_name: 'hello_world_app',
          service_version: '1.0',
          device: StringIO.new,
          format: :gelf,
        )

        expect(described_class).to have_received(:configure_logging)
      end

      it 'assigns our custom sidekiq job logger depending on the sidekiq version' do
        Loga.reset

        Loga.configure(
          service_name: 'hello_world_app',
          service_version: '1.0',
          device: StringIO.new,
          format: :gelf,
        )

        m = ENV['BUNDLE_GEMFILE'].match(/sidekiq(?<version>\d+)/)

        case m['version']
        when '51'
          expect(::Sidekiq.options[:job_logger]).to eq(Loga::Sidekiq5::JobLogger)
        when '6'
          expect(::Sidekiq.options[:job_logger]).to eq(Loga::Sidekiq6::JobLogger)
        end
      end
    end

    shared_examples 'a blank change' do
      it 'does nothing' do
        expect(described_class.configure_logging).to be_nil
      end
    end

    context 'when sidekiq is not defined' do
      before { hide_const('Sidekiq') }

      it_behaves_like 'a blank change'
    end

    context 'when sidekiq version is 4.2' do
      before { stub_const('::Sidekiq::VERSION', '4.2') }

      it_behaves_like 'a blank change'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
loga-2.8.0 spec/loga/sidekiq_spec.rb
loga-2.7.0 spec/loga/sidekiq_spec.rb
loga-2.6.1 spec/loga/sidekiq_spec.rb
loga-2.6.0 spec/loga/sidekiq_spec.rb
loga-2.5.4 spec/loga/sidekiq_spec.rb
loga-2.5.3 spec/loga/sidekiq_spec.rb