Sha256: dae4b7f697b5f1f0163d1d6a7bf5ef3795b547563f6b70f7651ec1ce69157322

Contents?: true

Size: 948 Bytes

Versions: 9

Compression:

Stored size: 948 Bytes

Contents

require 'spec_helper'

require 'active_support/rescuable'

describe Rollbar::ActiveJob do
  class TestJob
    # To mix in rescue_from
    include ActiveSupport::Rescuable
    include Rollbar::ActiveJob

    attr_reader :job_id

    def perform(exception, job_id)
      @job_id = job_id
      # ActiveJob calls rescue_with_handler when a job raises an exception
      rescue_with_handler(exception) || raise(exception)
    end
  end

  before { reconfigure_notifier }

  let(:exception) { StandardError.new('oh no') }
  let(:job_id) { "123" }

  it "reports the error to Rollbar" do
    expected_params = { :job => "TestJob", :job_id => job_id }
    expect(Rollbar).to receive(:error).with(exception, expected_params)
    TestJob.new.perform(exception, job_id) rescue nil
  end

  it "reraises the error so the job backend can handle the failure and retry" do
    expect { TestJob.new.perform(exception, job_id) }.to raise_error exception
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rollbar-2.13.1 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.13.0 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.12.0 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.11.5 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.11.4 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.11.3 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.11.2 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.11.1 spec/rollbar/plugins/active_job_spec.rb
rollbar-2.11.0 spec/rollbar/plugins/active_job_spec.rb