diff --git a/lib/rspec/rails/matchers/active_job.rb b/lib/rspec/rails/matchers/active_job.rb index 336ec58c1..583f56faf 100644 --- a/lib/rspec/rails/matchers/active_job.rb +++ b/lib/rspec/rails/matchers/active_job.rb @@ -109,7 +109,7 @@ def supports_block_expectations? def check(jobs) @matching_jobs, @unmatching_jobs = jobs.partition do |job| - if job_match?(job) && arguments_match?(job) && queue_match?(job) && at_match?(job) && priority_match?(job) + if matches_constraints?(job) args = deserialize_arguments(job) @block.call(*args) true @@ -123,10 +123,6 @@ def check(jobs) return false end - check_countable - end - - def check_countable @matching_jobs_count = @matching_jobs.size case @expectation_type @@ -163,13 +159,23 @@ def base_job_message(job) end end - def job_match?(job) + def matches_constraints?(job) + job_matches?(job) && arguments_match?(job) && queue_match?(job) && at_match?(job) && priority_match?(job) + end + + def job_matches?(job) @job ? @job == job[:job] : true end # Rails 6.1 serializes the priority with a string key - def fetch_priority(job) - job[:priority] || job['priority'] + if ::Rails.version.to_f >= 7 + def fetch_priority(job) + job[:priority] + end + else + def fetch_priority(job) + job['priority'] + end end def arguments_match?(job)