1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/lib/sidekiq/testing.rb

45 lines
1.2 KiB
Ruby
Raw Normal View History

module Sidekiq
module Worker
2012-02-10 23:30:14 -05:00
##
# The Sidekiq testing infrastructure overrides perform_async
2012-02-10 23:30:14 -05:00
# so that it does not actually touch the network. Instead it
# stores the asynchronous jobs in a per-class array so that
2012-02-10 23:30:14 -05:00
# 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]
#
2012-04-05 23:06:47 -04:00
# 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
2012-06-28 03:46:18 -04:00
alias_method :client_push_old, :client_push
def client_push(opts)
jobs << opts
2012-02-10 23:30:14 -05:00
true
end
def jobs
@pushed ||= []
end
def drain
while job = jobs.shift do
new.perform(*job['args'])
end
end
end
end
end