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.2.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.2.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.1.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.1.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.0.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-3.0.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.12.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.11.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.10.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.10.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.9.8 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.9.3 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.9.2 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.9.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.9.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.8.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.8.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.7.1 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.7.0 lib/pact/mock_service/interactions/interaction_diff_message.rb
pact-mock_service-2.6.4 lib/pact/mock_service/interactions/interaction_diff_message.rb