Class: VCR::RequestMatcherRegistry::URIWithoutParamsMatcher

Inherits:
Struct
  • Object
show all
Defined in:
lib/vcr/request_matcher_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#params_to_ignoreObject

Returns the value of attribute params_to_ignore

Returns:

  • (Object)

    the current value of params_to_ignore



19
20
21
# File 'lib/vcr/request_matcher_registry.rb', line 19

def params_to_ignore
  @params_to_ignore
end

Instance Method Details

#call(request_1, request_2) ⇒ Object



39
40
41
# File 'lib/vcr/request_matcher_registry.rb', line 39

def call(request_1, request_2)
  partial_uri_from(request_1) == partial_uri_from(request_2)
end

#partial_uri_from(request) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vcr/request_matcher_registry.rb', line 20

def partial_uri_from(request)
  request.parsed_uri.tap do |uri|
    return uri unless uri.query # ignore uris without params, e.g. "http://example.com/"

    uri.query = uri.query.split('&').tap { |params|
      params.map! do |p|
        key, value = p.split('=')
        key.gsub!(/\[\]\z/, '') # handle params like tag[]=
        [key, value]
      end

      params.reject! { |p| params_to_ignore.include?(p.first) }
      params.map!    { |p| p.join('=') }
    }.join('&')

    uri.query = nil if uri.query.empty?
  end
end

#to_procObject



43
44
45
# File 'lib/vcr/request_matcher_registry.rb', line 43

def to_proc
  lambda { |r1, r2| call(r1, r2) }
end