Class: RSpec::Sidekiq::Matchers::EnqueueSidekiqJob Private

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.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.

Instance Attribute Summary collapse

Attributes inherited from Base

#actual_jobs, #expected_arguments, #expected_options, #klass

Instance Method Summary collapse

Methods inherited from Base

#at, #description, #formatted, #immediately, #in, #normalize_arguments, #on, #with

Constructor Details

#initialize(job_class) ⇒ EnqueueSidekiqJob

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 EnqueueSidekiqJob.



8
9
10
11
12
13
14
15
16
17
# File 'lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb', line 8

def initialize(job_class)
  super()
  default = if RSpec::Sidekiq.configuration.sidekiq_gte_7?
    ::Sidekiq::Job
  else
    ::Sidekiq::Worker
  end

  @klass = job_class || default
end

Instance Attribute Details

#original_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.

Plus that from Base



6
7
8
# File 'lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb', line 6

def original_jobs
  @original_jobs
end

Instance Method Details

#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.



33
34
35
36
37
38
39
# File 'lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb', line 33

def failure_message
  if @actual_jobs.none?
    "expected to enqueue a job but enqueued 0"
  else
    super
  end
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.



41
42
43
44
45
46
47
48
# File 'lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb', line 41

def failure_message_when_negated
  messages = ["expected not to enqueue a #{@klass} job but enqueued #{actual_jobs.count}"]

  messages << "  with arguments #{formatted(expected_arguments)}" if expected_arguments
  messages << "  with context #{formatted(expected_options)}" if expected_options

  messages.join("\n")
end

#matches?(proc) ⇒ Boolean

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:

  • (Boolean)

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb', line 19

def matches?(proc)
  raise ArgumentError, "Only block syntax supported for enqueue_sidekiq_job" unless Proc === proc

  @original_jobs = EnqueuedJobs.new(@klass)
  proc.call
  @actual_jobs = EnqueuedJobs.new(@klass).minus!(original_jobs)

  if @actual_jobs.none?
    return false
  end

  @actual_jobs.includes?(expected_arguments, expected_options)
end

#supports_block_expectations?Boolean

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:

  • (Boolean)


50
51
52
# File 'lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb', line 50

def supports_block_expectations?
  true
end