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.



193
194
195
# File 'lib/rspec/sidekiq/matchers/base.rb', line 193

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.



191
192
193
# File 'lib/rspec/sidekiq/matchers/base.rb', line 191

def jobs
  @jobs
end

Instance Method Details

#each(&block) ⇒ Object



212
213
214
# File 'lib/rspec/sidekiq/matchers/base.rb', line 212

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

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

Returns:

  • (Boolean)


197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/rspec/sidekiq/matchers/base.rb', line 197

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



216
217
218
219
220
221
222
# File 'lib/rspec/sidekiq/matchers/base.rb', line 216

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

  @jobs -= other.jobs

  self
end