Sha256: cd8ea2d69001e468b31caee276d6afc965a2e38f817708adec47e1d6fabc8d16
Contents?: true
Size: 1.88 KB
Versions: 13
Compression:
Stored size: 1.88 KB
Contents
require 'spec_helper' class GoodJob < CanvasSync::Job def perform(job_chain, argument) end end class EvilError < StandardError; end; class BadJob < CanvasSync::Job def perform(job_chain, 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 expect { BadJob.perform_now({ jobs: [], global_options: { on_failure: 'BadJob.good_catcher' } }) }.to raise_exception(StandardError) end it 'logs a failing error handler' do expect(BadJob).to receive(:bad_catcher).once.and_call_original expect { BadJob.perform_now({ jobs: [], global_options: { on_failure: 'BadJob.bad_catcher' } }) }.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
13 entries across 13 versions & 1 rubygems