Вы можете использовать ActiveJob::TestHelper
и ActiveSupport::Testing::TimeHelpers
.
Добавить помощника к rails_helper.rb
.
config.include ActiveJob::TestHelper
config.include ActiveSupport::Testing::TimeHelpers
Добавить тест к спецификации.
class Some < ApplicationRecord
def hello
SomeJob.set(wait: 3.seconds).perform_later 'Hello!'
end
end
RSpec.describe Some, type: :model do
it 'should start job after 3 seconds' do
time = Time.current
travel_to(time) do
assertion = {
job: SomeJob,
args: ['Hello!'],
at: (time + 3.seconds).to_i
}
assert_enqueued_with(assertion) { Some.new.hello }
end
end
end