class RSpec::Matchers::MultiMatcherDiff

to render multiple diffs. Also can handle one pair.
Handles list of expected and actual value pairs when there is a need
@api private

def self.for_many_matchers(matchers)

Returns:
  • (RSpec::Matchers::MultiMatcherDiff) -

Parameters:
  • matchers (Array) -- list of matchers to wrap

Other tags:
    Api: - private
def self.for_many_matchers(matchers)
  new(matchers.map { |m| [m.expected, diff_label_for(m), m.actual] })
end

def self.from(expected, actual)

Returns:
  • (RSpec::Matchers::MultiMatcherDiff) -

Parameters:
  • actual (Any) -- value
  • expected (Any) -- value to be wrapped

Other tags:
    Api: - private
def self.from(expected, actual)
  return expected if self === expected
  new([[expected, DEFAULT_DIFF_LABEL, actual]])
end

def diff_label_for(matcher)

def diff_label_for(matcher)
  "Diff for (#{truncated(RSpec::Support::ObjectFormatter.format(matcher))}):"
end

def diffs(differ)

def diffs(differ)
  @expected_list.map do |(expected, diff_label, actual)|
    diff = differ.diff(actual, expected)
    next if diff.strip.empty?
    if diff == "\e[0m\n\e[0m"
      "#{diff_label}\n" \
        "  <The diff is empty, are your objects producing identical `#inspect` output?>"
    else
      "#{diff_label}#{diff}"
    end
  end.compact.join("\n")
end

def initialize(expected_list)

def initialize(expected_list)
  @expected_list = expected_list
end

def message_with_diff(message, differ)

Returns:
  • (String) -

Parameters:
  • differ (Proc) --
  • message (String) -- original failure message

Other tags:
    Api: - private
def message_with_diff(message, differ)
  diff = diffs(differ)
  message = "#{message}\n#{diff}" unless diff.empty?
  message
end

def truncated(description)

def truncated(description)
  return description if description.length <= DESCRIPTION_MAX_LENGTH
  description[0...DESCRIPTION_MAX_LENGTH - 3] << "..."
end