class RSpec::Sidekiq::Matchers::JobArguments

@api private

Attributes

job[RW]

Public Class Methods

new(job) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 39
def initialize(job)
  self.job = job
end

Public Instance Methods

matches?(expected_args) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 44
def matches?(expected_args)
  matcher = RSpec::Mocks::ArgumentListMatcher.new(*expected_args)

  matcher.args_match?(*unwrapped_arguments)
end
unwrapped_arguments() click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 50
def unwrapped_arguments
  args = job["args"]

  return deserialized_active_job_args if active_job?

  args
end

Private Instance Methods

active_job?() click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 60
def active_job?
  job["class"] == "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
end
active_job_original_args() click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 77
def active_job_original_args
  active_job_args = job["args"].detect { |arg| arg.is_a?(Hash) && arg.key?("arguments") }
  active_job_args ||= {}
  active_job_args["arguments"] || []
end
deserialized_active_job_args() click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 64
def deserialized_active_job_args
  active_job_args = ActiveJob::Arguments.deserialize(active_job_original_args)

  # ActiveJob 7 (aj7) changed deserialization structure, adding passed arguments
  # in an aj-specific hash under the :args key
  aj7_args_hash = active_job_args.detect { |arg| arg.respond_to?(:key) && arg.key?(:args) }

  return active_job_args if aj7_args_hash.nil?

  active_job_args.delete(aj7_args_hash)
  active_job_args.concat(aj7_args_hash[:args])
end