Sha256: 5a1989b731110b795b8d456d1d07d1f0a6985d2af68c8f2cbc952d762c2a253d

Contents?: true

Size: 1.45 KB

Versions: 48

Compression:

Stored size: 1.45 KB

Contents

require 'pact/shared/json_differ'
require 'pact/mock_service/interaction_decorator'

module Pact
  module MockService
    module Interactions
      class InteractionDiffMessage

        def initialize previous_interaction, new_interaction
          @previous_interaction = previous_interaction
          @new_interaction = new_interaction
        end

        def to_s
          "An interaction with same description (#{new_interaction.description.inspect}) and provider state (#{new_interaction.provider_state.inspect}) but a different #{differences} has already been used. Please use a different description or provider state, or remove any random data in the interaction."
        end

        private

        attr_reader :previous_interaction, :new_interaction

        def differences
          diff = Pact::JsonDiffer.call(previous_interaction_hash, new_interaction_hash, allow_unexpected_keys: false)
          diff.keys.collect do | parent_key |
            diff[parent_key].keys.collect do | child_key |
              "#{parent_key} #{child_key}"
            end
          end.flatten.join(", ").reverse.sub(",", "dna ").reverse
        end

        def previous_interaction_hash
          raw_hash previous_interaction
        end

        def new_interaction_hash
          raw_hash new_interaction
        end

        def raw_hash interaction
          JSON.parse(Pact::MockService::InteractionDecorator.new(interaction).to_json)
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
pact-mock_service-3.12.3 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.12.2 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.12.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.12.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.11.2 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.11.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.11.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.10.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
hs-pact-mock_service-3.9.2 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.9.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.9.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.8.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.7.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.6.2 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.6.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.6.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.5.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.4.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.3.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.3.0 lib/pact/mock_service/interactions/interaction_diff_message.rb