From 8b111e9e3be14bd21cbfec702e0828c2330af2b3 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Wed, 19 Apr 2023 09:12:50 +0300 Subject: [PATCH] fixup! Write a spec for retried job --- lib/rspec/rails/matchers/active_job.rb | 1 - spec/rspec/rails/matchers/active_job_spec.rb | 12 +++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/rspec/rails/matchers/active_job.rb b/lib/rspec/rails/matchers/active_job.rb index b7a61f381..944391032 100644 --- a/lib/rspec/rails/matchers/active_job.rb +++ b/lib/rspec/rails/matchers/active_job.rb @@ -232,7 +232,6 @@ def matches?(proc) original_enqueued_jobs = Set.new(queue_adapter.enqueued_jobs) proc.call - enqueued_jobs = Set.new(queue_adapter.enqueued_jobs) check(enqueued_jobs - original_enqueued_jobs) diff --git a/spec/rspec/rails/matchers/active_job_spec.rb b/spec/rspec/rails/matchers/active_job_spec.rb index a0cb79e71..dbe4c2791 100644 --- a/spec/rspec/rails/matchers/active_job_spec.rb +++ b/spec/rspec/rails/matchers/active_job_spec.rb @@ -101,24 +101,22 @@ def self.name; "LoggingJob"; end context "when job is retried" do include ActiveJob::TestHelper - let(:retried_job) do + let(:unreliable_job) do Class.new(ActiveJob::Base) do retry_on StandardError, wait: 5, queue: :retry - def self.name; "RetriedJob"; end + def self.name; "UnreliableJob"; end def perform; raise StandardError; end end end - before do - stub_const("RetriedJob", retried_job) - queue_adapter.perform_enqueued_jobs = true - end + before { stub_const("UnreliableJob", unreliable_job) } it "passes with reenqueued job" do time = Time.current.change(usec: 0) travel_to time do - expect { retried_job.perform_later }.to have_enqueued_job(retried_job).on_queue(:retry).at(time + 5) + UnreliableJob.perform_later + expect { perform_enqueued_jobs }.to have_enqueued_job(UnreliableJob).on_queue(:retry).at(time + 5) end end end