Class: VCR::RequestMatcherRegistry

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

Overview

Keeps track of the different request matchers.

Defined Under Namespace

Classes: Matcher, URIWithoutParamsMatcher

Constant Summary collapse

DEFAULT_MATCHERS =

The default request matchers used for any cassette that does not specify request matchers.

[:method, :uri]

Instance Method Summary collapse

Constructor Details

#initializeRequestMatcherRegistry

Returns a new instance of RequestMatcherRegistry.



49
50
51
52
# File 'lib/vcr/request_matcher_registry.rb', line 49

def initialize
  @registry = {}
  register_built_ins
end

Instance Method Details

#[](matcher) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/vcr/request_matcher_registry.rb', line 64

def [](matcher)
  @registry.fetch(matcher) do
    matcher.respond_to?(:call) ?
      Matcher.new(matcher) :
      raise_unregistered_matcher_error(matcher)
  end
end

#register(name, &block) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/vcr/request_matcher_registry.rb', line 55

def register(name, &block)
  if @registry.has_key?(name)
    warn "WARNING: There is already a VCR request matcher registered for #{name.inspect}. Overriding it."
  end

  @registry[name] = Matcher.new(block)
end

#uri_without_params(*ignores) ⇒ #call Also known as: uri_without_param

Builds a dynamic request matcher that matches on a URI while ignoring the named query parameters. This is useful for dealing with non-deterministic URIs (i.e. that have a timestamp or request signature parameter).

Examples:

without_timestamp = VCR.request_matchers.uri_without_param(:timestamp)

# use it directly...
VCR.use_cassette('example', :match_requests_on => [:method, without_timestamp]) { }

# ...or register it as a named matcher
VCR.configure do |c|
  c.register_request_matcher(:uri_without_timestamp, &without_timestamp)
end

VCR.use_cassette('example', :match_requests_on => [:method, :uri_without_timestamp]) { }

Parameters:

  • ignores (Array<#to_s>)

    The names of the query parameters to ignore

Returns:

  • (#call)

    the request matcher



91
92
93
# File 'lib/vcr/request_matcher_registry.rb', line 91

def uri_without_params(*ignores)
  uri_without_param_matchers[ignores]
end