Sha256: c8152087d18abd8240d13e921df49dd8538d2a97be9a3fdc6e1684333d416005

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'test_helper'

require 'exception_notification/resque'
require 'resque'
require 'mock_redis'
require 'resque/failure/multiple'
require 'resque/failure/redis'

class ResqueTest < ActiveSupport::TestCase
  setup do
    # Resque.redis=() only supports a String or Redis instance in Resque 1.8
    Resque.instance_variable_set(:@redis, MockRedis.new)

    Resque::Failure::Multiple.classes = [Resque::Failure::Redis, ExceptionNotification::Resque]
    Resque::Failure.backend = Resque::Failure::Multiple

    @worker = Resque::Worker.new(:jobs)
    # Forking causes issues with Mocha's `.expects`
    @worker.cant_fork = true
  end

  test 'count returns the number of failures' do
    Resque::Job.create(:jobs, BadJob)
    @worker.work(0)
    assert_equal 1, ExceptionNotification::Resque.count
  end

  test 'notifies exception when job fails' do
    ExceptionNotifier.expects(:notify_exception).with do |ex, opts|
      ex.is_a?(RuntimeError) &&
        ex.message == 'Bad job!' &&
        opts[:data][:resque][:error_class] == 'RuntimeError' &&
        opts[:data][:resque][:error_message] == 'Bad job!' &&
        opts[:data][:resque][:failed_at].present? &&
        opts[:data][:resque][:payload] == {
          'class' => 'ResqueTest::BadJob',
          'args' => []
        } &&
        opts[:data][:resque][:queue] == :jobs &&
        opts[:data][:resque][:worker].present?
    end

    Resque::Job.create(:jobs, BadJob)
    @worker.work(0)
  end

  class BadJob
    def self.perform
      raise 'Bad job!'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exception_notification-4.4.0 test/exception_notification/resque_test.rb