Sha256: ebb2284d4e034e44eb21409daec5188d8190fdeb7cf7ef104ba7a3bac1e9ef96

Contents?: true

Size: 1.02 KB

Versions: 61

Compression:

Stored size: 1.02 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
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
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
canvas_sync-0.10.5 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.10.4 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.10.3 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.10.2 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.10.0 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.9.4 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.9.3 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.9.2 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.9.1 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.9.0 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.8.4 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.8.3 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.8.2 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.8.1 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.8.0 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.7.3 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.7.2 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.7.1 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.7.0 spec/canvas_sync/jobs/job_spec.rb
canvas_sync-0.6.4 spec/canvas_sync/jobs/job_spec.rb