class RSpec::Sidekiq::Matchers::EnqueuedJobs

Attributes

jobs[R]

Public Class Methods

new(klass) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 117
def initialize(klass)
  @jobs = unwrap_jobs(klass.jobs).map { |job| EnqueuedJob.new(job) }
end

Public Instance Methods

each(&block) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 136
def each(&block)
  jobs.each(&block)
end
includes?(arguments, options, count) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 121
def includes?(arguments, options, count)
  matching = jobs.filter { |job| matches?(job, arguments, options) }

  case count
  in [:exactly, n]
    matching.size == n
  in [:at_least, n]
    matching.size >= n
  in [:at_most, n]
    matching.size <= n
  else
    matching.size > 0
  end
end
minus!(other) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 140
def minus!(other)
  self unless other.is_a?(EnqueuedJobs)

  @jobs -= other.jobs

  self
end

Private Instance Methods

arguments_matches?(job, arguments) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 155
def arguments_matches?(job, arguments)
  job_arguments = JobArguments.new(job)

  job_arguments.matches?(arguments)
end
matches?(job, arguments, options) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 150
def matches?(job, arguments, options)
  arguments_matches?(job, arguments) &&
    options_matches?(job, options)
end
options_matches?(job, options) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 161
def options_matches?(job, options)
  parser = JobOptionParser.new(job)

  parser.matches?(options)
end
unwrap_jobs(jobs) click to toggle source
# File lib/rspec/sidekiq/matchers/base.rb, line 167
def unwrap_jobs(jobs)
  return jobs if jobs.is_a?(Array)
  jobs.values.flatten
end