Module: Sidekiq::Worker::ClassMethods

Defined in:
lib/sidekiq/testing.rb,
lib/sidekiq/worker.rb

Overview

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]

Instance Method Summary collapse

Instance Method Details

#jobsObject


29
30
31
# File 'lib/sidekiq/testing.rb', line 29

def jobs
  @pushed ||= []
end

#perform_async(*args) ⇒ Object


32
33
34
# File 'lib/sidekiq/worker.rb', line 32

def perform_async(*args)
  Sidekiq::Client.push('class' => self.name, 'args' => args)
end

#perform_async_oldObject


23
24
25
# File 'lib/sidekiq/testing.rb', line 23

def perform_async(*args)
  Sidekiq::Client.push('class' => self.name, 'args' => args)
end

#queue(name) ⇒ Object


36
37
38
# File 'lib/sidekiq/worker.rb', line 36

def queue(name)
  Sidekiq::Client.queue_mappings[self.name] = name.to_s
end