Module: RSpec::Expectations::ExpectationHelper

Defined in:
lib/super_diff/rspec/monkey_patches.rb

Class Method Summary collapse

Class Method Details

.handle_failure(matcher, message, failure_message_method) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/super_diff/rspec/monkey_patches.rb', line 20

def self.handle_failure(matcher, message, failure_message_method)
  message = message.call if message.respond_to?(:call)
  message ||= matcher.__send__(failure_message_method)

  if matcher.respond_to?(:diffable?) && matcher.diffable?
    # Look for expected_for_diff and actual_for_diff if possible
    expected =
      if matcher.respond_to?(:expected_for_diff)
        matcher.expected_for_diff
      else
        matcher.expected
      end

    actual =
      if matcher.respond_to?(:actual_for_diff)
        matcher.actual_for_diff
      else
        matcher.actual
      end

    ::RSpec::Expectations.fail_with(message, expected, actual)
  else
    ::RSpec::Expectations.fail_with(message)
  end
end