Sha256: 6a73c53bdf2b4ddfefe765e0e7278536639dc2c8f65cd75a6e729727c12f9281

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# typed: strict

require_relative "share/stringifies_method_name"
require_relative "share/stringifies_call"

module Mocktail
  class ExplainsNils
    extend T::Sig

    sig { void }
    def initialize
      @stringifies_method_name = T.let(StringifiesMethodName.new, StringifiesMethodName)
      @stringifies_call = T.let(StringifiesCall.new, StringifiesCall)
    end

    sig { returns(T::Array[UnsatisfyingCallExplanation]) }
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mocktail-2.0.0 lib/mocktail/sorbet/mocktail/explains_nils.rb