class RSpec::Rails::Matchers::HaveEnqueuedMail

def deserialize_arguments(job)

so we override the active job implementation and customise it here.
Ruby 3.1 changed how params were serialized on Rails 6.1
def deserialize_arguments(job)
  args = super
  return args unless Hash === args.last
  hash = args.pop
  if hash.key?("_aj_ruby2_keywords")
    keywords = hash["_aj_ruby2_keywords"]
    original_hash = keywords.each_with_object({}) { |new_hash, keyword| new_hash[keyword.to_sym] = hash[keyword] }
    args + [original_hash]
  elsif hash.key?(:args) && hash.key?(:params)
    args + [hash]
  elsif hash.key?(:args)
    args + hash[:args]
  else
    args + [hash]
  end
end