Sha256: 3a6886f8bd255501eef1059478707382e317c2adfba3dd2f552cd37bacfc53d3

Contents?: true

Size: 1.73 KB

Versions: 126

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'

class GoodJob < CanvasSync::Job
  def perform(argument)
  end
end

class EvilError < StandardError; end;

class BadJob < CanvasSync::Job
  def perform(argument)
    raise EvilError
  end

  def self.evil_catcher(e, *opts)
    raise EvilError
  end

  def self.good_catcher(e, *opts)

  end
end

RSpec.describe CanvasSync::Job do
  describe '#perform' do
    it 'creates a CanvasSync::JobLog and logs relevant data on it' do
      expect {
        GoodJob.perform_now("argument")
      }.to change { CanvasSync::JobLog.count }.by(1)

      job_log = CanvasSync::JobLog.last
      expect(job_log.started_at).to_not be_nil
      expect(job_log.job_class).to eq(GoodJob.to_s)
      expect(job_log.job_arguments).to eq(["argument"])
      expect(job_log.completed_at).to_not be_nil
    end

    it 'logs exceptions on the CanvasSync::JobLog and then re-raises' do
      expect {
        BadJob.perform_now("argument")
      }.to raise_exception(StandardError)

      job_log = CanvasSync::JobLog.last
      expect(job_log.exception).to eq("EvilError: EvilError")
      expect(job_log.backtrace).to_not be_nil
    end

    it 'invokes an error handler' do
      expect(BadJob).to receive(:good_catcher).once
      set_batch_context(on_failure: 'BadJob.good_catcher')
      expect {
        BadJob.perform_now()
      }.to raise_exception(StandardError)
    end

    it 'logs a failing error handler' do
      expect(BadJob).to receive(:bad_catcher).once.and_call_original
      set_batch_context(on_failure: 'BadJob.bad_catcher')
      expect {
        BadJob.perform_now()
      }.to raise_exception(StandardError)
      job_log = CanvasSync::JobLog.last
      expect(job_log.backtrace).to include "Error Occurred while handling an Error"
    end
  end
end

Version data entries

126 entries across 126 versions & 1 rubygems

Version Path
canvas_sync-0.22.9 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.8 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.6 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.5 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.4 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.3 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.2 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.1 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0.beta8 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0.beta7 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0.beta6 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0.beta5 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0.beta4 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0.beta3 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0.beta2 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.22.0.beta1 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.21.1 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.21.1.beta1 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.21.0 spec/canvas_sync/jobs/job_spec.rb