Class: Mocktail::ExplainsNils

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mocktail/explains_nils.rb,
lib/mocktail/sorbet/mocktail/explains_nils.rb

Instance Method Summary collapse

Constructor Details

#initializeExplainsNils

Returns a new instance of ExplainsNils.



8
9
10
11
# File 'lib/mocktail/explains_nils.rb', line 8

def initialize
  @stringifies_method_name = StringifiesMethodName.new
  @stringifies_call = StringifiesCall.new
end

Instance Method Details

#explainObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mocktail/explains_nils.rb', line 13

def explain
  Mocktail.cabinet.unsatisfying_calls.map { |unsatisfying_call|
    dry_call = unsatisfying_call.call
    other_stubbings = unsatisfying_call.other_stubbings

    UnsatisfyingCallExplanation.new(unsatisfying_call, <<~MSG)
      `nil' was returned by a mocked `#{@stringifies_method_name.stringify(dry_call)}' method
      because none of its configured stubbings were satisfied.

      The actual call:

        #{@stringifies_call.stringify(dry_call, always_parens: true)}

      The call site:

        #{unsatisfying_call.backtrace.first}

      #{@stringifies_call.stringify_multiple(other_stubbings.map(&:recording),
        nonzero_message: "Stubbings configured prior to this call but not satisfied by it",
        zero_message: "No stubbings were configured on this method")}
    MSG
  }
end