Skip to content

Commit

Permalink
fixup! Write a spec for retried job
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Apr 19, 2023
1 parent f202c6c commit 8b111e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion lib/rspec/rails/matchers/active_job.rb
Expand Up @@ -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)
Expand Down
12 changes: 5 additions & 7 deletions spec/rspec/rails/matchers/active_job_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 8b111e9

Please sign in to comment.