Sha256: 6e2f6aaedbe8413a5aae7fff50bfd9334eeca9b854af11d8cf9ae8b807034a10

Contents?: true

Size: 838 Bytes

Versions: 3

Compression:

Stored size: 838 Bytes

Contents

module Peddler
  module Test
    class VCRMatcher
      TRANSIENT_PARAMS = %w( AWSAccessKeyId SellerId Signature Timestamp
                             StartDate CreatedAfter QueryStartDateTime ).freeze

      attr_reader :req_1, :req_2

      def self.call(req_1, req_2)
        new(req_1, req_2).compare
      end

      def initialize(req_1, req_2)
        @req_1 = req_1
        @req_2 = req_2
      end

      def compare
        compare_uri && compare_body
      end

      private

      def compare_uri
        req_1.uri == req_2.uri
      end

      def compare_body
        extract_params(req_1.body) == extract_params(req_2.body)
      end

      def extract_params(body)
        params = ::CGI.parse(body)
        TRANSIENT_PARAMS.each do |k|
          params.delete(k)
        end

        params
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
peddler-1.1.0 lib/peddler/test/vcr_matcher.rb
peddler-1.0.2 lib/peddler/test/vcr_matcher.rb
peddler-1.0.1 lib/peddler/test/vcr_matcher.rb