Class: RSpec::Sidekiq::Matchers::HaveEnqueuedJob

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sidekiq/matchers/have_enqueued_job.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_arguments) ⇒ HaveEnqueuedJob

Returns a new instance of HaveEnqueuedJob.



9
10
11
# File 'lib/rspec/sidekiq/matchers/have_enqueued_job.rb', line 9

def initialize expected_arguments
  @expected_arguments = expected_arguments
end

Instance Method Details

#descriptionObject



13
14
15
# File 'lib/rspec/sidekiq/matchers/have_enqueued_job.rb', line 13

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

#failure_messageObject



17
18
19
20
# File 'lib/rspec/sidekiq/matchers/have_enqueued_job.rb', line 17

def failure_message
  "expected to have an enqueued #{@klass} job with arguments #{@expected_arguments}\n\n" +
  "found: #{@actual}"
end

#matches?(klass) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/rspec/sidekiq/matchers/have_enqueued_job.rb', line 22

def matches? klass
  @klass = klass
  @actual = klass.jobs.map { |job| job["args"] }
  @actual.any? { |arguments| Array(@expected_arguments) == arguments }
end

#negative_failure_messageObject Also known as: failure_message_when_negated



28
29
30
# File 'lib/rspec/sidekiq/matchers/have_enqueued_job.rb', line 28

def negative_failure_message
  "expected to not have an enqueued #{@klass} job with arguments #{@expected_arguments}"
end