Class: RSpec::Sidekiq::Matchers::HaveJob Private
- Inherits:
-
Object
- Object
- RSpec::Sidekiq::Matchers::HaveJob
- 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.
Instance Attribute Summary collapse
- #expected_arguments ⇒ Object readonly private
- #expected_count ⇒ Object readonly private
- #expected_job_class ⇒ Object readonly private
Instance Method Summary collapse
- #at_least(n) ⇒ Object private
- #at_most(n) ⇒ Object private
- #description ⇒ Object private
- #died_within(duration) ⇒ Object private
- #exactly(n) ⇒ Object private
- #failure_message ⇒ Object private
- #failure_message_when_negated ⇒ Object private
-
#initialize(expected_job_class) ⇒ HaveJob
constructor
private
A new instance of HaveJob.
- #matches?(set_or_class) ⇒ Boolean private
- #never ⇒ Object private
- #once ⇒ Object private
- #scanning(pattern) ⇒ Object private
- #thrice ⇒ Object private
- #times ⇒ Object (also: #time) private
- #twice ⇒ Object private
- #with(*expected_arguments) ⇒ Object private
- #with_error(message) ⇒ Object private
- #with_error_class(error_class) ⇒ Object private
- #with_retry_count(count) ⇒ Object private
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.
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 = nil @expected_error_class = nil @expected_retry_count = nil @expected_died_within = nil end |
Instance Attribute Details
#expected_arguments ⇒ Object (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.
16 17 18 |
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 16 def expected_arguments @expected_arguments end |
#expected_count ⇒ Object (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.
16 17 18 |
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 16 def expected_count @expected_count end |
#expected_job_class ⇒ Object (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.
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.
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.
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 |
#description ⇒ 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.
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.
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.
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_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.
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 = ["expected to #{description}"] if expected_arguments.any? << " with arguments:" << " -#{formatted(expected_arguments)}" end filters = [] filters << "error: #{formatted(@expected_error_message)}" if 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 << " with filters: #{filters.join(', ')}" if filters.any? << "but found #{@actual_jobs.size}" .join("\n") end |
#failure_message_when_negated ⇒ 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.
132 133 134 |
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 132 def "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.
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 |
#never ⇒ 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.
59 60 61 62 |
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 59 def never set_expected_count :exactly, 0 self end |
#once ⇒ 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.
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.
34 35 36 37 |
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 34 def scanning(pattern) @scan_pattern = pattern self end |
#thrice ⇒ 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.
74 75 76 77 |
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 74 def thrice set_expected_count :exactly, 3 self end |
#times ⇒ Object 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.
94 95 96 |
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 94 def times self end |
#twice ⇒ 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.
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.
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.
39 40 41 42 |
# File 'lib/rspec/sidekiq/matchers/have_job.rb', line 39 def with_error() = 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.
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.
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 |