Sha256: 39fed1a1afaaa763b93f28e56f9bb4fd197f196265bef122ae20a281213ceecd

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

require 'airbrake/shoryuken'

RSpec.describe Airbrake::Shoryuken::ErrorHandler do
  let(:error) { AirbrakeTestError.new('shoryuken error') }
  let(:body) { { message: 'message' } }
  let(:queue) { 'foo_queue' }

  let(:worker) do
    Class.new do
      def self.to_s
        'FooWorker'
      end
    end.new
  end

  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

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

  context "when there's an error" do
    it 'notifies' do
      expect do
        subject.call(worker, queue, nil, body) { raise error }
      end.to raise_error(error)

      wait_for_a_request_with_body(/"message":"shoryuken\serror"/)
      wait_for_a_request_with_body(/"params":{.*"queue":"#{queue}"/)
      wait_for_a_request_with_body(/"params":{.*"body":\{"message":"message"\}/)
      wait_for_a_request_with_body(/"component":"shoryuken","action":"FooWorker"/)
    end

    context "and it's a batch" do
      let(:body) { [{ message1: 'message1' }, { message2: 'message2' }] }

      it 'notifies' do
        expect do
          subject.call(worker, queue, nil, body) { raise error }
        end.to raise_error(error)

        wait_for_a_request_with_body(/"message":"shoryuken\serror"/)
        wait_for_a_request_with_body(/"params":{.*"queue":"#{queue}"/)
        wait_for_a_request_with_body(
          /"params":{.*"batch":\[\{"message1":"message1"\},\{"message2":"message2"\}\]/
        )
        wait_for_a_request_with_body(/"component":"shoryuken","action":"FooWorker"/)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
airbrake-9.2.1 spec/unit/shoryuken_spec.rb
airbrake-9.2.0 spec/unit/shoryuken_spec.rb
airbrake-9.1.0 spec/unit/shoryuken_spec.rb
airbrake-9.0.2 spec/unit/shoryuken_spec.rb
airbrake-9.0.1 spec/unit/shoryuken_spec.rb
airbrake-9.0.0 spec/unit/shoryuken_spec.rb
airbrake-8.3.2 spec/unit/shoryuken_spec.rb
airbrake-8.3.1 spec/unit/shoryuken_spec.rb
airbrake-8.3.0 spec/unit/shoryuken_spec.rb