Sha256: 66e4c2e7af54dfb166803b7c073afb3583e8fda871decf7f9014e174529bd562

Contents?: true

Size: 940 Bytes

Versions: 9

Compression:

Stored size: 940 Bytes

Contents

module Sidekiq
  module Worker

    ##
    # The Sidekiq testing infrastructure overrides perform_async
    # so that it does not actually touch the network.  Instead it
    # stores the asynchronous jobs in a per-class array so that
    # their presence/absence can be asserted by your tests.
    #
    # This is similar to ActionMailer's :test delivery_method and its
    # ActionMailer::Base.deliveries array.
    #
    # Example:
    #
    #   require 'sidekiq/testing'
    #
    #   assert_equal 0, HardWorker.jobs.size
    #   HardWorker.perform_async(:something)
    #   assert_equal 1, HardWorker.jobs.size
    #   assert_equal :something, HardWorker.jobs[0]['args'][0]
    #
    module ClassMethods
      alias_method :perform_async_old, :perform_async
      def perform_async(*args)
        jobs << { 'class' => self.name, 'args' => args }
        true
      end

      def jobs
        @pushed ||= []
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sidekiq-0.11.1 lib/sidekiq/testing.rb
sidekiq-0.11.0 lib/sidekiq/testing.rb
sidekiq-0.10.1 lib/sidekiq/testing.rb
sidekiq-0.10.0 lib/sidekiq/testing.rb
sidekiq-0.9.1 lib/sidekiq/testing.rb
sidekiq-0.9.0 lib/sidekiq/testing.rb
sidekiq-0.8.0 lib/sidekiq/testing.rb
sidekiq-0.7.0 lib/sidekiq/testing.rb
sidekiq-0.6.0 lib/sidekiq/testing.rb