Class: RSpec::Sidekiq::Matchers::HaveJob Private

Inherits:
Object
  • Object
show all
Includes:
Mocks::ArgumentMatchers, ArgumentNormalization, CountExpectation
Defined in:
lib/rspec/sidekiq/matchers/have_job.rb

Overview

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.

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_job_class) ⇒ HaveJob

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

API:

  • private



18
19
20
21
22
23
24
25
26
27
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 18

def initialize(expected_job_class)
  @expected_job_class = expected_job_class
  @expected_arguments = [any_args]
  @expected_count = [:positive, 1]
  @scan_pattern = nil
  @expected_error_message = nil
  @expected_error_class = nil
  @expected_retry_count = nil
  @expected_died_within = nil
end

Instance Attribute Details

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

API:

  • private



16
17
18
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 16

def expected_arguments
  @expected_arguments
end

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

API:

  • private



16
17
18
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 16

def expected_count
  @expected_count
end

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

API:

  • private



16
17
18
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 16

def expected_job_class
  @expected_job_class
end

Instance Method Details

#at_least(n) ⇒ 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.

API:

  • private



84
85
86
87
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 84

def at_least(n)
  set_expected_count :at_least, n
  self
end

#at_most(n) ⇒ 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.

API:

  • private



89
90
91
92
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 89

def at_most(n)
  set_expected_count :at_most, n
  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.

API:

  • private



108
109
110
111
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 108

def description
  set_label = @set_class || "set"
  "have #{count_message} #{job_message} in #{set_label}"
end

#died_within(duration) ⇒ 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.

API:

  • private



54
55
56
57
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 54

def died_within(duration)
  @expected_died_within = duration
  self
end

#exactly(n) ⇒ 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.

API:

  • private



79
80
81
82
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 79

def exactly(n)
  set_expected_count :exactly, n
  self
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.

API:

  • private



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 113

def failure_message
  message = ["expected to #{description}"]
  if expected_arguments.any?
    message << "  with arguments:"
    message << "    -#{formatted(expected_arguments)}"
  end

  filters = []
  filters << "error: #{formatted(@expected_error_message)}" if @expected_error_message
  filters << "error_class: #{formatted(normalize_error_class(@expected_error_class))}" if @expected_error_class
  filters << "retry_count: #{formatted(@expected_retry_count)}" if @expected_retry_count
  if @expected_died_within
    filters << "died_within: #{formatted(@expected_died_within)}"
  end
  message << "  with filters: #{filters.join(', ')}" if filters.any?
  message << "but found #{@actual_jobs.size}"
  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.

API:

  • private



132
133
134
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 132

def failure_message_when_negated
  "expected not to #{description} but found #{@actual_jobs.size}"
end

#matches?(set_or_class) ⇒ 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:

API:

  • private



99
100
101
102
103
104
105
106
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 99

def matches?(set_or_class)
  @set_class = set_or_class.is_a?(Class) ? set_or_class : set_or_class.class
  set = set_or_class.is_a?(Class) ? set_or_class.new : set_or_class

  @actual_jobs = matching_jobs(set)

  count_matches?(@actual_jobs.size)
end

#neverObject

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.

API:

  • private



59
60
61
62
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 59

def never
  set_expected_count :exactly, 0
  self
end

#onceObject

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.

API:

  • private



64
65
66
67
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 64

def once
  set_expected_count :exactly, 1
  self
end

#scanning(pattern) ⇒ 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.

API:

  • private



34
35
36
37
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 34

def scanning(pattern)
  @scan_pattern = pattern
  self
end

#thriceObject

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.

API:

  • private



74
75
76
77
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 74

def thrice
  set_expected_count :exactly, 3
  self
end

#timesObject Also known as: time

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.

API:

  • private



94
95
96
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 94

def times
  self
end

#twiceObject

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.

API:

  • private



69
70
71
72
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 69

def twice
  set_expected_count :exactly, 2
  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.

API:

  • private



29
30
31
32
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 29

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

#with_error(message) ⇒ 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.

API:

  • private



39
40
41
42
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 39

def with_error(message)
  @expected_error_message = message
  self
end

#with_error_class(error_class) ⇒ 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.

API:

  • private



44
45
46
47
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 44

def with_error_class(error_class)
  @expected_error_class = error_class
  self
end

#with_retry_count(count) ⇒ 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.

API:

  • private



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

def with_retry_count(count)
  @expected_retry_count = count
  self
end