Sha256: de4509e1f1d01458b104088808d4cbbc896e4a1c450f6fe975b828ce404a6dd7

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module WebMock

  class RequestSignature < Request

    def match(request_profile)
      raise ArgumentError unless request_profile.is_a?(RequestProfile)
      match_method(request_profile) &&
        match_body(request_profile) &&
        match_headers(request_profile) &&
        match_uri(request_profile)
    end

    private

    def match_uri(request_profile)
      if request_profile.uri.is_a?(Addressable::URI)
        WebMock::Util::URI.normalize_uri(uri) === WebMock::Util::URI.normalize_uri(request_profile.uri)
      elsif request_profile.uri.is_a?(Regexp)
        WebMock::Util::URI.variations_of_uri_as_strings(self.uri).any? { |u| u.match(request_profile.uri) }
      else
        false
      end
    end

    def match_headers(request_profile)
      return false if self.headers && !self.headers.empty? && request_profile.headers && request_profile.headers.empty?
      if request_profile.headers && !request_profile.headers.empty?
        request_profile.headers.each do | key, value |
          return false unless (self.headers && self.headers.has_key?(key) && value == self.headers[key])
        end
      end
      return true
    end

    def match_body(request_profile)
      request_profile.body == self.body || request_profile.body.nil?
    end

    def match_method(request_profile)
      request_profile.method == self.method || request_profile.method == :any
    end
  end


end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
webmock-0.8.2 lib/webmock/request_signature.rb
webmock-0.8.1 lib/webmock/request_signature.rb
webmock-0.8.0 lib/webmock/request_signature.rb