Class: RSpec::Sidekiq::Matchers::BeRetryable

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

Instance Method Summary collapse

Constructor Details

#initialize(expected_retry) ⇒ BeRetryable

Returns a new instance of BeRetryable.



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

def initialize(expected_retry)
  @expected_retry = expected_retry
end

Instance Method Details

#descriptionObject



13
14
15
16
17
18
19
20
21
# File 'lib/rspec/sidekiq/matchers/be_retryable.rb', line 13

def description
  if @expected_retry.is_a?(Numeric)
    "retry #{@expected_retry} times"    # retry: 5
  elsif @expected_retry
    'retry the default number of times' # retry: true
  else
    'not retry'                         # retry: false
  end
end

#failure_messageObject



23
24
25
# File 'lib/rspec/sidekiq/matchers/be_retryable.rb', line 23

def failure_message
  "expected #{@klass} to #{description} but got #{@actual}"
end

#failure_message_when_negatedObject



33
34
35
# File 'lib/rspec/sidekiq/matchers/be_retryable.rb', line 33

def failure_message_when_negated
  "expected #{@klass} to not #{description}".gsub 'not not ', ''
end

#matches?(job) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/rspec/sidekiq/matchers/be_retryable.rb', line 27

def matches?(job)
  @klass = job.is_a?(Class) ? job : job.class
  @actual = @klass.get_sidekiq_options['retry']
  @actual == @expected_retry
end