Class: RSpec::Matchers::MultiMatcherDiff Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_list) ⇒ MultiMatcherDiff

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MultiMatcherDiff.

16
17
18
# File 'lib/rspec/matchers/multi_matcher_diff.rb', line 16
def initialize(expected_list)
  @expected_list = expected_list
end

Class Method Details

.for_many_matchers(matchers) ⇒ RSpec::Matchers::MultiMatcherDiff

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wraps provided matcher list in instance of MultiMatcherDiff.

Parameters:

  • matchers (Array<Any>)

    list of matchers to wrap

Returns:

37
38
39
# File 'lib/rspec/matchers/multi_matcher_diff.rb', line 37
def self.for_many_matchers(matchers)
  new(matchers.map { |m| [m.expected, diff_label_for(m), m.actual] })
end

.from(expected, actual) ⇒ RSpec::Matchers::MultiMatcherDiff

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wraps provided expected value in instance of MultiMatcherDiff. If provided value is already an MultiMatcherDiff then it just returns it.

Parameters:

  • expected (Any)

    value to be wrapped

  • actual (Any)

    value

Returns:

27
28
29
30
# File 'lib/rspec/matchers/multi_matcher_diff.rb', line 27
def self.from(expected, actual)
  return expected if self === expected
  new([[expected, DEFAULT_DIFF_LABEL, actual]])
end

Instance Method Details

#message_with_diff(message, differ) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns message with diff(s) appended for provided differ factory and actual value if there are any

Parameters:

  • message (String)

    original failure message

  • differ (Proc)

Returns:

  • (String)
47
48
49
50
51
# File 'lib/rspec/matchers/multi_matcher_diff.rb', line 47
def message_with_diff(message, differ)
  diff = diffs(differ)
  message = "#{message}\n#{diff}" unless diff.empty?
  message
end