Class: RSpec::Sidekiq::Matchers::EnqueuedJobs

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rspec/sidekiq/matchers/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ EnqueuedJobs

Returns a new instance of EnqueuedJobs.



123
124
125
# File 'lib/rspec/sidekiq/matchers/base.rb', line 123

def initialize(klass)
  @jobs = unwrap_jobs(klass.jobs).map { |job| EnqueuedJob.new(job) }
end

Instance Attribute Details

#jobsObject (readonly)

Returns the value of attribute jobs.



121
122
123
# File 'lib/rspec/sidekiq/matchers/base.rb', line 121

def jobs
  @jobs
end

Instance Method Details

#each(&block) ⇒ Object



142
143
144
# File 'lib/rspec/sidekiq/matchers/base.rb', line 142

def each(&block)
  jobs.each(&block)
end

#includes?(arguments, options, count) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/rspec/sidekiq/matchers/base.rb', line 127

def includes?(arguments, options, count)
  matching = jobs.filter { |job| matches?(job, arguments, options) }

  case count[0]
  when :exactly
    matching.size == count[1]
  when :at_least
    matching.size >= count[1]
  when :at_most
    matching.size <= count[1]
  else
    matching.size > 0
  end
end

#minus!(other) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/rspec/sidekiq/matchers/base.rb', line 146

def minus!(other)
  return self unless other.is_a?(EnqueuedJobs)

  @jobs -= other.jobs

  self
end