2012-02-10 00:46:44 -05:00
|
|
|
require 'helper'
|
|
|
|
require 'sidekiq/worker'
|
|
|
|
|
|
|
|
class TestTesting < MiniTest::Unit::TestCase
|
|
|
|
describe 'sidekiq testing' do
|
|
|
|
|
|
|
|
class DirectWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
def perform(a, b)
|
|
|
|
a + b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls the worker directly when in testing mode' do
|
|
|
|
begin
|
|
|
|
# Override Sidekiq::Worker
|
2012-02-10 01:33:36 -05:00
|
|
|
require 'sidekiq/testing'
|
2012-02-10 23:30:14 -05:00
|
|
|
assert_equal 0, DirectWorker.jobs.size
|
|
|
|
assert DirectWorker.perform_async(1, 2)
|
|
|
|
assert_equal 1, DirectWorker.jobs.size
|
2012-02-10 00:46:44 -05:00
|
|
|
ensure
|
|
|
|
# Undo override
|
2012-02-10 01:33:36 -05:00
|
|
|
Sidekiq::Worker::ClassMethods.class_eval do
|
|
|
|
remove_method :perform_async
|
|
|
|
alias_method :perform_async, :perform_async_old
|
|
|
|
remove_method :perform_async_old
|
|
|
|
end
|
2012-02-10 00:46:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|