Sha256: aa15210b3a5dc55cc3bc4be98d351e917f806483acce7b8b343b7afbf6e4b215

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'term/ansicolor'
require 'pact/term'

module Pact
  module Matchers
    module Messages

      def match_term_failure_message diff, color_enabled
        message = Pact.configuration.diff_formatter.call(diff)

        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.
          message.split("\n").collect{ |line| ::Term::ANSIColor.reset + line }.join("\n")
        else
          message
        end

      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 expected_desc expected
        case expected
        when Pact::Term then "match #{expected.matcher.inspect}"
        when NilClass then "be nil"
        else
          "match \"#{expected}\""
        end
      end

      def actual_desc actual
        actual.nil? ? 'nil' : '"' + actual + '"'
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pact-1.1.0 lib/pact/provider/matchers/messages.rb
pact-1.1.0.rc5 lib/pact/provider/matchers/messages.rb
pact-1.1.0.rc4 lib/pact/provider/matchers/messages.rb
pact-1.1.0.rc3 lib/pact/provider/matchers/messages.rb