Class: RSpec::Sidekiq::Matchers::Base Private

Inherits:
Object
  • Object
show all
Includes:
Matchers::Composable, Mocks::ArgumentMatchers
Defined in:
lib/rspec/sidekiq/matchers/base.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

EnqueueSidekiqJob, HaveEnqueuedSidekiqJob

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.



169
170
171
172
# File 'lib/rspec/sidekiq/matchers/base.rb', line 169

def initialize
  @expected_arguments = [any_args]
  @expected_options = {}
end

Instance Attribute Details

#actual_jobsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



167
168
169
# File 'lib/rspec/sidekiq/matchers/base.rb', line 167

def actual_jobs
  @actual_jobs
end

#expected_argumentsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



167
168
169
# File 'lib/rspec/sidekiq/matchers/base.rb', line 167

def expected_arguments
  @expected_arguments
end

#expected_optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



167
168
169
# File 'lib/rspec/sidekiq/matchers/base.rb', line 167

def expected_options
  @expected_options
end

#klassObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



167
168
169
# File 'lib/rspec/sidekiq/matchers/base.rb', line 167

def klass
  @klass
end

Instance Method Details

#at(timestamp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



179
180
181
182
# File 'lib/rspec/sidekiq/matchers/base.rb', line 179

def at(timestamp)
  @expected_options["at"] = timestamp.to_time.to_i
  self
end

#descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



199
200
201
# File 'lib/rspec/sidekiq/matchers/base.rb', line 199

def description
  "have an enqueued #{klass} job with arguments #{expected_arguments}"
end

#failure_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/rspec/sidekiq/matchers/base.rb', line 203

def failure_message
  message = ["expected to have an enqueued #{klass} job"]
  if expected_arguments
    message << "  with arguments:"
    message << "    -#{formatted(expected_arguments)}"
  end

  if expected_options.any?
    message << "  with context:"
    message << "    -#{formatted(expected_options)}"
  end

  if actual_jobs.any?
    message << "but have enqueued only jobs"
    if expected_arguments
      job_messages = actual_jobs.map do |job|
        base = "  -JID:#{job.jid} with arguments:"
        base << "\n    -#{formatted(job.args)}"
        if expected_options.any?
          base << "\n   with context: #{formatted(job.context)}"
        end

        base
      end

      message << job_messages.join("\n")
    end
  end

  message.join("\n")
end

#failure_message_when_negatedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



235
236
237
238
239
240
# File 'lib/rspec/sidekiq/matchers/base.rb', line 235

def failure_message_when_negated
  message = ["expected not to have an enqueued #{klass} job"]
  message << "  arguments: #{expected_arguments}" if expected_arguments.any?
  message << "  options: #{expected_options}" if expected_options.any?
  message.join("\n")
end

#formatted(thing) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



242
243
244
# File 'lib/rspec/sidekiq/matchers/base.rb', line 242

def formatted(thing)
  RSpec::Support::ObjectFormatter.format(thing)
end

#immediatelyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def immediately
  @expected_options["at"] = nil
  self
end

#in(interval) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



184
185
186
187
# File 'lib/rspec/sidekiq/matchers/base.rb', line 184

def in(interval)
  @expected_options["at"] = (Time.now.to_f + interval.to_f).to_i
  self
end

#normalize_arguments(args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/rspec/sidekiq/matchers/base.rb', line 246

def normalize_arguments(args)
  if args.is_a?(Array)
    args.map{ |x| normalize_arguments(x) }
  elsif args.is_a?(Hash)
    args.each_with_object({}) do |(key, value), hash|
      hash[key.to_s] = normalize_arguments(value)
    end
  elsif args.is_a?(Symbol)
    args.to_s
  else
    args
  end
end

#on(queue) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def on(queue)
  @expected_options["queue"] = queue
  self
end

#with(*expected_arguments) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



174
175
176
177
# File 'lib/rspec/sidekiq/matchers/base.rb', line 174

def with(*expected_arguments)
  @expected_arguments = normalize_arguments(expected_arguments)
  self
end