Sha256: e69ec9e4897ac4d2a2728453fecea34e574808b7b6ddc24791b84d7a49ceb42b
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
require 'term/ansicolor' require 'pact/term' module Pact module Matchers module Messages C = ::Term::ANSIColor def match_term_failure_message diff, actual, diff_formatter, color_enabled actual_string = String === actual ? actual : actual.to_json maybe_coloured_string = color_enabled ? C.white(actual_string) : actual_string message = "Actual: #{maybe_coloured_string}\n\n" formatted_diff = 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pact-1.15.0 | lib/pact/provider/matchers/messages.rb |
pact-1.14.0 | lib/pact/provider/matchers/messages.rb |