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.



117
118
119
# File 'lib/rspec/sidekiq/matchers/base.rb', line 117

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.



115
116
117
# File 'lib/rspec/sidekiq/matchers/base.rb', line 115

def jobs
  @jobs
end

Instance Method Details

#each(&block) ⇒ Object



136
137
138
# File 'lib/rspec/sidekiq/matchers/base.rb', line 136

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

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

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
129
130
131
132
133
134
# 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) ⇒ Object



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

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

  @jobs -= other.jobs

  self
end