Sha256: 27f879172aa07ccf2eaea201e6f965e87933ee99f32460d9c1ac7a63eb200d9c

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.2')
  require 'sidekiq'
  require 'sidekiq/cli'
  require 'airbrake/sidekiq'

  RSpec.describe "airbrake/sidekiq/error_handler" do
    let(:endpoint) { 'https://api.airbrake.io/api/v3/projects/113743/notices' }

    def wait_for_a_request_with_body(body)
      wait_for(a_request(:post, endpoint).with(body: body)).to have_been_made.once
    end

    def call_handler
      handler = Sidekiq.error_handlers.last
      handler.call(
        AirbrakeTestError.new('sidekiq error'),
        'class' => 'HardSidekiqWorker', 'args' => %w[bango bongo]
      )
    end

    before do
      stub_request(:post, endpoint).to_return(status: 201, body: '{}')
    end

    it "sends a notice to Airbrake" do
      expect(call_handler).to be_a(Airbrake::Promise)

      wait_for_a_request_with_body(/"message":"sidekiq\serror"/)
      wait_for_a_request_with_body(/"params":{.*"args":\["bango","bongo"\]/)
      wait_for_a_request_with_body(/"component":"sidekiq","action":"HardSidekiqWorker"/)
    end

    context "when Airbrake is not configured" do
      before do
        @notifiers = Airbrake.notifiers[:notice]
        @default_notifier = @notifiers.delete(:default)
      end

      after do
        @notifiers[:default] = @default_notifier
      end

      it "returns nil" do
        expect(call_handler).to be_nil
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
airbrake-8.1.4 spec/unit/sidekiq_spec.rb
airbrake-8.1.3 spec/unit/sidekiq_spec.rb
airbrake-8.1.2 spec/unit/sidekiq_spec.rb
airbrake-8.1.1 spec/unit/sidekiq_spec.rb
airbrake-8.1.0 spec/unit/sidekiq_spec.rb