Sha256: 2e32841c8bb6a267204f7ee5140fc3fb9874cc3586a54a51e6048d8c13f058bf
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
require 'term/ansicolor' require 'pact/term' module Pact module Matchers module Messages def match_term_failure_message diff, actual, color_enabled message = "Actual: #{(String === actual ? actual : actual.to_json)}\n\n" formatted_diff = Pact.configuration.diff_formatter.call(diff) message + colorize_if_enabled(formatted_diff, color_enabled) end def match_header_failure_message header_name, expected, actual "Expected header \"#{header_name}\" to #{expected_desc(expected)}, but was #{actual_desc(actual)}" end private def colorize_if_enabled formatted_diff, color_enabled if color_enabled # RSpec wraps each line in the failure message with failure_color, turning it red. # To ensure the lines in the diff that should be white, stay white, put an # ANSI reset at the start of each line. formatted_diff.split("\n").collect{ |line| ::Term::ANSIColor.reset + line }.join("\n") else formatted_diff end end def expected_desc expected case expected when NilClass then "be nil" else "match #{expected.inspect}" end end def actual_desc actual actual.nil? ? 'nil' : '"' + actual + '"' end end end end
Version data entries
4 entries across 4 versions & 1 rubygems