Sha256: b5484408e6d2de90b31f79c7a46f7e2168ef06cc4b9edb76a8607bd838de283c

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

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]
    #
    #   assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
    #   MyMailer.delayed.send_welcome_email('foo@example.com')
    #   assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
    #
    module ClassMethods
      alias_method :client_push_old, :client_push
      def client_push(opts)
        jobs << opts
        true
      end

      def jobs
        @pushed ||= []
      end

      def drain
        while job = jobs.shift do
          new.perform(*job['args'])
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sidekiq-2.3.3 lib/sidekiq/testing.rb
sidekiq-2.3.2 lib/sidekiq/testing.rb
sidekiq-2.3.1 lib/sidekiq/testing.rb
sidekiq-2.3.0 lib/sidekiq/testing.rb
sidekiq-2.2.1 lib/sidekiq/testing.rb
sidekiq-2.2.0 lib/sidekiq/testing.rb
sidekiq-2.1.1 lib/sidekiq/testing.rb
sidekiq-2.1.0 lib/sidekiq/testing.rb