Sha256: b716221f3cbdf0b3fd0e2f0ae9929281386668ea0dbd0c60c3fee6c448fc4afd

Contents?: true

Size: 1011 Bytes

Versions: 1

Compression:

Stored size: 1011 Bytes

Contents

require 'pact/consumer_contract/active_support_support'
require 'colored'

module Pact
  module Matchers
    class NestedJsonDiffDecorator

      include Pact::ActiveSupportSupport

      EXPECTED = '"EXPECTED"'
      EXPECTED_COLOURED = '"' + "expected".red + '"'
      ACTUAL = '"ACTUAL"'
      ACTUAL_COLOURED =  '"' + "actual".green + '"'

      attr_reader :diff

      def initialize diff
        @diff = diff
      end

      def to_hash
        diff
      end

      def to_s
        colourise_message_if_configured fix_json_formatting(diff.to_json)
      end

      def colourise_message_if_configured message
        if Pact.configuration.color_enabled
          colourise_message message
        else
          message
        end
      end

      def colourise_message message
        message.split("\n").collect{| line | colourise(line) }.join("\n")
      end

      def colourise line
        line.white.gsub(EXPECTED, EXPECTED_COLOURED).gsub(ACTUAL, ACTUAL_COLOURED)
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact-1.1.0.rc1 lib/pact/matchers/nested_json_diff_decorator.rb