require File.expand_path('test_helper', __dir__) $backburner_sum = 0 $backburner_numbers = [] class TestBackburnerJob include Backburner::Queue queue 'test.jobber' def self.perform(value, number) $backburner_sum += value $backburner_numbers << number end end class TestWorker < Backburner::Worker; end describe 'Backburner module' do before do Backburner.default_queues.clear clear_jobs!(Backburner.configuration.primary_queue, 'test-plain', 'parent-plain', 'bar.baz.foo') end describe 'for work method' do it 'invokes worker simple start' do Backburner::Workers::Simple.expects(:start).with(%w[foo bar]) Backburner.work('foo', 'bar') end it 'invokes other worker if specified in configuration' do Backburner.configure { |config| config.default_worker = TestWorker } TestWorker.expects(:start).with(%w[foo bar]) Backburner.work('foo', 'bar') end it 'invokes other worker if specified in work method as options' do TestWorker.expects(:start).with(%w[foo bar]) Backburner.work('foo', 'bar', worker: TestWorker) end it 'invokes worker start with no args' do Backburner::Workers::Simple.expects(:start).with([]) Backburner.work end end # work! describe 'for configuration' do it 'remembers the tube_namespace' do assert_equal 'demo.test', Backburner.configuration.tube_namespace end it 'remembers the namespace_separator' do assert_equal '.', Backburner.configuration.namespace_separator end it 'disallows a reserved separator' do assert_raises RuntimeError do Backburner.configuration.namespace_separator = ':' end end end # configuration describe 'for default_queues' do it 'supports assignment' do Backburner.default_queues << 'foo' Backburner.default_queues << 'bar' assert_same_elements %w[foo bar], Backburner.default_queues end end after do Backburner.configure { |config| config.default_worker = Backburner::Workers::Simple } end end # Backburner