Sha256: 1635f3ba5464c5705630f7f5314c72c1d7ac3e4b414b0ed48df17cee1a1610db

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

module Pact
  module Consumer
    class InteractionList

      attr_reader :interactions
      attr_reader :unexpected_requests

      def initialize
        clear
      end

      # For testing, sigh
      def clear
        @interactions = []
        @matched_interactions = []
        @unexpected_requests = []
      end

      def add interactions
        @interactions << interactions
      end

      def register_matched interaction
        @matched_interactions << interaction
      end

      def register_unexpected_request request
        @unexpected_requests << request
      end

      def all_matched?
        interaction_diffs.empty?
      end

      def missing_interactions
        @interactions - @matched_interactions
      end

      def interaction_diffs
        {
          :missing_interactions => missing_interactions.collect(&:as_json),
          :unexpected_requests => unexpected_requests.collect(&:as_json)
        }.inject({}) do | hash, pair |
          hash[pair.first] = pair.last if pair.last.any?
          hash
        end
      end

      def find_candidate_interactions actual_request
        interactions.select do | interaction |
          interaction.request.matches_route? actual_request
        end        
      end      

    end    
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pact-1.0.22 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.21 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.20 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.19 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.18 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.15 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.13 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.12 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.11 lib/pact/consumer/mock_service/interaction_list.rb
pact-1.0.10 lib/pact/consumer/mock_service/interaction_list.rb