Class: RSpec::Rewind::RetryDecision

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/rewind/retry_decision.rb

Defined Under Namespace

Classes: MatchResult

Instance Method Summary collapse

Constructor Details

#initialize(exception:, example:, retry_on:, skip_retry_on:, retry_if:, retry_on_default: :all, context: nil, strict_callable_arity: false) ⇒ RetryDecision

Returns a new instance of RetryDecision.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rspec/rewind/retry_decision.rb', line 30

def initialize(
  exception:,
  example:,
  retry_on:,
  skip_retry_on:,
  retry_if:,
  retry_on_default: :all,
  context: nil,
  strict_callable_arity: false
)
  @exception = exception
  @example = example
  @retry_on = normalize_matchers(retry_on)
  @skip_retry_on = normalize_matchers(skip_retry_on)
  @retry_if = retry_if
  @retry_on_default = retry_on_default
  @context = context
  @strict_callable_arity = strict_callable_arity
end

Instance Method Details

#decisionObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rspec/rewind/retry_decision.rb', line 54

def decision
  return rejected(:no_exception) unless @exception

  skip_match = find_match(@skip_retry_on)
  if skip_match.matched?
    return rejected(
      :skip_retry_on_matched,
      matched_skip_retry_on: skip_match.description,
      matcher_error: skip_match.error
    )
  end

  retry_match = nil
  if @retry_on.any?
    retry_match = find_match(@retry_on)
    unless retry_match.matched?
      return rejected(
        :retry_on_not_matched,
        matcher_error: retry_match.error
      )
    end
  elsif !retry_on_default_allowed?
    return rejected(:retry_on_default_rejected)
  end

  if @retry_if && !call_with_context(@retry_if)
    return rejected(
      :predicate_rejected,
      matched_retry_on: retry_match&.description
    )
  end

  allowed(matched_retry_on: retry_match&.description)
end

#retry?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/rspec/rewind/retry_decision.rb', line 50

def retry?
  decision.allowed?
end