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