Class: RSpec::Matchers::MultiMatcherDiff Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-expectations/lib/rspec/matchers/multi_matcher_diff.rb |
Overview
Handles list of expected and actual value pairs when there is a need to render multiple diffs. Also can handle one pair.
Constant Summary
-
DEFAULT_DIFF_LABEL =
Default diff label when there is only one matcher in diff output
"Diff:".freeze
-
DESCRIPTION_MAX_LENGTH =
Maximum readable matcher description length
65
Class Method Summary
-
.for_many_matchers(matchers) ⇒ RSpec::Matchers::MultiMatcherDiff
Internal use only
Wraps provided matcher list in instance of
MultiMatcherDiff
. -
.from(expected, actual) ⇒ RSpec::Matchers::MultiMatcherDiff
Internal use only
Wraps provided expected value in instance of
MultiMatcherDiff
. - .new(expected_list) ⇒ MultiMatcherDiff constructor Internal use only
- .diff_label_for(matcher) private Internal use only
- .truncated(description) private Internal use only
Instance Method Summary
-
#message_with_diff(message, differ) ⇒ String
Internal use only
Returns message with diff(s) appended for provided differ factory and actual value if there are any.
- #diffs(differ) private Internal use only
Class Method Details
.diff_label_for(matcher) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/multi_matcher_diff.rb', line 58
def diff_label_for(matcher) "Diff for (#{truncated(RSpec::Support::ObjectFormatter.format(matcher))}):" end
.for_many_matchers(matchers) ⇒ MultiMatcherDiff
Wraps provided matcher list in instance of MultiMatcherDiff
.
# File 'rspec-expectations/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) ⇒ MultiMatcherDiff
Wraps provided expected value in instance of MultiMatcherDiff
. If provided value is already an MultiMatcherDiff
then it just returns it.
# File 'rspec-expectations/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
.truncated(description) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/multi_matcher_diff.rb', line 62
def truncated(description) return description if description.length <= DESCRIPTION_MAX_LENGTH description[0...DESCRIPTION_MAX_LENGTH - 3] << "..." end
Instance Method Details
#diffs(differ) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/multi_matcher_diff.rb', line 68
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
#message_with_diff(message, differ) ⇒ String
Returns message with diff(s) appended for provided differ factory and actual value if there are any
# File 'rspec-expectations/lib/rspec/matchers/multi_matcher_diff.rb', line 47
def (, differ) diff = diffs(differ) = "#{}\n#{diff}" unless diff.empty? end